So I need a bit of help here.
I am making an Admin SWEP for my server, and the SWEP works.
The reason why im asking help is because of this weird error. In my code im using the function Kill on a player which works and has been tested. The SWEP has been tested many times and works great no problem with it, but even then, there keeps poping an error in the console:
[lua]weapons/sleeper/shared.lua:61: attempt to call method 'Kill' (a nil value)[/lua]
Anybody knows why it keeps saying this to me even if the SWEP works.
If you need to see my code here it is:
[lua]
if ( !self:CanPrimaryAttack() ) then return end
self:TakePrimaryAmmo( 0 )
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
self.Weapon:SetNextSecondaryFire( CurTime() + 0.5 )
local ent = self.Owner:GetEyeTrace().Entity
if ent:IsPlayer() then ent:Kill( ent ) end
if ent:IsPlayer() then ent:Lock( ent ) end
[/lua]
I didn't put all the code, only the part where im using the function.
Hope you can figure it out.
[QUOTE=Sylph;18173384]So I need a bit of help here.
I am making an Admin SWEP for my server, and the SWEP works.
The reason why im asking help is because of this weird error. In my code im using the function Kill on a player which works and has been tested. The SWEP has been tested many times and works great no problem with it, but even then, there keeps poping an error in the console:
[lua]weapons/sleeper/shared.lua:61: attempt to call method 'Kill' (a nil value)[/lua]
Anybody knows why it keeps saying this to me even if the SWEP works.
If you need to see my code here it is:
[lua]
if ( !self:CanPrimaryAttack() ) then return end
self:TakePrimaryAmmo( 0 )
self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
self.Weapon:SetNextSecondaryFire( CurTime() + 0.5 )
local ent = self.Owner:GetEyeTrace().Entity
if ent:IsPlayer() then ent:Kill( ent ) end
if ent:IsPlayer() then ent:Lock( ent ) end
[/lua]
I didn't put all the code, only the part where im using the function.
Hope you can figure it out.[/QUOTE]
This may not fix it, but try turning the
ent:Kill( ent )
into
ent:Kill()
Also change the two
if ent:IsPlayer() then
to
if ent:IsValid() and ent:IsPlayer() then
The fact of changing the:
[lua]Kill(ent)[/lua]
To:
[lua]Kill()[/lua]
Dosen't work.
I tried all you said but still doen't work, need something else :/.
Make sure its only running on the server. Kill doesn't exist clientside.
[QUOTE=foszor;18174429]Make sure its only running on the server. Kill doesn't exist clientside.[/QUOTE]
Hmm... ok, but it still works, anyway, I am implementing this function in the shared.lua file, would I need to put it in the cl_init.lua or init.lua, if so, how would I do that because the code is quite simple.
Of course it still works, because you're executing Kill on the server AND the client. You only want to do it on the server though.
[QUOTE=foszor;18174547]Of course it still works, because you're executing Kill on the server AND the client. You only want to do it on the server though.[/QUOTE]
Alright but how would you do that? make a function if ( SERVER ) ?
other than that I don't see how...
Can you help me out a bit please.
Encapsulate the portion that Kills the player in an [b]if ( SERVER ) then[/b] condition.
Alright I'll try that out in a second.
I'll get back to you if it dosen't.
Final Edit: Alright thanks, I got it working now. Thanks alot for your help and your comprehension.
BTW, to answer your earlier question
cl_init.lua is clientside only code
shared.lua is client and server code
init.lua is server only code
One of the things that bugs me is when someone get's an error they go "OMG ERROR HELP ME F1X" and they don't even read the error...
[QUOTE=Magnificor;18192033]One of the things that bugs me is when someone get's an error they go "OMG ERROR HELP ME F1X" and they don't even read the error...[/QUOTE]
Yeah that anoys me as well, this is why I always try fixing it my self, and if I can't well I ask for help and give the error report.
Sorry, you need to Log In to post a reply to this thread.