Beginner programmer here and am trying to make stuff in Gmod.
I made a simple script to explode when you press space while in a vehicle (Done with help of a friend)
Despite reinstalling and disabling addons, it just refuses to work for me, but it works for my friend without any issue.
Running clientside, this is the code:
hook.Add("PlayerEnteredVehicle", "PlyVehicleThing", function(ply, veh, role)
hook.Add( "KeyPress", "keypressexplode", function( ply, key)
if ( key == IN_JUMP ) then
local VehPos = ply:GetPos()
print(VehPos)
ply:ChatPrint("Explode!")
local explosion = ents.Create("env_explosion")
explosion:SetPos(Vector(VehPos))
explosion:Spawn()
explosion:Fire()
end
hook.Add("PlayerLeaveVehicle", "LeaveVehicleCheck", function(ply, veh)
hook.Remove("KeyPress", "keypressexplode")
end)
end)
end)
I have no idea why this won't work and would love some help
Thanks
You are not setting any keyvalues or firing any inputus on env_explosion, so nothing happens as it should. See documentation of env_Explosion on Valve Developer Community Wiki
After messing around with the code by adding "explosion" to explosion:fire() and setting key values, it finally worked.
Thanks for your help!
Sorry, you need to Log In to post a reply to this thread.