• How to find the position of any alive player?
    5 replies, posted
Hello, I am trying to attach a feature to my roll the dice script that will allow dead players on a certain team to roll for a respawn. As it is for deathrun, I need them to respawn on one of their teammates, not the spawn area. Trouble is I don't know how to go about finding an alive player and getting his position to use in a function. I believe what I have to do is create a loop that checks through all players and see if they are alive, but I don't know how to get the loop to check to make sure the player is a specific team as well and then grab his position. Currently I have [code] if chance >= 95 then local guy = POSTION OF FIRST ALIVE TEAMMATE THAT IT FINDS ply:Spawn(); ply:SetPos( guy ); rtdTextToAll(ply:Nick().." rolled a resurrection!"); else rtdClientText(ply,"Your resurrection failed!"); ply:SetNWInt("srtdLastUsed",os.time()); return false end [/code] As you can see, I would put the loop right after the first line, then have variable "guy" be defined as the position of the first alive teammate that the loop finds. So what kind of loop would I make that checks every player that is alive, and on team TEAM_RUNNER, then get this player's position? Thanks!
make a for loop containing players.GetAll() and then do "v:getpos()"
So would this do? [code] if chance >= 95 then for k, v in pairs(player.GetAll()) do if (v:Team() == TEAM_RUNNER) and (v:Alive() == true} then guy = v:GetPos() end end ply:Spawn() ply:SetPos( guy ) rtdTextToAll(ply:Nick().." rolled a resurrection!") else rtdClientText(ply,"Your resurrection failed."); ply:SetNWInt("srtdLastUsed",os.time()); return false end[/code] I feel like this wouldn't work because that would find the position of every player that meets the criteria, when we need only a single random player.
Assuming you're making this option only available to runners in your addon all you have to do is check that the player is a teammate of the said player and check if they are alive as such: [lua] for k, v in pairs (player.GetAll()) do if (v:Team() == ply:Team() and v:Alive()) then ply:Spawn() ply:SetPos(v:GetPos()) return end end [/lua]
As Doubleedge said. [editline]30th July 2015[/editline] Hai Niandra!!
[QUOTE=Doubleedge;48327899]Assuming you're making this option only available to runners in your addon all you have to do is check that the player is a teammate of the said player and check if they are alive as such: [lua] for k, v in pairs (player.GetAll()) do if (v:Team() == ply:Team() and v:Alive()) then ply:Spawn() ply:SetPos(v:GetPos()) return end end [/lua][/QUOTE] Thanks a bunch. Didn't know it was this simple!
Sorry, you need to Log In to post a reply to this thread.