DarkLink Posted June 25, 2011 Share Posted June 25, 2011 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 And I dont know how to fix it. I hope u guys know the problem, thanks alot! Link to comment
Castillo Posted June 25, 2011 Share Posted June 25, 2011 I had similar problems triggering events to client onResourceStart. Link to comment
DarkLink Posted June 25, 2011 Author Share Posted June 25, 2011 I had similar problems triggering events to client onResourceStart. hmm I see , so its a MTA problem? cant be fixed ? thanks for ur reply Link to comment
Castillo Posted June 25, 2011 Share Posted June 25, 2011 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
DarkLink Posted June 25, 2011 Author Share Posted June 25, 2011 AHAHAH LOL! The server makes things to fast, then it doesnt receive some things.. But with timer it works!! Really amazing solution Thanks alot mate! Link to comment
DiSaMe Posted June 25, 2011 Share Posted June 25, 2011 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
Wojak Posted June 25, 2011 Share Posted June 25, 2011 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
DarkLink Posted June 25, 2011 Author Share Posted June 25, 2011 Thanks alot guys, I understood the problem And the solution too ! I will use now onClientResourceStart instead of onResourceStart TY! Link to comment
Wojak Posted June 25, 2011 Share Posted June 25, 2011 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
DarkLink Posted June 25, 2011 Author Share Posted June 25, 2011 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
Backsage Posted September 22, 2018 Share Posted September 22, 2018 On 25/06/2011 at 10:57, Solidsnake14 said: I had similar problems triggering events to client onResourceStart. I had the same problem and your suggestion to use a timer worked. Link to comment
iMr.WiFi..! Posted September 22, 2018 Share Posted September 22, 2018 (edited) 4 hours ago, Backsage said: I had the same problem and your suggestion to use a timer worked. You can just give him Like/Thanks, not to reply in very old topic! Edited September 22, 2018 by iMr.WiFi..! 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