iiv03 Posted November 11, 2019 Share Posted November 11, 2019 I want to ask about knowing how this is If team1 players died and the 2 team left one player gives a number how? do i have to check the state? please i need an example Link to comment
Overkillz Posted November 11, 2019 Share Posted November 11, 2019 (edited) getPlayersInTeam isPedDead Edited November 11, 2019 by Overkillz 1 Link to comment
iiv03 Posted November 11, 2019 Author Share Posted November 11, 2019 (edited) 2 hours ago, Overkillz said: getPlayersInTeam isPedDead hello @Overkillz i make that line can you tell me is there wrong ? function pointsauto() local homeTeam = getPlayersInTeam(homeName) local players = getElementsByType(homeTeam) for id, player in pairs(players) do if isPedDead(player) and getElementData(player, "state") == "dead" then local pointE = tonumber(getElementData(team[2], "points") or 0) + 1 setElementData(team[2], "points", pointE) end local enemyTeam = getPlayersInTeam(enemyName) local players = getElementsByType(enemyName) for id, player in pairs(players) do if isPedDead(player) and getElementData(player, "state") == "dead" then local pointH = tonumber(getElementData(team[1], "points") or 0) + 1 setElementData(team[1], "points", pointH) end end end end addEventHandler("onResourceStart", getRootElement(), pointsauto) that's my try function pointsauto() local homeTeam = getPlayersInTeam(team[1]) if isPedDead(homeTeam) and getElementData(homeTeam, "state") == "dead" then local pointE = tonumber(getElementData(team[2], "points") or 0) + 1 setElementData(team[2], "points", pointE) end --[[local enemyTeam = getPlayersInTeam(enemyName) local players = getElementsByType(enemyName) for id, player in pairs(players) do if isPedDead(player) and getElementData(player, "state") == "dead" then local pointH = tonumber(getElementData(team[1], "points") or 0) + 1 setElementData(team[1], "points", pointH) end end]] end addEventHandler("onResourceStart", getRootElement(), pointsauto) this my try second i got error table in isPedDead what wrong ? EDIT:: function pointsauto() local homeTeam = getPlayersInTeam(team[1]) for k,v in ipairs(homeTeam) do local thePlayer = v if isPedDead(v) and getElementData(v, "state") == "dead" then local pointE = tonumber(getElementData(team[2], "points") or 0) + 1 setElementData(team[2], "points", pointE) end --[[local enemyTeam = getPlayersInTeam(enemyName) local players = getElementsByType(enemyName) for id, player in pairs(players) do if isPedDead(player) and getElementData(player, "state") == "dead" then local pointH = tonumber(getElementData(team[1], "points") or 0) + 1 setElementData(team[1], "points", pointH) end end]] end end addEventHandler("onResourceStart", getRootElement(), pointsauto) here i fixed but i want it through the last player of the team if he remains alive gets a point how?i wanna only last player Edited November 11, 2019 by xFabel Link to comment
Overkillz Posted November 11, 2019 Share Posted November 11, 2019 Well, Im dealing with your code and I need to say that is a bit dirty but I made few changes to let you know where you was wrong. Also, I need to say that onClientResourceStart isnt a good event to check the player alives in team. I decided to remove the function isPedDead since you are dealing with a race gamemode as far as I can see. Well, to finish this I don't recomend you to deal with homeName as team varaible and later use team[1] or team[2] function pointsauto() local homeTeamPoint = false local enemyTeamPoint = false -- LOOP FOR HOME TEAM local playersHomeTeam = getPlayersInTeam(homeName) --Assuming that homeName varaible is the team already created previously for id, player in pairs(playersHomeTeam) do if getElementData(player, "state") == "alive" then homeTeamPoint = true -- Here we say that there are alive players in home team and "MIGHT" the point foes for them break -- Here we stop the loop because there is already a player alive --setElementData(team[2], "points", 0) + 1 end end -- LOOP FOR ENEMY TEAM local playersEnemyTeam = getPlayersInTeam(enemyName) --Assuming that enemyName varaible is the team already created previously for id, player in pairs(playersEnemyTeam) do if getElementData(player, "state") == "alive" then enemyTeamPoint = true -- Here we say that there are alive players in home team and "MIGHT" the point foes for them break -- Here we stop the loop because there is already a player alive --setElementData(team[2], "points", 0) + 1 end end if homeTeamPoint ~= enemyTeamPoint then if homeTeamPoint then -- setElementData .... elseif enemyTeamPoint then -- setElementData .... end end end addEventHandler("onResourceStart", getRootElement(), pointsauto) Link to comment
iiv03 Posted November 11, 2019 Author Share Posted November 11, 2019 55 minutes ago, Overkillz said: Well, Im dealing with your code and I need to say that is a bit dirty but I made few changes to let you know where you was wrong. Also, I need to say that onClientResourceStart isnt a good event to check the player alives in team. I decided to remove the function isPedDead since you are dealing with a race gamemode as far as I can see. Well, to finish this I don't recomend you to deal with homeName as team varaible and later use team[1] or team[2] function pointsauto() local homeTeamPoint = false local enemyTeamPoint = false -- LOOP FOR HOME TEAM local playersHomeTeam = getPlayersInTeam(homeName) --Assuming that homeName varaible is the team already created previously for id, player in pairs(playersHomeTeam) do if getElementData(player, "state") == "alive" then homeTeamPoint = true -- Here we say that there are alive players in home team and "MIGHT" the point foes for them break -- Here we stop the loop because there is already a player alive --setElementData(team[2], "points", 0) + 1 end end -- LOOP FOR ENEMY TEAM local playersEnemyTeam = getPlayersInTeam(enemyName) --Assuming that enemyName varaible is the team already created previously for id, player in pairs(playersEnemyTeam) do if getElementData(player, "state") == "alive" then enemyTeamPoint = true -- Here we say that there are alive players in home team and "MIGHT" the point foes for them break -- Here we stop the loop because there is already a player alive --setElementData(team[2], "points", 0) + 1 end end if homeTeamPoint ~= enemyTeamPoint then if homeTeamPoint then -- setElementData .... elseif enemyTeamPoint then -- setElementData .... end end end addEventHandler("onResourceStart", getRootElement(), pointsauto) hey it still takes two points players if they die in the two teams I want the last player in one team only takes a point is not two teams taking themselves what caused the problem? function pointsauto() local homeTeamPoint = false local enemyTeamPoint = false -- LOOP FOR HOME TEAM local playersHomeTeam = getPlayersInTeam(team[1]) --Assuming that homeName varaible is the team already created previously for id, player in pairs(playersHomeTeam) do if getElementData(player, "state") == "alive" then homeTeamPoint = true -- Here we say that there are alive players in home team and "MIGHT" the point foes for them break -- Here we stop the loop because there is already a player alive --setElementData(team[2], "points", 0) + 1 end end -- LOOP FOR ENEMY TEAM local playersEnemyTeam = getPlayersInTeam(team[2]) --Assuming that enemyName varaible is the team already created previously for id, player in pairs(playersEnemyTeam) do if getElementData(player, "state") == "alive" then enemyTeamPoint = true -- Here we say that there are alive players in home team and "MIGHT" the point foes for them break -- Here we stop the loop because there is already a player alive --setElementData(team[2], "points", 0) + 1 end end if homeTeamPoint ~= enemyTeamPoint then if homeTeamPoint then local pointE = tonumber(getElementData(team[2], "points") or 0) + 1 setElementData(team[2], "points", pointE) elseif enemyTeamPoint then local pointH = tonumber(getElementData(team[1], "points") or 0) + 1 setElementData(team[1], "points", pointH) end end end addEventHandler("onResourceStart", getRootElement(), pointsauto) Link to comment
Overkillz Posted November 12, 2019 Share Posted November 12, 2019 (edited) Be aware about addEventHandler("onResourceStart", getRootElement(), pointsauto) It is going to add a point everytime a script is started. While changing the map it starts some scripts and might gives you troubles. You can use onClientPlayerWasted or something like that. Edited November 12, 2019 by Overkillz Link to comment
iiv03 Posted November 12, 2019 Author Share Posted November 12, 2019 (edited) 9 hours ago, Overkillz said: Be aware about addEventHandler("onResourceStart", getRootElement(), pointsauto) It is going to add a point everytime a script is started. While changing the map it starts some scripts and might gives you troubles. You can use onClientPlayerWasted or something like that. hey I used it onPlayerWasted because I am work on Server side After I tried it and didn't give any points yet if I want to ask if should be players on another team and team? because did not work with me and I am in one team and there is no one in a second team because there is a Loop? Edited November 12, 2019 by xFabel Link to comment
Overkillz Posted November 12, 2019 Share Posted November 12, 2019 1 hour ago, xFabel said: hey I used it onPlayerWasted because I am work on Server side After I tried it and didn't give any points yet if I want to ask if should be players on another team and team? because did not work with me and I am in one team and there is no one in a second team because there is a Loop? Might you are dealing with the elements wrongly. Why is there a loop if there is not anyone in a team ? The loop just check if there is an alive player. Previously the variables local homeTeamPoint = false local enemyTeamPoint = false are set with false. If the loop detects an alive player "MIGHT (As I commented in the code)" the point is for the team. Link to comment
iiv03 Posted November 12, 2019 Author Share Posted November 12, 2019 2 minutes ago, Overkillz said: Might you are dealing with the elements wrongly. Why is there a loop if there is not anyone in a team ? The loop just check if there is an alive player. Previously the variables local homeTeamPoint = false local enemyTeamPoint = false are set with false. If the loop detects an alive player "MIGHT (As I commented in the code)" the point is for the team. it's done thank you Link to comment
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