Will Gmod allow me to use player:kill() in shared.lua?
Fretta gamemode, and I have no time to test ATM so I'm asking the n00by question.
Thanks in advance!
[url]http://wiki.garrysmod.com/?title=Player.Kill[/url]
Because using the wiki is [I]that[/I] hard.
This guy might not be aware that there is a wiki, not sure why he wouldn't be aware of it, but still.
[QUOTE=LuckyLuke;22899816]This guy might not be aware that there is a wiki, not sure why he wouldn't be aware of it, but still.[/QUOTE]
[img]http://content.screencast.com/users/kingFlawless/folders/Jing/media/d16d9606-22f2-43d6-aeb9-870f52d71137/2010-06-26_1546.png[/img]
I know that there is a wiki, and use it often, but did not know wether or not shared lua files could contain server commands.
A better question is: How can I get player:kill() to work in shared.lua?
By encapsulating it in
[lua]if ( SERVER ) then
end[/lua]
or using a serverside hook.
Ok, will this work in a SWEP as primary fire?
EG:
[lua]
function SWEP:PrimaryAttack()
local Aim = self.Owner:GetEyeTrace()
if Aim.Entity:IsPlayer() and Aim.Entity:GetTeam() == "ENEMY" then
AimEnt:kill()
else
self.Owner:kill()
end
end
[/lua]
[QUOTE=|King Flawless|;22900318][img]http://content.screencast.com/users/kingFlawless/folders/Jing/media/d16d9606-22f2-43d6-aeb9-870f52d71137/2010-06-26_1546.png[/img][/QUOTE]
That's the Joke ...
I know there is a wiki and use it alot!!
Is it me or do you want your code so that if the player is not looking at another player or NPC it kills the player?
Exactly. Making this for TTT, for the Detective.
[lua]
function SWEP:PrimaryAttack()
local Aim = self.Owner:GetEyeTrace()
if Aim.Entity:IsPlayer() and Aim.Entity:GetRole() == "ROLE_TRAITOR" then
AimEnt:Kill()
else
self.Owner:Kill()
end
end
[/lua]
Will the kill part work? Forget about the GetRole etc.
[QUOTE=EMB;22901185]Exactly. Making this for TTT, for the Detective.
[lua]
function SWEP:PrimaryAttack()
local Aim = self.Owner:GetEyeTrace()
if Aim.Entity:IsPlayer() and Aim.Entity:GetRole() == "ROLE_TRAITOR" then
AimEnt:Kill()
else
self.Owner:Kill()
end
end
[/lua]
Will the kill part work? Forget about the GetRole etc.[/QUOTE]
The Kill() parts should work.
Even though it's in shared.lua?
Thanks!
I originally had it as:
[lua]
function SWEP:PrimaryAttack()
local AimEnt = self.Owner:GetEyeTrace().Entity
if AimEnt:IsPlayer() and AimEnt:GetRole() == "ROLE_TRAITOR" then
AimEnt:kill()
else
self.Owner:kill()
end
end
[/lua]
But that wouldn't have worked, even with the edit, would it?
Oh, ok then.
Just remember: shared files are run by both the client and the server. You can make it so a part of a shared file is only run by the client or the server by using the convenient "CLIENT" and "SERVER" expressions.
Ok, it doesn't work (not that I could get any really good test conditions).
IE it always kills the user.
Any suggestions? BTW if anyone would like to help me test it, please do contact me.
Don't use "ROLE_TRAITOR", because it's an enumeration (variable that is an equilevent for a number). Take off the quotes and use ROLE_TRAITOR.
K, will test tomorrow.
Sorry, you need to Log In to post a reply to this thread.