xXSurviverXx Posted November 23, 2010 Share Posted November 23, 2010 Hey all i know how to make a timer but i need the timer to display how much time is left on the screen this is the code im using to display the time left in --:-- dxDrawText(tostring (timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,1000),1.3,"Diploma","right","top",false,false,false) -- Timer Link to comment
dzek (varez) Posted November 23, 2010 Share Posted November 23, 2010 cool, and? posting one line of code is useless, you can post nothing - it will be the same Link to comment
Aibo Posted November 23, 2010 Share Posted November 23, 2010 function getTimeLeft(timer) if isTimer(timer) then local ms = getTimerDetails(timer) local m = math.floor(ms/60000) local s = math.floor((ms-m*60000)/1000) if m < 10 then m = "0"..m end if s < 10 then s = "0"..s end return m..":"..s else return "--:--" end end also "sWidth-0" is useless, max alpha is 255 (tocolor(225,225,225,255)) and font name is "diploma", not "Diploma" (though it maybe not case-sensitive) Link to comment
xXSurviverXx Posted November 23, 2010 Author Share Posted November 23, 2010 Thanks a lot man but now how do i display it on the screen this is the code i use to display health armour money and ammo on the screen dxDrawText(tostring(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,1000),1.3,"Diploma","right","top",false,false,false) -- Timer Link to comment
Aibo Posted November 23, 2010 Share Posted November 23, 2010 instead of "tostring(timer)" place "getTimeLeft(timer)", assuming the "timer" variable exists. Link to comment
xXSurviverXx Posted November 24, 2010 Author Share Posted November 24, 2010 i know ur trying to help, but this is like the first script im working on for mta and its hard timer = setTimer(getTimeLeft,600000,1) function getTimeLeft(timer) dxDrawText(getTimeLeft(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,1000),1.3,"Diploma","right","top",false,false,false) -- Timer if isTimer(timer) then local ms = getTimerDetails(timer) local m = math.floor(ms/60000) local s = math.floor((ms-m*60000)/1000) if m < 10 then m = "0"..m end if s < 10 then s = "0"..s end return m..":"..s else return "--:--" end end and if you cant help with that, i have TeamViewer ill pm you the id and pass Link to comment
Aibo Posted November 24, 2010 Share Posted November 24, 2010 oh my god timer = setTimer(outputChatBox, 600000, 1, "Time's up!") function getTimeLeft(timer) if isTimer(timer) then local ms = getTimerDetails(timer) local m = math.floor(ms/60000) local s = math.floor((ms-m*60000)/1000) if m < 10 then m = "0"..m end if s < 10 then s = "0"..s end return m..":"..s else return "--:--" end end addEventHandler("onClientRender", getRootElement(), function() dxDrawText(getTimeLeft(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,255),1.3,"diploma","right","top",false,false,false) -- Timer end) Link to comment
xXSurviverXx Posted November 24, 2010 Author Share Posted November 24, 2010 thanks so fucking much and yes i understand your"oh my god" i feel the same way thanks anyways though, you dont know how much you helped me out <3 Link to comment
xXSurviverXx Posted November 24, 2010 Author Share Posted November 24, 2010 umm one problem the timer works great and all, but it is for each person, i want i global by that i mean if the timer is at 5:36 i want it to stay at 5:36 for the person that joins, not start all over just for him. thanks Link to comment
Aibo Posted November 24, 2010 Share Posted November 24, 2010 well then you need to make main timer server-side, and on client join send to him the time that's left, and start his timer for dx display with that value. server: timer = setTimer(function() -- something to do when timer stops maybe end, 600000, 1) addEvent("requestTimeLeft", true) addEventHandler("requestTimeLeft", getRootElement(), function() local ms = 0 if isTimer(timer) then ms = getTimerDetails(timer) end triggerClientEvent(source, "serverStartsTimer", getRootElement(), ms) end) client: timer = false addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() triggerServerEvent("requestTimeLeft", getLocalPlayer()) -- asking the server how much time left on client resource start end) addEvent("serverStartsTimer", true) addEventHandler("serverStartsTimer", getRootElement(), -- reply from the server with time left function(ms) timer = setTimer(outputChatBox, ms, 1, "Time's up!") -- setting the timer with time we got from server end) function getTimeLeft(timer) if isTimer(timer) then local ms = getTimerDetails(timer) local m = math.floor(ms/60000) local s = math.floor((ms-m*60000)/1000) if m < 10 then m = "0"..m end if s < 10 then s = "0"..s end return m..":"..s else return "--:--" end end addEventHandler("onClientRender", getRootElement(), function() if timer then -- to check if timer started dxDrawText(getTimeLeft(timer),sWidth-0,sHeight-600,sWidth-347,sHeight-0,tocolor(225,225,225,255),1.3,"diploma","right","top",false,false,false) -- Timer end end) Link to comment
dzek (varez) Posted November 24, 2010 Share Posted November 24, 2010 Aiboforcen, maybe instead making ready scripts for him try to teach him something? xXSurviverXx, this is way too hard script as for beginner. I'd like to invite you to our wiki: https://wiki.multitheftauto.com/ Please check out Scripting box on main page Link to comment
Aibo Posted November 24, 2010 Share Posted November 24, 2010 people who do want to learn - will learn. people who do not - wont, no matter what and how you'll tell them Link to comment
dzek (varez) Posted November 24, 2010 Share Posted November 24, 2010 let him try? i dont see a point of supporting lazyness Link to comment
Wojak Posted November 24, 2010 Share Posted November 24, 2010 this don't need to be done from scratch... There is a nice core resource design for that: https://wiki.multitheftauto.com/wiki/Res ... ssiontimer Link to comment
xXSurviverXx Posted November 24, 2010 Author Share Posted November 24, 2010 you both have good points this is how i learned for samp scripting, and i thought this is how ill learn for mta, i have taken a look at wiki, but it does not provide as much information i need, and this server and client thing is just not provided in setTimer for wiki, its only client Link to comment
dzek (varez) Posted November 25, 2010 Share Posted November 25, 2010 what? setTimer can be used both client and server side 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