Jump to content

A question about setTimer's


Xeno

Recommended Posts

Posted

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) 

Posted
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 
  

Posted

Yes the timer is after the function,

And what do you mean by values.?

I use "player" for this:

local team = getPlayerTeam(player) 

Posted

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) 

Posted
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 

Posted

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) 

Posted

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) 

Posted

EDIT: SOrry I did not see the previous posts

myonlake, I wanted it so it starts a timer automatically when the resource starts.

Posted

I just tried to decipher this topic, but I can't make sense of it. Is your problem fixed now?

If not, what are you trying to do? Also important, is it client or serverside?

Posted

To make the script start when resource is started, put this:

addEventHandler("onClientResourceStart", getRootElement(), start) 

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

Posted

That's because you named your function as "setTimer".

function onStart() -- Here. 
    setTimer(start, 1000, 1, player) 
end 
addEventHandler("onClientResourceStart", resourceRoot, onStart) 

Posted

That works SolidSnake, but I get 1 more error saying

"Expected function at argument 1, got resource-data"

  setTimer(start, 1000, 1, player) 

Posted

Nevermind its fixed, I forgot to remove something.

Thank you all that helped me! <

I forgot to delete:

addEventHandler("onClientResourceStart", getRootElement(), setTimer) 

Posted

Sorry for the double post, but no one would read it if I didn't:

local team = getPlayerTeam(player) 

bad "player" pointer at getPlayerTeam 

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

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

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

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