Jump to content

ERROR: Server triggered clientside event showDX, but ev.....


DarkLink

Recommended Posts

Okay guys, I am having here a major bug that I really need to fixed it. But cant ..

So I am having these error on clientscript:

  
[2011-06-25 18:37:43] ERROR: Server triggered clientside event showDX, but event is not added clientside 
  

And its everything okay to me, add event true.. the handler is okay too..

CLIENT SIDE:

  
    addEvent ( "showDX", true ) 
    function showNumbersDX () 
      addEventHandler ( "onClientRender", getRootElement(), drawDX ) 
    end 
    addEventHandler ( "showDX", getRootElement(), showNumbersDX ) 
      
     
    addEvent ( "hideDX", true ) 
    function hideNumbersDX () 
      removeEventHandler ( "onClientRender", getRootElement(), drawDX) 
    end 
    addEventHandler ( "hideDX", getRootElement(), hideNumbersDX ) 
     
     
    function drawDX ()       
         
        X,Y = guiGetScreenSize () 
        X = X * (2.5/3) 
        Y = Y * (1/4) 
        dxDrawText ( getElementData(getLocalPlayer(),"secondsRemaining"), X, Y, X, Y, tocolor(255, 255, 255, 255), 5) 
    end 
  

SERVER SIDE:

  
    segundos = 30 
    timerEnabled = false 
      
    function onJoin () 
        if gamemodeStarted == false then 
            setElementData(source,"secondsRemaining",tostring(segundos)) 
             
            --if timerEnabled then 
                --setElementData(source,"secondsRemaining",tostring(segundos)) 
                --triggerClientEvent ( source, "showDX", source) 
            --end 
       
            if(getPlayerCount() >= 2) then 
                escreve() 
            end 
         
        end 
       
        end 
    addEventHandler ( "onPlayerJoin", getRootElement(), onJoin ) 
      
    function escreve () 
        timerEnabled = true 
        for i,v in pairs(getElementsByType("player")) do 
            setElementData(v,"secondsRemaining",tostring(segundos)) 
            triggerClientEvent ( v, "showDX", v ) 
        end 
        setTimer(countDown,1000,30) 
    end 
    
      
    function countDown() 
        segundos = segundos -1 
            for i,v in pairs(getElementsByType("player")) do 
                setElementData(v,"secondsRemaining",tostring(segundos)) 
            end 
            if segundos <= 0 then 
                triggerClientEvent ( "hideDX", getRootElement() ) 
                timerEnabled = false 
                spawn() 
                gamemodeStarted = true 
            end 
    end 
      
    function onStart () 
        timerEnabled = false 
            if(getPlayerCount() >= 2) then 
                 
                --for i, v in ipairs(getElementsByType("player")) do 
                    --setElementData(v,"secondsRemaining",tostring(segundos)) 
                --end 
             
                escreve() 
            end 
    end 
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart ) 
  

I think was Solid Snake that helped me doing this timer with DxDrawText (thanks btw)

Now I changed somethings to do this:

when resource stops, and then start again.. if there are more than 2 players the timer will start again.. and ofc the gamemode too.

But when I try to do that. 2 players on server.

I STOP resource.

I START resource.

then the timer dont appear.. and I get that error on clientscript.

I guess its weird :S

And I dont know how to fix it.

I hope u guys know the problem, thanks alot!

Link to comment

Yes, you can use a timer and it will work.

segundos = 30 
    timerEnabled = false 
      
    function onJoin () 
        if gamemodeStarted == false then 
            setElementData(source,"secondsRemaining",tostring(segundos)) 
            
            --if timerEnabled then 
                --setElementData(source,"secondsRemaining",tostring(segundos)) 
                --triggerClientEvent ( source, "showDX", source) 
            --end 
      
            if(getPlayerCount() >= 2) then 
                escreve() 
            end 
        
        end 
      
        end 
    addEventHandler ( "onPlayerJoin", getRootElement(), onJoin ) 
      
    function escreve () 
        timerEnabled = true 
        for i,v in pairs(getElementsByType("player")) do 
            setElementData(v,"secondsRemaining",tostring(segundos)) 
            triggerClientEvent ( v, "showDX", v ) 
        end 
        setTimer(countDown,1000,30) 
    end 
    
      
    function countDown() 
        segundos = segundos -1 
            for i,v in pairs(getElementsByType("player")) do 
                setElementData(v,"secondsRemaining",tostring(segundos)) 
            end 
            if segundos <= 0 then 
                triggerClientEvent ( "hideDX", getRootElement() ) 
                timerEnabled = false 
                spawn() 
                gamemodeStarted = true 
            end 
    end 
      
    function onStart () 
        timerEnabled = false 
            if(getPlayerCount() >= 2) then 
                
                --for i, v in ipairs(getElementsByType("player")) do 
                    --setElementData(v,"secondsRemaining",tostring(segundos)) 
                --end 
            
                setTimer(escreve,1000,1) 
            end 
    end 
    addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart ) 

Link to comment

When the resource starts serverside, it hasn't started clientside yet. If event is triggered before the resource which adds it is downloaded, that will result in an error. Using a timer isn't reliable - you can't be sure that client will download the resource before the timer function gets executed. It's better to trigger server event onClientResourceStart, so the server knows the resource has started clientside, and then showDX can be triggered.

Link to comment
When the resource starts serverside, it hasn't started clientside yet. If event is triggered before the resource which adds it is downloaded, that will result in an error. Using a timer isn't reliable - you can't be sure that client will download the resource before the timer function gets executed. It's better to trigger server event onClientResourceStart, so the server knows the resource has started clientside, and then showDX can be triggered.

yes, that's exactly the problem here...

i always add

triggerServerEvent("onResourcenameClientFileDownload", getLocalPlayer()) 

at the end of the clientside file, if its triggered you can safely trigger client events from the server, DarkLink you may use it instead of "onPlayerJoin"

Link to comment
I will use now onClientResourceStart instead of onResourceStart

onResourceStart is triggered only once

onClientResourceStart is triggered every time a player downloads the resource clientside file (but only once per client unlill disconect, it will be triggered again after reconnect )

so if you want to replace the startup code "onResourceStart" and run it with a custom event triggered by "onClientResourceStart" it will be like starting a new resource every time a player join the server (you will eventually run out of memory, and same stuff will be run multiple times)

but "onClientResourceStart" may be used for detecting if it's safe to trigger client events to a specyfic client

Link to comment
I will use now onClientResourceStart instead of onResourceStart

onResourceStart is triggered only once

onClientResourceStart is triggered every time a player downloads the resource clientside file (but only once per client unlill disconect, it will be triggered again after reconnect )

so if you want to replace the startup code "onResourceStart" and run it with a custom event triggered by "onClientResourceStart" it will be like starting a new resource every time a player join the server (you will eventually run out of memory, and same stuff will be run multiple times)

but "onClientResourceStart" may be used for detecting if it's safe to trigger client events to a specyfic client

Okay , didnt know that will be trigger like infinite times (each client start resource)

Solved some of my problems now :)

Thanks alot wojak ;)

Link to comment
  • 7 years later...

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...