Jump to content

A question about setTimer's


Xeno

Recommended Posts

If I was going to set a timer on a function, and I was using "player", would I make the timer like this:

setTimer(wafflecheese, 1000,1, player) 

Because I get a bad argument if I put it in the function like this,

function wafflecheese(player) 

Link to comment
Are you sure the timer is created -after- the function?

Not necessarily...

If I was going to set a timer on a function, and I was using "player", would I make the timer like this:
setTimer(wafflecheese, 1000,1, player) 

Because I get a bad argument if I put it in the function like this,

function wafflecheese(player) 

Are you sure "player" have an value ?

Test the value

  
if player then 
setTimer(wafflecheese, 1000, 1, player) 
else 
outputChatBox("No value") 
end 
  

Link to comment

Check it out.

function wafflecheese(player) 
    if player then 
        outputChatBox("Value found.", player, 0, 255, 0, false) 
    else 
        outputChatBox("Value not found.", player, 255, 0, 0, false) 
    end 
end 
  
addCommandHandler("execute", 
function(player, cmd) 
    setTimer(wafflecheese, 1000, 1, player) 
end) 

Link to comment
function timerHandler (thePlayer) 
    setTimer(set, 1000, 1, thePlayer) 
end 
addEventHandler("onResourceStart", getResourceRootElement(),timerHandler) 
function set (thePlayer) 
    if (thePlayer) then 
        outputChatBox("Value found.", thePlayer, 0, 255, 0, false) 
        timerHandler(thePlayer) 
    else 
        outputChatBox("Value not found.", player, 255, 0, 0, false) 
    end 
end 

Link to comment

Shall I just give you some of my script?

  
  
function start() 
  
crate = createObject(2991,-1353,-185,14) 
  
local team = getPlayerTeam(player) 
if team then 
    local police = getTeamFromName("Police") 
    if (team == police) then 
  
    end 
elseif team then 
local police = getTeamFromName("Criminals") 
  
end 
end 
-setTimer(start, 1000,1, player) 

Link to comment

Code had no sense, what a MESS.

I have no idea what did you want to do with it but created something with it.

Command: /check

local crate = createObject(2991, -1353, -185, 14) 
  
function start(player) 
    local team = getPlayerTeam(player) 
    if team then 
        local police = getTeamFromName("Police") 
        local criminals = getTeamFromName("Criminals") 
         
        if (team == police) then 
            outputChatBox("You're a police officer.", source, 0, 255, 0, false) 
        elseif (team == criminal) then 
            outputChatBox("You're a criminal.", source, 0, 255, 0, false) 
        end 
    end 
end 
  
addCommandHandler("check", 
function(player, cmd) 
    setTimer(start, 1000, 1, player) 
end) 

Link to comment
To make the script start when resource is started, put this:
addEventHandler("onClientResourceStart", getRootElement(), start) 

I mean so it starts the timer off:

  
function setTimer(player) 
    setTimer(start, 1000, 1, player) 
end 
addEventHandler("onClientResourceStart", getRootElement(), setTimer) 

But I get an error saying Stacked Overflow -- Whatever that means?

And SDK, No I have not, all I need is a timer that sets off the function once, sorry I wasn't very clear lol.

Link to comment
function start(player) 
crate = createObject(2991,-1353,-185,14) 
  
    local team = getPlayerTeam(player) 
local object = createObject(2991, -1353, -185, 14) 
    if team then 
        local police = getTeamFromName("Police") 
        local criminals = getTeamFromName("Criminals") 
        
        if (team == police) then 
            outputChatBox("You're a police officer.", source, 0, 255, 0, false) 
        elseif (team == criminal) then 
            outputChatBox("You're a criminal.", source, 0, 255, 0, false) 
        end 
    end 
end 
  
function onStart(player) -- Here. 
    setTimer(start, 7500, 1, player) 
  
end 
addEventHandler("onResourceStart", getRootElement(), onStart) 

Link to comment
function start(source, player) 
    crate = createObject(2991,-1353,-185,14) 
      
        local team = getPlayerTeam(source) 
    local object = createObject(2991, -1353, -185, 14) 
        if team then 
            local police = getTeamFromName("Police") 
            local criminals = getTeamFromName("Criminals") 
            
            if (team == police) then 
                outputChatBox("You're a police officer.", source, 0, 255, 0, false) 
            elseif (team == criminal) then 
                outputChatBox("You're a criminal.", source, 0, 255, 0, false) 
            end 
        end 
    end 
      
    function onStart(player) -- Here. 
        setTimer(start, 7500, 1, player) 
      
    end 
    addEventHandler("onResourceStart", getRootElement(), onStart) 

Link to comment
function start(player) 
crate = createObject(2991,-1353,-185,14) 
  
    local team = getPlayerTeam(player) 
local object = createObject(2991, -1353, -185, 14) 
    if team then 
        local police = getTeamFromName("Police") 
        local criminals = getTeamFromName("Criminals") 
        
        if (team == police) then 
            outputChatBox("You're a police officer.", player, 0, 255, 0, false) 
        elseif (team == criminal) then 
            outputChatBox("You're a criminal.", player, 0, 255, 0, false) 
        end 
    end 
end 
  
function onStart(player) 
    setTimer(function () 
        for index, player in ipairs(getElementsByType("player")) do 
            start(player) 
        end 
    end, 7500, 1) 
end 
addEventHandler("onResourceStart", resourceRoot, onStart) 

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