Jump to content

HELP - Event triggering problem.


Father0625

Recommended Posts

Hello guys its me again, i have some bull:~ problem.

I cant trigger a client event, and i dont know why, because normally i can.. Sorry for my bad english, im not the best.

 

So the problem. Im making an event system to my server on my own way, like "TDM" or "Race" events. In the test now, i can start it with /testrace comamnd, then something happens to all players on the server, because i only do test it with my best friend, so we 2 guys on the server and no more.

Everything good, only the Client side event isnt triggered. But what is wrong? Because no errors in the server's command line.

 

I want to do, when i use a command, a client side event do runs for all online player.

What do i do wrong?

 

Script_serverside:

 

 

local racer_players = {

}

function testrace(player, command)


  local players = getElementsByType ( "player" )
  for theKey,thePlayer in ipairs(players)
     triggerClientEvent("raceCevent", thePlayer) -- Only this isnt running!
     outputChatBox("for thePlayer", thePlayer, 255, 0, 0)
     table.insert( racer_players, theKey, thePlayer)
  end


  outputChatBox("Server script is working further..", player, 255, 0, 0)
  triggerEvent("race_start", root)

end
addCommandHandler('race', testrace)

addEvent( "race_start", true )
addEventHandler( "race_start", root, function()
  outputChatBox("race_start event is triggered", player, 255, 0, 0)
  for theKey,thePlayer in ipairs(racer_players) do 

    --I do some script here, doesnt matters
  end

end)

 

Script_clientside

addEvent("raceCevent", true)
addEventHandler("raceCevent", localPlayer, function()
  outputChatBox("raceCevent is triggered!", 0, 255, 0)

end)

 

On the server: https://prnt.sc/7Fb8rWxxSjbo

No errors in the command line.

What is bad? :(

 

Thanks for help guys!

- Father

Link to comment
  • Moderators
3 hours ago, Father0625 said:
triggerClientEvent("raceCevent", thePlayer) 

 

3 hours ago, Father0625 said:
addEventHandler("raceCevent", localPlayer, function()

Normally this combination should be working.

 

But there is one thing that is incorrect, and that is where the event is triggered.

Currently it should trigger for all players, but multiplied by the amount of players. Since there is no player target set to where the event is sending to.

triggerClientEvent("raceCevent", thePlayer) 

 

My recommendations:

Serverside

triggerClientEvent(
  thePlayer, -- send to this player
  "raceCevent", 
  resourceRoot -- source is resourceRoot
) 

 

Clientside

addEvent("raceCevent", true)
addEventHandler("raceCevent", 
resourceRoot, -- activate the event based on the source resourceRoot
function ()
    
end, false) -- disable propagate for security reasons

 

  • Thanks 2
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...