Hello,
I'm making a GMod gamemode where everyone has a grenade. Once this grenade is thrown, I want the player who threw it to be killed off.
How can I do this?
Here is my current code:
init.lua:
[CODE]AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
include( 'shared.lua' )
function GM:PlayerLoadout( pl )
t = weapons.GetList()
--for key,value in pairs(t) do r = key z = value for key,value in pairs(z) do print(r,value) end end --print shit!
pl:Give( "weapon_crowbar" )
pl:Give("weapon_frag")
end[/CODE]
cl_init.lua:
[CODE]
include('shared.lua')
pl = LocalPlayer()
function weapon:CanPrimaryAttack()
if ( self.Weapon:Clip1() <= 0 ) then
LocalPlayer():Kill()
end
end[/CODE]
shared.lua just contains the standard [CODE]function GM:Initialize() end[/CODE] and the GM.Name info.
As you can see in cl_init.lua, I have tried to use CanPrimaryAttack, but this just errors.
Thanks in advanced for any help!
Hedgehog1029
I think you have to return false inside the check for clip.
I think, I never used that function before.
[editline]14th December 2013[/editline]
Also you said it errors but gave no error?
your using a swep function in a gamemodes cl_init.lua...wat..just..wat
try this:
[lua]
function KillDemFools()
for id,pl in pairs( player.GetAll() )do
if pl:GetAmmoCount("grenade") == 0 then
pl:Kill()
end
end
end
hook.Add("Think", "killdemfools_hook", KillDemFools)
[/lua]
Edit: this goes in init.lua
[QUOTE=legendofrobbo;43180872]your using a swep function in a gamemodes cl_init.lua...wat..just..wat
try this:
[lua]
function KillDemFools()
for id,pl in pairs( player.GetAll() )do
if pl:GetAmmoCount("grenade") == 0 then
pl:Kill()
end
end
end
hook.Add("Think", "killdemfools_hook", KillDemFools)
[/lua]
Edit: this goes in init.lua[/QUOTE]
thanks! that nearly did it! unfortunatley that did cause an error where the character couldn't die because it was being killed repeatedly, but i fixed that by adding this:
[CODE]
if pl:GetAmmoCount("grenade") == 0 then
pl:Kill()
pl:SetAmmo(1,"Grenade") --this is the bit I added
[/CODE]
But your solution was almost perfect, thanks for the help!!
hedgehog1029
Sorry, you need to Log In to post a reply to this thread.