• DarkRP Change Job?
    2 replies, posted
Hello i'm trying to make a job npc but can't get the code to work :/ [lua] function change_police( ply, team, death ) if ply:GetPos():Distance(ents.FindByClass("npc_hqs_police")[1]:GetPos()) > 200 then return false else ply:ChangeTeam( "TEAM_POLICE", true ) end end concommand.Add("_police_change", change_police) [/lua] i run it on serverside.
Somone?
You're just getting one random guy from the list, just because he's first in the table doesn't mean he's the closest to you. [lua]function JoinPolice(ply, _, _) for _,npc in pairs(ents.FindByClass("npc_hqs_police")) do // Looping through all the police guys if npc:GetPos():Distance(ply:GetPos()) < 200 then // If the npc's distance to the player is less than 200.. ply:ChangeTeam("TEAM_POLICE", true) // Change team return // Stop the function so we don't loop through more npcs in the waste end end end concommand.Add("_police_change", JoinPolice)[/lua]
Sorry, you need to Log In to post a reply to this thread.