Jump to content

kill time


Recommended Posts

hi guys, i have a problem with some timers i need for my script to work like i want, the problem is that all works fine but the timers isnt setting for who uses /kill is setting it for all players not just client, here is my code.

local locktime = 0
local times = {} 
 
function suicide ( player, commandName )
if ( player ) and locktime == 0 then
killPed ( player )
	times[player] = setTimer(Lock,50,1)
	times[player] = setTimer(UnLock,5000,1)
elseif locktime == 1 then
outputChatBox("ERROR: You can suicide once every 1 minute.",player,255,0,0)
end
end
addCommandHandler ( "kill", suicide )
 
function Lock()
locktime = 1
end
 
function UnLock()
locktime = 0
end

Link to comment
  SolidSnake14 said:
hi guys, i have a problem with some timers i need for my script to work like i want, the problem is that all works fine but the timers isnt setting for who uses /kill is setting it for all players not just client, here is my code.
local locktime = 0
local times = {} 
 
function suicide ( player, commandName )
if ( player ) and locktime == 0 then
killPed ( player )
	times[player] = setTimer(Lock,50,1)
	times[player] = setTimer(UnLock,5000,1)
elseif locktime == 1 then
outputChatBox("ERROR: You can suicide once every 1 minute.",player,255,0,0)
end
end
addCommandHandler ( "kill", suicide )
 
function Lock()
locktime = 1
end
 
function UnLock()
locktime = 0
end

make the commandhandler clientsidded maybe

Link to comment
  [DMC] said:
...

make the commandhandler clientsidded maybe

This way he will not be able to kill the player. He'll have to triggerServerEvent which is pointless because the command can be server-side without any problems.

SolidSnake14, you have a global variable locktime which is set by any player and because it's just simple variable you check if it's already set to 1 (by other player).

Solution:

Make a table which will hold value for each player separately or use set/getElementData to determine if player used the command within the last minute. You have to remember, setTimer lets you pass additional arguments to the functions it will call, so you can pass player element to a function which would "unlock" the command for him.

NOTE: You didn't need timer to set locktime to 1. You could set it inside the if clause. You also don't need to hold timers in a table because you don't even use them anywhere, killing them, etc.

Link to comment

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