Jump to content

Set Timer


SkiZo

Recommended Posts

Posted (edited)

Hello Every One :) 

function Armor(thePlayer, commandName)
    setPedArmor ( thePlayer, 30 )
end
addCommandHandler("armor", Armor)

 

i Was Asking If There is A Solution To Make Player Use that Comman "armor" after 3 min 
When He Used He Can't Use it again only after 3min
Sorry For My Bad English :$ 

Edited by S.W.A.T
Posted (edited)

this will work 

commandTimer = {}
function Armor(thePlayer, commandName)
if isTimer(commandTimer[getPlayerSerial(thePlayer)]) then return outputChatBox( "Armor: You can't use this command right now ! You must wait "..math.floor(getTimerDetails(commandTimer[getPlayerSerial(thePlayer)])/1000).." seconds to use it again!",thePlayer, 255, 0, 0) end
    setPedArmor ( thePlayer, 30 )
	commandTimer[getPlayerSerial(thePlayer)] = setTimer(function () end, 175000, 1) 
end
addCommandHandler("armor", Armor)

 

Edited by Best-Killer
fixed
Posted (edited)

Thanks ! But :\ 
[2017-01-08 20:51:37] WARNING: Skills\jetpack.lua:99: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got nil]
[2017-01-08 20:51:37] WARNING: Skills\jetpack.lua:104: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got nil]
[2017-01-08 20:51:43] WARNING: Skills\jetpack.lua:99: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got nil]
[2017-01-08 20:51:43] WARNING: Skills\jetpack.lua:101: Bad argument @ 'getTimerDetails' [Expected lua-timer at argument 1, got nil]
[2017-01-08 20:51:43] ERROR: Skills\jetpack.lua:101: attempt to perform arithmetic on a boolean value

@Best-Killer

 

Edited by S.W.A.T
Posted
2 minutes ago, S.W.A.T said:

Thanks ! But :\ 
[2017-01-08 20:51:37] WARNING: Skills\jetpack.lua:99: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got nil]
[2017-01-08 20:51:37] WARNING: Skills\jetpack.lua:104: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got nil]
[2017-01-08 20:51:43] WARNING: Skills\jetpack.lua:99: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got nil]
[2017-01-08 20:51:43] WARNING: Skills\jetpack.lua:101: Bad argument @ 'getTimerDetails' [Expected lua-timer at argument 1, got nil]
[2017-01-08 20:51:43] ERROR: Skills\jetpack.lua:101: attempt to perform arithmetic on a boolean value

@Best-Killer

 

i edited the code go try now

Posted (edited)

Using serial to store data is not the best option cause players from some countries have same serial for lots of people. Better use:

commandTimer[thePlayer] = setTimer(function () end, 175000, 1) 
commandTimer = {}
function Armor(thePlayer, commandName)
if isTimer(commandTimer[thePlayer]) then return outputChatBox( "Armor: You can't use this command right now ! You must wait "..math.floor(getTimerDetails(commandTimer[thePlayer])/1000).." seconds to use it again!",thePlayer, 255, 0, 0) end
    setPedArmor ( thePlayer, 30 )
	commandTimer[thePlayer] = setTimer(function () end, 175000, 1) 
end
addCommandHandler("armor", Armor)

 

Edited by AfterAll14
Posted (edited)
18 minutes ago, AfterAll14 said:

Using serial to store data is not the best option cause players from some countries have same serial for lots of people. Better use:


commandTimer[thePlayer] = setTimer(function () end, 175000, 1) 

commandTimer = {}
function Armor(thePlayer, commandName)
if isTimer(commandTimer[thePlayer]) then return outputChatBox( "Armor: You can't use this command right now ! You must wait "..math.floor(getTimerDetails(commandTimer[thePlayer])/1000).." seconds to use it again!",thePlayer, 255, 0, 0) end
    setPedArmor ( thePlayer, 30 )
	commandTimer[thePlayer] = setTimer(function () end, 175000, 1) 
end
addCommandHandler("armor", Armor)

 

People in same countries had same Serial ? :o 

Well I Will Change it :) 

THANKS :)

 

Edited by S.W.A.T
Posted (edited)

Yeah, and thats ruined my race scoreboard script in which points were attached to player's serial. I hardly expected that two or more players could have common serial. And here they are :D

DNA - only way to be confident.

local DNA = getPlayerDNA(thePlayer)
someTable[DNA] = someUselessData

 

Edited by AfterAll14
  • Like 1
Posted

I don't think MTA serials have any significant probability for a collision like that. I'd even go as far as to say that the guy who played played on multiple machines, aka multiboxing.

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