Jump to content

10min Round Length Timer


xXSurviverXx

Recommended Posts

Posted

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 
  

Posted

cool, and?

posting one line of code is useless, you can post nothing - it will be the same :/

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
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)

?

Posted

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 
  

Posted

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

Posted

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) 

?

Posted

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

Posted

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) 

?

Posted

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 :)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

people who do want to learn - will learn.

people who do not - wont, no matter what and how you'll tell them

?

Posted

let him try?

i dont see a point of supporting lazyness

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

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

Posted

what?

setTimer can be used both client and server side

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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