Hello everyone,
Now, I've been [u]attempting[/u] to code and LR (last request) system for Garry's Mod Jailbreak, and it's going quite well. However, I wan't to check if the player is last alive, and I've been having some trouble.
I know how to check if the player is just generally alive, but I need to know if there the [b]last alive[/b] on that team (prisoners).
All help is appreciated!
Thanks in advance,
Myles
Get the list of the players on your prisoners team [url=http://wiki.garrysmod.com/page/team/GetPlayers]team.GetPlayers[/url]
Create a table
Iterate through the list of players in your team
If they are alive, add them to the table
After that's done, check if the length of the table storing alive players is 1
If so, the first (and only) item in that table is your surviving player
Do this in a [url=http://wiki.garrysmod.com/page/GM/PlayerDeath]PlayerDeath[/url] hook.
Few ways, but to make things simple, it would be nice to know what type of jailbreak you are using, as it may contain some helpful hooks.
Thank you for your help, Internet1001 c: Since I'm kinda a noob is there a chance you could provide a small segment of code that I could learn from?
[lua]hook.Add( "PlayerDeath", "LastRequest", function() -- hooking PlayerDeath
local alive_prisoners = {} -- table to store alive prisoners
for k, ply in pairs( team.GetPlayers( TEAM_PRISONERS ) ) do -- iterate through the players on team TEAM_PRISONERS
if ply:Alive() then table.insert( alive_prisoners, ply ) end -- if the player is alive then add them to the table
end
if #alive_prisoners == 1 then hook.Call( "LastRequest", GM, alive_prisoners[1] ) end -- Call the hook "LastRequest" which passes on the only alive prisoner
end )[/lua]
And this would go in they "init.lua" file, correct? - Also, thank you for writing out the code, as well as helping me with this :3
[editline]26th August 2014[/editline]
Ok, thank you so much! It's all working! When it releases I will give you some credit for helping with the code :D
What if that last prisoner is rebelling?
They will be able to pick an LR, however. If the guards know that the prisoner is rebelling, then the other guards can kill him / her during the LR.
Sorry, you need to Log In to post a reply to this thread.