Wei Posted May 6, 2012 Share Posted May 6, 2012 how can I make that all players on server cannot do a command like the most system on rober of ammunation and it output chat box ammunation has been allready robbed. You need to wait (seconds) to rob it again. Link to comment
jeremaniak Posted May 6, 2012 Share Posted May 6, 2012 (edited) --addEvent maybe and cancelEvent () setTimer outputChatBox ? Edited May 6, 2012 by Guest Link to comment
Wei Posted May 6, 2012 Author Share Posted May 6, 2012 how... I know that functions. Can you give me a sample? I need to have getTickCount too... Link to comment
Wei Posted May 6, 2012 Author Share Posted May 6, 2012 I'll try... I will report again if I won't know Link to comment
Guest Guest4401 Posted May 6, 2012 Share Posted May 6, 2012 I'd go with getTickCount I don't really think setTimer should even be used. Link to comment
Wei Posted May 6, 2012 Author Share Posted May 6, 2012 how can i getTickCount transver to chat box ? Link to comment
jeremaniak Posted May 6, 2012 Share Posted May 6, 2012 Maybe create a colsphere or something and if there is already someone inside then outputchatbox something and the second person cant rob or do it with a marker time = getTickCount () outputChatBox("time:"..time, root, 255, 255, 255 , true) Link to comment
Jaysds1 Posted May 6, 2012 Share Posted May 6, 2012 like this: addEventHandler("onClientRender",root,function() tick = getTickCount() outputChatBox("Tick Count"..tick..".") end) lol, everytime a frame goes by it outputs the tick Link to comment
hxv Posted May 6, 2012 Share Posted May 6, 2012 It's all on wiki, just read it all https://wiki.multitheftauto.com/wiki/getTickCount This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task. Link to comment
Guest Guest4401 Posted May 6, 2012 Share Posted May 6, 2012 It's all on wiki, just read it allhttps://wiki.multitheftauto.com/wiki/getTickCount This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task. Exactly, I meant the same... When it is robbed, use getTickCount() to get current tick count. When someone tries to rob it again, subtract previous tick count with present tick count. Use >, <, <=, >= to see if _ seconds have passed or not. If not passed, then tell the user that he has to wait _ seconds more Link to comment
Wei Posted May 6, 2012 Author Share Posted May 6, 2012 how can I make that player need to wait 60 minutes to type command again CODE: function setTimerToNextCommand(thePlayer) local chance = math.random (1, 5) local rand = math.random ( 1000, 7000 ) if (chance == 1) then outputChatBox( "YEAH! you've got $" tonumber (rand), thePlayer, 0, 255, 0) givePlayerMoney(thePlayer, rand) else outputChatBox( "Failed", thePlayer, 0, 255, 0) end addCommandHandler("lottery buy", setTimerToNextCommand) Link to comment
Guest Guest4401 Posted May 6, 2012 Share Posted May 6, 2012 In this example the person can buy lottery only every 10 seconds interval = 10 -- in seconds function setTimerToNextCommand(thePlayer) if getTickCount() - (getElementData(thePlayer,"tick") or (-interval)*1000 ) > interval*1000 then -- if 10 seconds past since his last lottery local chance = math.random (1, 5) local rand = math.random ( 1000, 7000 ) setElementData(thePlayer,"tick",getTickCount()) -- get Current tick count and save it if (chance == 1) then outputChatBox( "YEAH! you've got $"..tonumber (rand), thePlayer, 0, 255, 0) givePlayerMoney(thePlayer, rand) else outputChatBox( "Failed", thePlayer, 0, 255, 0) end else outputChatBox("Please wait "..(interval + 1) - math.ceil((getTickCount() - getElementData(thePlayer,"tick"))/1000).." seconds more to buy lottery again",thePlayer,0,255,0) end end addCommandHandler("lotterybuy", setTimerToNextCommand) Link to comment
ben_wright Posted May 6, 2012 Share Posted May 6, 2012 just to help out, you'll have to save that data when the player logs in/out, especially if it's going to be on 1 hour cooldown. 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