Jump to content

question


Recommended Posts

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
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 by Avagard
Link to comment

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

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
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 by Gordon_G
Link to comment
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

 

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 by Avagard
Link to comment

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 :D

Edited by Gordon_G
Link to comment
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 by pa3ck
Link to comment

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 by Avagard
Link to comment
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.

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...