Avagard Posted May 3, 2017 Share Posted May 3, 2017 i have a question. for example if i have 30 players in my server will in this code it will set "roundswonbyct1" 30 times and will it trigger 30 times???? here is the code(serverSide): cttime1 = setTimer( function() local getCTscore1 = getElementData(scoreCT1,"roundswonbyct1") local getTscore1 = getElementData(scoreT1,"roundswonbyt1") local players = getElementsByType ( "player" ) for theKey,thePlayers in ipairs ( players ) do local playerTeamCT1 = getTeamName(getPlayerTeam(thePlayers)) if getElementDimension ( thePlayers ) == 0 then if ( playerTeamCT1 ) == "Counter Terrorist" then if getElementData ( thePlayers , "alive" ) == true then setElementData(scoreCT1,"roundswonbyct1",getElementData(scoreCT1,"roundswonbyct1")+1) triggerClientEvent ( thePlayers, "getitServer1",thePlayers, getCTscore1,getTscore1) triggerClientEvent (thePlayers, "TimeEndRestartCT1",thePlayers) end end end end end, 129000, 0) if yes.. then i don`t want that i just want to check if players in terrorist team are alive!!! please tell me how to fix that IF YES and also please explain if not, then tell me its okay ty Link to comment
NeXuS™ Posted May 3, 2017 Share Posted May 3, 2017 This'll trigger the number of alive CT players. What do you want to do exactly? Check if there is any alive player from the terrorist team? Link to comment
Avagard Posted May 3, 2017 Author Share Posted May 3, 2017 (edited) 1 hour ago, NeXuS™ said: This'll trigger the number of alive CT players. What do you want to do exactly? Check if there is any alive player from the terrorist team? i don't want that... i want to trigger it for all alive CT players how do i fix that? i don't want it to trigger 30 times wtf D: Edited May 3, 2017 by Avagard Link to comment
NeXuS™ Posted May 3, 2017 Share Posted May 3, 2017 It'll only trigger for alive CT players. "This'll trigger the number of alive CT players." So if there are 10 alive CTs, it'll trigger 10 times. Link to comment
DNL291 Posted May 4, 2017 Share Posted May 4, 2017 11 hours ago, Avagard said: if yes.. then i don`t want that i just want to check if players in terrorist team are alive Then just use the event onPlayerWasted and check the team of player who died, or depending on how it should be use this function https://wiki.multitheftauto.com/wiki/GetAlivePlayersInTeam. Link to comment
Avagard Posted May 4, 2017 Author Share Posted May 4, 2017 i don't want that i just want to trigger the event for all alive ct players, which means if there are 5 alive ct players then it get trigged only for them, i don't want to trigger it 10 times will this do? cttime1 = setTimer( function() local getCTscore1 = getElementData(scoreCT1,"roundswonbyct1") local getTscore1 = getElementData(scoreT1,"roundswonbyt1") local playerTeamCT1 = getTeamName(getPlayerTeam(resourceRoot)) if getElementDimension ( resourceRoots ) == 0 then if ( playerTeamCT1 ) == "Counter Terrorist" then if getElementData ( resourceRoot , "alive" ) == true then setElementData(scoreCT1,"roundswonbyct1",getElementData(scoreCT1,"roundswonbyct1")+1) triggerClientEvent ("getitServer1",resourceRoot, getCTscore1,getTscore1) triggerClientEvent ("TimeEndRestartCT1",resourceRoot) end end end end, 129000, 0) Link to comment
Avagard Posted May 4, 2017 Author Share Posted May 4, 2017 EDITTTTTTTTTTTTTTT now will this do it? cttime1 = setTimer( function() local players = getPlayersInTeam ( CT ) for playerKey, playerValue in ipairs ( players ) do if getElementDimension ( playerValue ) == 0 then if getElementData ( playerValue , "alive" ) == true then triggerClientEvent ("TimeEndRestartCT1",playerValue) end end end end, 129000, 0) it won't trigger 10 times if players in ct are 10 alive, right? Link to comment
Gordon_G Posted May 4, 2017 Share Posted May 4, 2017 (edited) 7 minutes ago, Avagard said: EDITTTTTTTTTTTTTTT now will this do it? cttime1 = setTimer( function() local players = getPlayersInTeam ( CT ) for playerKey, playerValue in ipairs ( players ) do if getElementDimension ( playerValue ) == 0 then if getElementData ( playerValue , "alive" ) == true then triggerClientEvent ("TimeEndRestartCT1",playerValue) end end end end, 129000, 0) it won't trigger 10 times if players in ct are 10 alive, right? If there a 10 players in CT team alive, it'll trigger the client event 10 times. Want do you want to do exactly ? Edited May 4, 2017 by Gordon_G Link to comment
Avagard Posted May 4, 2017 Author Share Posted May 4, 2017 (edited) i do not want to trigger it 10 times i just want to trigger it ONE TIME for every CT team players alive WHEN TIME ENDS but i do not know how Edited May 4, 2017 by Avagard Link to comment
Gordon_G Posted May 4, 2017 Share Posted May 4, 2017 (edited) Yes, it'll work if CT value is goodly a team created in the same resource Edited May 4, 2017 by Gordon_G 1 Link to comment
DNL291 Posted May 4, 2017 Share Posted May 4, 2017 13 hours ago, Avagard said: i don't want that i just want to trigger the event for all alive ct players, which means if there are 5 alive ct players then it get trigged only for them, i don't want to trigger it 10 times will this do? It will always trigger depending on the number of team members, you can't simply trigger 1 time for many players because the client-side runs individually. Link to comment
Avagard Posted May 5, 2017 Author Share Posted May 5, 2017 9 hours ago, DNL291 said: It will always trigger depending on the number of team members, you can't simply trigger 1 time for many players because the client-side runs individually. so what should i do??? Link to comment
Avagard Posted May 5, 2017 Author Share Posted May 5, 2017 (edited) i tried to learn something, will this work? cttime1 = setTimer( function() local playerTeamCT1 = getTeamName(getPlayerTeam(getRootElement()) if getElementDimension ( getRootElement() ) == 0 then if ( playerTeamCT1 ) == "Counter Terrorist" then if getElementData ( getRootElement() , "alive" ) == true then triggerClientEvent ("TimeEndRestartCT1",getRootElement()) end end end end end, 129000, 0) Edited May 5, 2017 by Avagard Link to comment
Gordon_G Posted May 5, 2017 Share Posted May 5, 2017 (edited) If you put getRootElement() it ill trigger the client event for everyone, not only for the players who are in the CT team, I do not thing it's what you want to do. You should keep the last code you did, because here, there is no loop, so the execution of the triggerClientEvent can't work. You can not define getRootElement() to take all the players. What @DNL291 said was not in order to modify your code, that was just a right information Edited May 5, 2017 by Gordon_G Link to comment
pa3ck Posted May 5, 2017 Share Posted May 5, 2017 (edited) 13 hours ago, DNL291 said: It will always trigger depending on the number of team members, you can't simply trigger 1 time for many players because the client-side runs individually. That's wrong, you can trigger to multiple clients that are inside a table without using a loop. Wiki says: If you specify a single player it will just be sent to that player. This argument can also be a table of player elements. Pseudo code to achieve what you want without triggering multiple times: local teamMembers = getAllMembers() -- get list of team members local triggerTo = {} -- init an empty table for k, v in ipairs(teamMembers) -- loop through the possible team members if(isAlive(v) and whateverYouWant(v)) then -- conditions to meet table.insert(triggerTo) -- they met the conditions, put them in the table we created end end triggerClientEvent(triggerTo, "myEvent", resourceRoot ) -- use the triggerTo table as the sendTo argument Keep in mind, that's a non-working code, you can't just copy-paste it, fill in the blanks, this way you will not trigger inside the loop Edited May 5, 2017 by pa3ck Link to comment
Avagard Posted May 5, 2017 Author Share Posted May 5, 2017 (edited) will this work? local teamMembers = getPlayersInTeam ( T ) local triggerTo = {} for k, v in ipairs(teamMembers) if getElementDimension ( v ) == 0 and getElementData ( v , "alive" ) == true then table.insert(triggerTo) end end triggerClientEvent(triggerTo, "TimeEndRestartCT1", resourceRoot ) Edited May 5, 2017 by Avagard Link to comment
pa3ck Posted May 5, 2017 Share Posted May 5, 2017 (edited) That should work as long as "T" is an actual team element (you're also missing the "do" after (teamMembers)) Edited May 5, 2017 by pa3ck Link to comment
Avagard Posted May 5, 2017 Author Share Posted May 5, 2017 (edited) ok and how do i reset the table? for example when someone leaves the lobby (a gamemode i am using) or when someone switches the team is this not important and the script can do it automatically? Edited May 5, 2017 by Avagard Link to comment
pa3ck Posted May 5, 2017 Share Posted May 5, 2017 Well, that will only run once, you will need to call it inside a setTimer or attach it to an event, eg. when the round ends etc, but yes, whenever it triggers, it will update the table automatically. 1 Link to comment
Avagard Posted May 5, 2017 Author Share Posted May 5, 2017 oh, okay i wasted your time.. thank you very much! Link to comment
pa3ck Posted May 5, 2017 Share Posted May 5, 2017 No, you did not waste my time at all, you're welcome. Link to comment
DNL291 Posted May 5, 2017 Share Posted May 5, 2017 9 hours ago, pa3ck said: That's wrong, you can trigger to multiple clients that are inside a table without using a loop. Wiki says: If you specify a single player it will just be sent to that player. This argument can also be a table of player elements. Pseudo code to achieve what you want without triggering multiple times: local teamMembers = getAllMembers() -- get list of team members local triggerTo = {} -- init an empty table for k, v in ipairs(teamMembers) -- loop through the possible team members if(isAlive(v) and whateverYouWant(v)) then -- conditions to meet table.insert(triggerTo) -- they met the conditions, put them in the table we created end end triggerClientEvent(triggerTo, "myEvent", resourceRoot ) -- use the triggerTo table as the sendTo argument Keep in mind, that's a non-working code, you can't just copy-paste it, fill in the blanks, this way you will not trigger inside the loop Will not that method in pratice trigger for each player? Since client unlike server side executes for a specific player. If using a table of player elements it works, can you explain me how the MTA internally will execute this function using a table on 'sendTo' argument? @Avagard: If your code already works, you don't have to worry about it, you will waste your time. Otherwise, make sure your code doesn't use too much bandwidth, in this case you can explain what you want to achieve and we can give you alternatives. 1 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