• Zip Ties, Un-Tie Players on Death
    16 replies, posted
So earlier I asked for assistance in altering my Zip Ties, now I have noticed another issue. Players who are killed while zip-tied remain zip-tied into the next life. They can run full speed and switch weapons and what not, but some actions, such as picking up weapons are restricted. I was curious how I would go about making it so the script would end/set the player un-tied if they were to die. Here is the code involved: Would this function do it? [code] --- Again I have very limited LUA knowledge and even scraping this up took me a good 15 minutes to figure out something that actually sounded remotely right. function meta:DeadPlayer if ply.nextspawn and Entity:IsTied() then return self.TiedUp = false end
Hook into PlayerDeath and then check if they're tied, and if so, un-tie them.
[code] hook.Add("PlayerDeath", "untieDeath", function(p) if (p:IsTied()) then p:UntiePlayer(p); end end); [/code] Also a personal note here, your function names are a bit silly and so is the layout of your function declarations. [code] target:TieUpPlayer(player_tying_me_up) [/code] Is silly. It should either be: [code] target:TieUp(player_tying_me_up) [/code] Or: [code] player_tying_me_up:TieUpPlayer(target) [/code] But its just a personal preference. Also you might want to look into [URL="http://wiki.garrysmod.com/page/GM/FindUseEntity"]GM:FindUseEntity[/URL] or [URL="http://wiki.garrysmod.com/page/GM/PlayerUse"]GM:PlayerUse[/URL] for your "E to tie" thingy.
[QUOTE=G4MB!T;45520541][code] hook.Add("PlayerDeath", "untieDeath", function(p) if (p:IsTied()) then p:UntiePlayer(p); end end); [/code] Also a personal note here, your function names are a bit silly and so is the layout of your function declarations. [code] target:TieUpPlayer(player_tying_me_up) [/code] Is silly. It should either be: [code] target:TieUp(player_tying_me_up) [/code] Or: [code] player_tying_me_up:TieUpPlayer(target) [/code] But its just a personal preference. Also you might want to look into [URL="http://wiki.garrysmod.com/page/GM/FindUseEntity"]GM:FindUseEntity[/URL] or [URL="http://wiki.garrysmod.com/page/GM/PlayerUse"]GM:PlayerUse[/URL] for your "E to tie" thingy.[/QUOTE] I am stupid, if I add this to the LUA file, it is not shared.lua, would it require a map change to take effect?
There are a few ways of reloading scripts but for simplicity I think you should restart the server.
That did not work :/
[QUOTE=Frubbs;45520806]That did not work :/[/QUOTE] Care to be a little more specific?
Players remain tied on respawn.
Ok I'v amended the code. Try this: [code] hook.Add("PlayerDeath", "untieDeath", function(p) print("Player has died."); if (p:IsTied()) then print("Player is tied... untying"); p:UntiePlayer(p); end end); [/code] Tell us what it prints in the console.
[QUOTE=G4MB!T;45521028]Ok I'v amended the code. Try this: [code] hook.Add("PlayerDeath", "untieDeath", function(p) print("Player has died."); if (p:IsTied()) then print("Player is tied... untying"); p:UntiePlayer(p); end end); [/code] Tell us what it prints in the console.[/QUOTE] Nothing is printed in console. Does this function need to go in lua/autorun/server? Currently I have it in the code with the other stuff. [url]http://puu.sh/auaSt/7dc964b1e1.png[/url]
Ye sorry, PlayerDeath is a server-side hook.
So could I put it in an if (SERVER) then and be fine?
Yes as long as the script is also being run on the server.
[code] if (SERVER) then hook.Add("PlayerDeath", "untieDeath", function(p) print("Player has died."); if (p:IsTied()) then print("Player is tied... untying"); p:UntiePlayer(p); end end); end [/code] Still not functioning and nothing printing in console. The file is being used on the server as well.
Where is the file located? The hook should be called whenever someone dies and if it isnt, its probably not being run.
I did it for him. The UntiePlayer function had EVERYTHING in a timer, so it's useless when you want to untie a player immediately. I just added a PlayerDeath hook with the relevant code to untie the player (set the var to false) The code was put in a file called "arrest.lua", which is serverside.
Nicely done.
Sorry, you need to Log In to post a reply to this thread.