• How Kill player?
    18 replies, posted
Hello, I'm making SWEP and I'm wondering - how to kill a player when he press LMB? function SWEP:PrimaryAttack() end What now?
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8ca2.html?title=SWEP.PrimaryAttack[/url]
Self.Owner:ConComand("kill")
[lua] function SWEP:PrimaryAttack() if(self && self.Owner && SERVER)then local _Player = self.Owner; if(IsValid(_Player) && _Player:IsPlayer() && _Player:Kill)then _Player:Kill(); end end end [/lua]
[QUOTE=zzaacckk;35351407][lua] function SWEP:PrimaryAttack() if(self && self.Owner && SERVER)then local _Player = self.Owner; if(IsValid(_Player) && _Player:IsPlayer() && _Player:Kill)then _Player:Kill(); end end end [/lua][/QUOTE] Why are you checking if Kill is a valid function, obviously it is and why are you checking if self is nil, of course its not fucking nil if the function is getting called, and PrimaryAttack only works on the serverside. [lua]function SWEP:PrimaryAttack() if IsValid( self.Owner ) then self.Owner:Kill() end end[/lua]
PrimaryAttack runs shared unless you're doing it wrong.
[CODE] function SWEP:PrimaryAttack() if SERVER then self.Owner:Kill() self.Owner:ChatPrint("You appear to be dead now.") end end [/CODE] Am i late?
for the love of god, ply:Kill(). It's a function you can call. Why in the fuck would you use a concommand to do this?
[QUOTE=Chessnut;35352000]PrimaryAttack runs shared unless you're doing it wrong.[/QUOTE] Read the notes [img]http://puu.sh/n4Xs[/img]
[QUOTE=Ruzza;35351911] [lua]function SWEP:PrimaryAttack() if IsValid( self.Owner ) then self.Owner:Kill() end end[/lua][/QUOTE] Still can't kill with it or anyother ways ;/ It doesn't seems to work, I click LMB and nothing.
[QUOTE=Krizzu;35358534]Still can't kill with it or anyother ways ;/ It doesn't seems to work, I click LMB and nothing.[/QUOTE] What is IsValid? IsValid is a method you use on entities. Do if self.Owner:IsValid() then ... Your condition will always evaluate as nil, which in Lua, equates to false.
[QUOTE=Irkalla;35364410]What is IsValid? IsValid is a method you use on entities. Do if self.Owner:IsValid() then ... Your condition will always evaluate as nil, which in Lua, equates to false.[/QUOTE] if you do nil:IsValid() it will error, IsValid( entity ) and entity:IsValid() is the same thing but IsValid( entity ) is preferred because you can use it on more than just an entity.
[QUOTE=Ruzza;35355435]Read the notes[/QUOTE] That's bullshit, it gets called on the client, but not when playing singleplayer. It needs to be called clientside for prediction when playing on a server.
[LUA] function SWEP:PrimaryAttack() if (SERVER) then self.Owner:Kill() end end [/LUA] [LUA] function SWEP:PrimaryAttack() self.Owner:Kill() end [/LUA]
[QUOTE=DrJenkins;35397512][LUA] function SWEP:PrimaryAttack() if (SERVER) then self.Owner:Kill() end end [/LUA] [/QUOTE] Yep, I used it, but when i press LMB, nothing happens. O.o
[QUOTE=Krizzu;35399401]Yep, I used it, but when i press LMB, nothing happens. O.o[/QUOTE] Are you testing in singleplayer? Test it in multiplayer.
Krizzu, If you are testing in singleplayer, use the SECOND code. The first is for multiplayer
I all time test in multiplayer. Used first and not working O.o
Try the otherone
Sorry, you need to Log In to post a reply to this thread.