Newbie Posted May 1, 2014 Share Posted May 1, 2014 local x,y = guiGetScreenSize() local defScale = 1 local currentScale = defScale local maxScale = 2 local step = 0.05 -- How fast to change the size local turn = true -- true = increase size, false = decrease size local text = "Loading next map" local font = dxCreateFont("myFont.ttf",10) function renderPulse() if turn == true then -- If we increase the value currentScale = currentScale + step if currentScale > maxScale then currentScale = maxScale turn = false -- Reached max? Then make it go back end else currentScale = currentScale - step if currentScale < defScale then currentScale = defScale turn = true end end local width = dxGetTextWidth(text,currentScale,font) local height = dxGetFontHeight(currentScale,font) dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) end addEventHandler("onClientRender",getRootElement(),renderPulse) I need to make this work only if race state is "LoadingMap" Link to comment
Dealman Posted May 1, 2014 Share Posted May 1, 2014 function exampleFunction_Handler(newState, oldState) if(newState == "LoadingMap") then -- Your code here end end addEvent("onRaceStateChanging", false) addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) This event is server-side. Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 Well, i know. Thats why im asking bcz my code is client sided Link to comment
Gallardo9944 Posted May 1, 2014 Share Posted May 1, 2014 Oh wow, full copypaste of my example Use triggerClientEvent. Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 Oh wow, full copypaste of my example Use triggerClientEvent. Yes its yours, i find dat in forum. Thanks Link to comment
Dealman Posted May 1, 2014 Share Posted May 1, 2014 You'll need to change the boolean from false to true if you want to be able to remotely trigger it from a client. Nvm, misunderstood what you're trying to do. Just create an event for your client-side function, and trigger it via the server-side event I provided. Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 A little help mby ? function exampleFunction_Handler(newState, oldState) if(newState == "LoadingMap") then triggerClientEvent ( dont know what to write here.) end end addEvent("onRaceStateChanging", false) addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) Link to comment
Dealman Posted May 1, 2014 Share Posted May 1, 2014 Create the event client-side using addEvent, then use an event handler. IE; function myClientFunction_Handler() -- Wow, such code. Very program end addEvent("myEvent", true) -- True means you can trigger this event via the server. False means you can not. addEventHandler("myEvent", getRootElement(), myClientFunction_Handler) -- You'll of course need an event handler. Then trigger it via the server like this; triggerClientEvent("myEvent", getRootElement()) -- This will trigger for all players. triggerClientEvent(playerElement, "myEvent", getRootElement()) -- This will trigger for the specified player element only. Edit: Of course you can use it to transfer data as well. Example; function myServerFunction_Handler() local argumentOne = "Hello World!"; local argumentTwo = 1.337; triggerClientEvent("myEvent", getRootElement(), argumentOne, argumentTwo) end function myClientFunction_Handler(arg1, arg2) -- You can define those with whatever name you want outputChatBox(arg1) outputChatBox(tostring(arg2)) -- Since 2nd variable is a float value - convert it to a string end addEvent("myEvent", true) addEventHandler("myEvent", getRootElement(), myClientFunction_Handler) Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 Did i fail ? Client: local x,y = guiGetScreenSize() local defScale = 1 local currentScale = defScale local maxScale = 2 local step = 0.05 -- How fast to change the size local turn = true -- true = increase size, false = decrease size local text = "Loading next map" local font = dxCreateFont("myFont.ttf",10) function myClientFunction_Handler() if turn == true then -- If we increase the value currentScale = currentScale + step if currentScale > maxScale then currentScale = maxScale turn = false -- Reached max? Then make it go back end else currentScale = currentScale - step if currentScale < defScale then currentScale = defScale turn = true end end local width = dxGetTextWidth(text,currentScale,font) local height = dxGetFontHeight(currentScale,font) dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) end addEvent("myEvent", true) addEventHandler("myEvent", getRootElement(), myClientFunction_Handler) Server: function exampleFunction_Handler(newState, oldState) if(newState == "LoadingMap") then triggerClientEvent(playerElement, "myEvent", getRootElement()) end end addEvent("onRaceStateChanging", false) addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) Link to comment
Dealman Posted May 1, 2014 Share Posted May 1, 2014 Well you need to define the player element. As of now it's returning nil - and as such the event won't be triggered. Try removing the playerElement. Then it will trigger for all players currently on the server. Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 I think it dont work because i'd had to remove this line: addEventHandler("onClientRender",getRootElement(),renderPulse) Link to comment
Karuzo Posted May 1, 2014 Share Posted May 1, 2014 local x,y = guiGetScreenSize() local defScale = 1 local currentScale = defScale local maxScale = 2 local step = 0.05 -- How fast to change the size local turn = true -- true = increase size, false = decrease size local text = "Loading next map" local font = dxCreateFont("myFont.ttf",10) function myClientFunction_Handler() if turn == true then -- If we increase the value currentScale = currentScale + step if currentScale > maxScale then currentScale = maxScale turn = false -- Reached max? Then make it go back end else currentScale = currentScale - step if currentScale < defScale then currentScale = defScale turn = true end end local width = dxGetTextWidth(text,currentScale,font) local height = dxGetFontHeight(currentScale,font) dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) end function AddingEvent() addEventHandler("onClientRender",root,myClientFunction_Handler) end addEvent("myEvent", true) addEventHandler("myEvent", getRootElement(), AddingEvent) Link to comment
Karuzo Posted May 1, 2014 Share Posted May 1, 2014 Well you need to define the player element. As of now it's returning nil - and as such the event won't be triggered. Try removing the playerElement.Then it will trigger for all players currently on the server. Did you do that? Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 (edited) READ PAGE 2 Edited May 1, 2014 by Guest Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 (edited) It starts when state is LoadingMap but dont stops when state loadingMap finished Edited May 2, 2014 by Guest Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 How to kill it on state Running Link to comment
Karuzo Posted May 1, 2014 Share Posted May 1, 2014 --server function exampleFunction_Handler(newState, oldState) if(newState == "LoadingMap") then triggerClientEvent(playerElement, "myEvent", getRootElement()) elseif (newState == "Running") then triggerClientEvent(playerElement,"removeEvent",getRootElement()) end end addEvent("onRaceStateChanging", false) addEventHandler("onRaceStateChanging", getRootElement(), exampleFunction_Handler) --client local x,y = guiGetScreenSize() local defScale = 1 local currentScale = defScale local maxScale = 2 local step = 0.05 -- How fast to change the size local turn = true -- true = increase size, false = decrease size local text = "Loading next map" local font = dxCreateFont("myFont.ttf",10) function myClientFunction_Handler() if turn == true then -- If we increase the value currentScale = currentScale + step if currentScale > maxScale then currentScale = maxScale turn = false -- Reached max? Then make it go back end else currentScale = currentScale - step if currentScale < defScale then currentScale = defScale turn = true end end local width = dxGetTextWidth(text,currentScale,font) local height = dxGetFontHeight(currentScale,font) dxDrawText(text,x/2-width/2,y/2-height/2,width,height,tocolor(255,255,255,255),currentScale,font) end function AddingEvent() addEventHandler("onClientRender",root,myClientFunction_Handler) end addEvent("myEvent", true) addEventHandler("myEvent", getRootElement(), AddingEvent) function RemovingEvent() removeEventHandler("onClientRender",root,myClientFunction_Handler) end addEvent("removeEvent", true) addEventHandler("removeEvent", getRootElement(), RemovingEvent) Link to comment
Newbie Posted May 1, 2014 Author Share Posted May 1, 2014 Thanks. I've removed playerElement otherwise i was getting a nil. Link to comment
Karuzo Posted May 1, 2014 Share Posted May 1, 2014 ah yeah, was my mistake. You're welcome. Link to comment
Newbie Posted May 2, 2014 Author Share Posted May 2, 2014 it works perfectly, but when i login with /login it starts to bug, it shows all the time.. Strange.. 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