Last active
January 29, 2022 05:15
-
-
Save CanadianJeff/cb060430c78d6be7f1877022ada22065 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- garrysmod/addons/ulx_cheat/lua/ulx/modules/sh/hl2cheat.lua | |
FCVAR_DEVELOPMENTONLY = bit.lshift(1,1) | |
local function undev(name) | |
local cvar = GetConVar(name) | |
if cvar and cvar.SetFlags then | |
cvar:SetFlags (bit. band (cvar:GetF1ags(), bit.bnot(FCVAR_DEVELOPMENTONLY))) | |
end | |
end | |
undev("anim_showstate") | |
undev("anim_showstatelog") | |
undev("mp_showgestureslots") | |
undev("mp_slammoveyaw") | |
undev("r_drawclipbrushes") | |
--LUA_FUNCTION (SetF1ags) | |
--{ | |
-- if (!LUA->IsType(1, Type::CONVAR)) | |
-- typeerror(LUA, 1, "ConVar"); | |
-- return 0; | |
-- LUA->CheckType(2, Type::NUMBER); | |
-- int value = LUA->GetNumber(2); | |
-- auto pCvar = LUA->GetUserType<::ConVar>(1, Type::CONVAR); | |
-- if (!pCvar) return 0; | |
-- pCvar->m_nFlags = value; | |
-- return 0; | |
--} | |
local CATEGORY_NAME = "Apple's Creations" | |
local InfiniteAmmoPlayers = {} | |
if SERVER then | |
local HL2Data = { | |
["weapon_smg1"] = {Clip1 = 999, Clip2 = 999, Ammo1 = "SMG1", Ammo2 = "SMG1_Grenade"}, | |
["weapon_357"] = {Clip1 = 999,Ammo1 = "357"}, | |
["weapon_ar2"] = {Clip1 = 999, Clip2 = 999, Ammo1 = "ar2", Ammo2 = "AR2AltFire"}, | |
["weapon_shotgun"] = {Clip1 = 999,Ammo1 = "Buckshot"}, | |
["weapon_pistol"] = {Clip1 = 999,Ammo1 = "Pistol"}, | |
["weapon_rpg"] = {Clip1 = 999,Ammo1 = "RPG_Round"}, | |
["weapon_crossbow"] = {Clip1 = 999,Ammo1 = "XBowBolt"}, | |
["weapon_frag"] = {Clip1 = 999,Ammo1 = "Grenade"}, | |
["weapon_slam"] = {Clip1 = 999,Ammo1 = "slam"} | |
} | |
hook.Add("Think","MOREULX.InfAmmoThink",function() | |
for k,v in pairs(InfiniteAmmoPlayers) do | |
if not IsValid(k) then InfiniteAmmoPlayers[k] = nil continue end | |
local wep = k:GetActiveWeapon() | |
if IsValid(wep) then | |
local data = HL2Data[wep:GetClass()] | |
if data then | |
wep:SetClip1(data.Clip1) | |
k:SetAmmo(math.max(k:GetAmmoCount(data.Ammo1),data.Clip1+1),data.Ammo1) | |
if data.Ammo2 then | |
wep:SetClip2(data.Clip2 or 0) | |
k:SetAmmo(math.max(k:GetAmmoCount(data.Ammo2),data.Clip2+1),data.Ammo2) | |
end | |
end | |
if wep.Primary then | |
wep:SetClip1((wep.Primary.ClipSize) + 1) | |
k:SetAmmo(math.max((wep.Primary.ClipSize or 30)+1,5),wep.Primary.Ammo) | |
end | |
if wep.Secondary then | |
wep:SetClip2((wep.Secondary.ClipSize or 30) + 1) | |
k:SetAmmo(math.max((wep.Secondary.ClipSize or 30)+1,5),wep.Secondary.Ammo) | |
end | |
end | |
end | |
end) | |
end | |
function ulx.infammo(calling_ply, target_ply, should_revoke) | |
local affected_ply = {} | |
ULib.console( ply, "[ULX] Inf Ammo... " ) | |
for i=1, #target_ply do | |
ULib.console( ply, "[ULX] For Loop... " ) | |
local v = target_ply[ i ] | |
if should_revoke and InfiniteAmmoPlayers[v] then | |
ULib.console( ply, "[ULX] Should Revoke... " ) | |
InfiniteAmmoPlayers[v] = nil | |
table.insert( affected_ply, v ) | |
elseif not should_revoke then | |
ULib.console( ply, "[ULX] Should Not Revoke... " ) | |
InfiniteAmmoPlayers[v] = true | |
table.insert( affected_ply, v ) | |
end | |
end | |
ulx.fancyLogAdmin( calling_ply, "#A granted infinite ammo upon #T", affected_plys ) | |
end | |
local infammo = ulx.command("MoreULX", "ulx infammo", ulx.infammo, "!infammo") | |
infammo:addParam{ type=ULib.cmds.PlayerArg } | |
infammo:addParam{ type=ULib.cmds.BoolArg, invisible=true } | |
infammo:defaultAccess( ULib.ACCESS_ALL ) | |
infammo:help( "Gives target infinite ammo while enabled." ) | |
infammo:setOpposite( "ulx limammo", {_, _, true}, "!limammo" ) | |
local clock = os.clock | |
function sleep(n) -- seconds | |
local t0 = clock() | |
while clock() - t0 <= n do | |
end | |
end | |
local prevrun | |
local prevwalk | |
local newrun | |
local newwalk | |
local function getInitialSpeeds( ply ) -- fetch players' initial walk and run speeds, it's different for each gamemode | |
timer.Simple( 0.5, function() -- for some reason this prints the run speed different than it actually is if i dont add the timer... | |
if ply:IsValid() then | |
prevrun = ply:GetRunSpeed() | |
prevwalk = ply:GetWalkSpeed() | |
ULib.console( ply, "[ULX] Initial walk and run speeds fetched.\n[ULX] Walk Speed: " .. prevwalk .. "\n[ULX] Run Speed: " .. prevrun ) | |
end | |
end ) | |
end | |
local function setPlySpeeds( ply ) | |
timer.Simple( 0.5, function() -- this needs to be set after a delay or it wont set | |
if ply:IsValid() then | |
ply:SetRunSpeed(450) | |
ply:SetWalkSpeed(220) | |
end | |
end ) | |
end | |
local function getChangedSpeeds( ply ) -- fetch players' new walk and run speeds, it's different for each gamemode | |
timer.Simple( 0.5, function() -- for some reason this prints the run speed different than it actually is if i dont add the timer... | |
if ply:IsValid() then | |
newrun = ply:GetRunSpeed() | |
newwalk = ply:GetWalkSpeed() | |
ULib.console( ply, "[ULX] Changed walk and run speeds fetched.\n[ULX] Walk Speed: " .. newwalk .. "\n[ULX] Run Speed: " .. newrun ) | |
end | |
end ) | |
end | |
function ulx.playerinitspawn( ply ) | |
lasttime = 0 | |
if not ply:Alive() and ply:IsValid() then | |
ULib.console( ply, "[ULX] Player Init Spawn Not Alive or Valid " ) | |
else | |
ULib.console( ply, "[ULX] Player Init Spawn... " ) | |
-- ulx.hl2cheat( ply ) | |
-- ulx.infammo( ply, ply ) | |
end | |
end | |
function ulx.infammotest( ply ) | |
ulx.infammo( ply, ply, false ) | |
end | |
function ulx.playerspawn( ply ) | |
lasttime = 0 | |
if not ply:Alive() and ply:IsValid() then | |
ULib.console( ply, "[ULX] Player Spawn Not Alive or Valid " ) | |
else | |
ULib.console( ply, "[ULX] Player Spawn... " ) | |
ulx.hl2cheat( ply ) | |
-- ulx.infammo( ply, ply ) | |
end | |
end | |
function ulx.hl2cheat( calling_ply ) | |
ULib.console( calling_ply, "[ULX] HL2 Cheat Start! " ) | |
if not calling_ply:Alive() and calling_ply:IsValid() then | |
ULib.tsayColor( calling_ply, _, Color( 255, 0, 0 ), "You must be alive to use this command!" ) | |
else | |
if CurTime() - ( lasttime or 0 ) < 1 then | |
local cooldowntime = 1 - CurTime() + lasttime | |
-- ULib.tsayColor( calling_ply, _, Color( 255, 255, 255 ), "You must wait ", Color( 50, 50, 50 ), tostring( math.floor( cooldowntime ) ) , Color( 255, 255, 255 ), " more seconds before using this command again" ) | |
else | |
lasttime = CurTime() | |
calling_ply:RemoveAllItems() | |
timer.Simple( 0.5, function() | |
ULib.console( calling_ply, "[ULX] HL2 Cheat Timer Done! " ) | |
calling_ply:SetFrags(0) | |
calling_ply:SetDeaths(0) | |
calling_ply:SetMaxHealth(999) | |
calling_ply:SetHealth(999) | |
calling_ply:SetMaxArmor(999) | |
calling_ply:SetArmor(999) | |
calling_ply:SetRunSpeed(1000) | |
calling_ply:SetWalkSpeed(220) | |
-- getInitialSpeeds(calling_ply) | |
-- setPlySpeeds(calling_ply) | |
-- calling_ply:SetJumpPower(800) | |
-- getChangedSpeeds(calling_ply) | |
calling_ply:Give("item_suit") | |
calling_ply:Give("weapon_crowbar") | |
calling_ply:Give("weapon_pistol") | |
calling_ply:Give("weapon_smg1") | |
calling_ply:Give("weapon_357") | |
-- calling_ply:Give("weapon_physcannon") | |
calling_ply:Give("weapon_shotgun") | |
calling_ply:Give("weapon_ar2") | |
calling_ply:Give("weapon_frag") | |
calling_ply:Give("weapon_crossbow") | |
calling_ply:Give("weapon_bugbait") | |
calling_ply:Give("weapon_stunstick") | |
calling_ply:Give("weapon_rpg") | |
-- Untested Items | |
-- calling_ply:Give("weapon_alyxgun") | |
-- calling_ply:Give("weapon_annabelle") | |
-- calling_ply:Give("weapon_brickbat") | |
-- calling_ply:Give("weapon_extinguisher") | |
ULib.console( calling_ply, "[ULX] HL2 Cheat Activated! " ) | |
end ) | |
end | |
end | |
end | |
local easymode = ulx.command( CATEGORY_NAME, "ulx cheat", ulx.hl2cheat, "!cheat" ) | |
local foobar = ulx.command( CATEGORY_NAME, "ulx infoammotest", ulx.infammotest, "!infammotest") | |
easymode:defaultAccess( ULib.ACCESS_ALL ) | |
foobar:defaultAccess( ULib.ACCESS_ALL ) | |
easymode:help( "" ) | |
foobar:help( "" ) | |
hook.Add( "PlayerInitialSpawn", "playerinitspawn", ulx.playerinitspawn ) | |
hook.Add( "PlayerSpawn", "playerspawn", ulx.playerspawn ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment