Gravestone Posted April 1, 2016 Posted April 1, 2016 (edited) Like I posted before, this post is related to the previous one. So basically this code selects whether the person goes to Police or Drug dealer. I want random selection, I mean a player types /dd and he is selected in the team. The selection should be done 1 by 1 so there are equal number of players in each team. * fixed * Edited April 10, 2016 by Guest
Moderators IIYAMA Posted April 3, 2016 Moderators Posted April 3, 2016 local theTeams = {"Drug Dealers", "Police"} addCommandHandler("dd", function(player) local team = getTeamFromName(theTeams[math.random(#theTeams)]) if team then -- does the team exist? setPlayerTeam(player, team) spawnPlayer(player, 1585.5485839844, -1677.8289794922, 5.8969912528992) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 280) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 0, 0, 255) outputChatBox("#0000ff(Mission) #8e8c00Kill the #fff000Drug Lord #8e8c00before he delievers the drugs!", player, 255, 255, 255, true) else outputDebugString("Team not found!") end end)
Gravestone Posted April 9, 2016 Author Posted April 9, 2016 What about the Drug Dealers team's properties? Your code will only select the teams randomly, I want 1 by 1 selection. setPlayerTeam(player, getTeamFromName("Drug Dealers")) spawnPlayer(player, 1887.6721191406, -2473.6330566406, 13.53911781311) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, math.random(1, 200)) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 255, 0, 0) outputChatBox("#ff0000(Mission) #8e8c00Help the #fff000Drug Lord #8e8c00to deliever the drugs!", player, 255, 255, 255, true) end
Gravestone Posted April 9, 2016 Author Posted April 9, 2016 What about the Drug Dealers team's properties? Your code will only select the teams randomly, I want 1 by 1 selection. setPlayerTeam(player, getTeamFromName("Drug Dealers")) spawnPlayer(player, 1887.6721191406, -2473.6330566406, 13.53911781311) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, math.random(1, 200)) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 255, 0, 0) outputChatBox("#ff0000(Mission) #8e8c00Help the #fff000Drug Lord #8e8c00to deliever the drugs!", player, 255, 255, 255, true) end
Moderators IIYAMA Posted April 9, 2016 Moderators Posted April 9, 2016 Try this: local theTeams = {"Drug Dealers", "Police"} local sortAtPlayersInTeam = function (teamNameA,teamNameB) local teamA, teamB = getTeamFromName(teamNameA), getTeamFromName(teamNameB) if teamA and teamB then local playersInTeamA = getPlayersInTeam (teamA) local playersInTeamB = getPlayersInTeam (teamB) return playersInTeamA > playersInTeamB or (playersInTeamA == playersInTeamB and math.random(2) == 1) end return false end addCommandHandler("dd", function(player) table.sort(theTeams, sortAtPlayersInTeam) local team = getTeamFromName(theTeams[1]) if team then -- does the team exist? setPlayerTeam(player, team) spawnPlayer(player, 1585.5485839844, -1677.8289794922, 5.8969912528992) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 280) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 0, 0, 255) outputChatBox("#0000ff(Mission) #8e8c00Kill the #fff000Drug Lord #8e8c00before he delievers the drugs!", player, 255, 255, 255, true) else outputDebugString("Team not found!") end end)
Moderators IIYAMA Posted April 9, 2016 Moderators Posted April 9, 2016 Try this: local theTeams = {"Drug Dealers", "Police"} local sortAtPlayersInTeam = function (teamNameA,teamNameB) local teamA, teamB = getTeamFromName(teamNameA), getTeamFromName(teamNameB) if teamA and teamB then local playersInTeamA = getPlayersInTeam (teamA) local playersInTeamB = getPlayersInTeam (teamB) return playersInTeamA > playersInTeamB or (playersInTeamA == playersInTeamB and math.random(2) == 1) end return false end addCommandHandler("dd", function(player) table.sort(theTeams, sortAtPlayersInTeam) local team = getTeamFromName(theTeams[1]) if team then -- does the team exist? setPlayerTeam(player, team) spawnPlayer(player, 1585.5485839844, -1677.8289794922, 5.8969912528992) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 280) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 0, 0, 255) outputChatBox("#0000ff(Mission) #8e8c00Kill the #fff000Drug Lord #8e8c00before he delievers the drugs!", player, 255, 255, 255, true) else outputDebugString("Team not found!") end end)
Gravestone Posted April 9, 2016 Author Posted April 9, 2016 If the player is selected as a drug dealer, his properties will be set same as the army guy's.
Gravestone Posted April 9, 2016 Author Posted April 9, 2016 If the player is selected as a drug dealer, his properties will be set same as the army guy's.
Moderators IIYAMA Posted April 9, 2016 Moderators Posted April 9, 2016 If the player is selected as a drug dealer, his properties will be set same as the army guy's. local theTeams = {"Drug Dealers", "Police"} local sortAtPlayersInTeam = function (teamNameA,teamNameB) local teamA, teamB = getTeamFromName(teamNameA), getTeamFromName(teamNameB) if teamA and teamB then local playersInTeamA = getPlayersInTeam (teamA) local playersInTeamB = getPlayersInTeam (teamB) return playersInTeamA > playersInTeamB or (playersInTeamA == playersInTeamB and math.random(2) == 1) end return false end addCommandHandler("dd", function(player) table.sort(theTeams, sortAtPlayersInTeam) local teamName = theTeams[1] local team = getTeamFromName(teamName) if team then -- does the team exist? if teamName == "Police" then setPlayerTeam(player, getTeamFromName("Police")) spawnPlayer(player, 1585.5485839844, -1677.8289794922, 5.8969912528992) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 280) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 0, 0, 255) outputChatBox("#0000ff(Mission) #8e8c00Kill the #fff000Drug Lord #8e8c00before he delievers the drugs!", player, 255, 255, 255, true) elseif teamName == "Drug Dealers" then setPlayerTeam(player, team) spawnPlayer(player, 1585.5485839844, -1677.8289794922, 5.8969912528992) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 280) giveWeapon(player, 22, 200) setPlayerNametagColor(player, 0, 0, 255) outputChatBox("#0000ff(Mission) #8e8c00Kill the #fff000Drug Lord #8e8c00before he delievers the drugs!", player, 255, 255, 255, true) end else outputDebugString("Team not found!") end end)
Gravestone Posted April 15, 2016 Author Posted April 15, 2016 Error at line 9, attempt to compare two table values.
Moderators IIYAMA Posted April 15, 2016 Moderators Posted April 15, 2016 local playersInTeamA = #getPlayersInTeam (teamA) local playersInTeamB = #getPlayersInTeam (teamB)
Gravestone Posted April 19, 2016 Author Posted April 19, 2016 Random selection is working, but I want to disable the /dd and /lord when the player is already selected in a team and show an error, "You can not change your team now!".
Moderators IIYAMA Posted April 19, 2016 Moderators Posted April 19, 2016 if getPlayerTeam(player) then --... else outputChatBox("You can not change your team now!", player) end
Gravestone Posted April 20, 2016 Author Posted April 20, 2016 It is showing the message when I first type /dd and is not selecting me in a team.
Moderators IIYAMA Posted April 20, 2016 Moderators Posted April 20, 2016 Then you are already in a team or you added it wrong.
Moderators IIYAMA Posted April 20, 2016 Moderators Posted April 20, 2016 addCommandHandler("dd", function(player) if getPlayerTeam(player) then -- the rest of the code. else outputChatBox("You can not change your team now!", player) end end)
Gravestone Posted April 21, 2016 Author Posted April 21, 2016 (edited) Same error, selecting me in the team when I'm already in team and not selecting me when I am not in a team. Edited April 21, 2016 by Guest
Moderators IIYAMA Posted April 21, 2016 Moderators Posted April 21, 2016 addCommandHandler("dd", function(player) if not getPlayerTeam(player) then table.sort(theTeams, sortAtPlayersInTeam) local teamName = theTeams[1] local team = getTeamFromName(teamName) if team then -- does the team exist? if teamName == "US Army" then setPlayerTeam(player, getTeamFromName("US Army")) spawnPlayer(player, 1585.5485839844, -1677.8289794922, 5.8969912528992) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 163) giveWeapon(player, 31, 500) giveWeapon(player, 29, 200) giveWeapon(player, 24, 100) setPlayerNametagColor(player, 221, 177, 0) blipua = createBlipAttachedTo(player, 0, 2, 221, 177, 0) outputChatBox("#0000ff(Mission) #8e8c00Kill the #328c6eDrug Lord #8e8c00before he delievers the drugs!", player, 255, 255, 255, true) elseif teamName == "Drug Dealers" then setPlayerTeam(player, team) spawnPlayer(player, 1484.75549, -666.62592, 95.60126) setCameraTarget(player, player) fadeCamera(player, true) setElementModel(player, 29) giveWeapon(player, 30, 500) --Give him a weapon pack giveWeapon(player, 23, 50) giveWeapon(player, 25, 30) setPlayerNametagColor(player, 168, 0, 255) blipdd = createBlipAttachedTo(player, 0, 2, 168, 0, 255) outputChatBox("#008AB0(Mission) #8e8c00Help the #328c6eDrug Lord #8e8c00to deliever the drugs!", player, 255, 255, 255, true) end end else outputChatBox("#FF0000Error: You can not change your team now", player, 255, 255, 255, true) end end)
Gravestone Posted April 21, 2016 Author Posted April 21, 2016 Same problem. Selecting me in the team when I move myself to a team through admin panel and not selecting when I'm not in a team.
Moderators IIYAMA Posted April 21, 2016 Moderators Posted April 21, 2016 Same problem. Selecting me in the team when I move myself to a team through admin panel and not selecting when I'm not in a team. nope, if [b][color=#FF0000]not[/color][/b] getPlayerTeam(player) then -- set in team Make sure you update the version correctly.
Gravestone Posted April 21, 2016 Author Posted April 21, 2016 Yeah it's working. I posted the same comment 2 times. I was commenting and the comment wasn't appearing on the first page. I'm pretty new here so I thought the comments will continue on the same page. Sorry.
Gravestone Posted May 8, 2016 Author Posted May 8, 2016 The script doesn't select 1 by 1, it is still selecting players randomly.
Moderators IIYAMA Posted May 8, 2016 Moderators Posted May 8, 2016 The script doesn't select 1 by 1, it is still selecting players randomly. Selecting players randomly? You never said anything about random players, only (random + 1 by 1) adding player to team. Which is doing that. If you still have your doubts about that, why don't you check theTeams table?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now