Xeno Posted January 8, 2012 Share Posted January 8, 2012 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
myonlake Posted January 8, 2012 Share Posted January 8, 2012 Are you sure the timer is created -after- the function? Link to comment
FatalTerror Posted January 8, 2012 Share Posted January 8, 2012 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
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 Yes the timer is after the function, And what do you mean by values.? I use "player" for this: local team = getPlayerTeam(player) Link to comment
myonlake Posted January 8, 2012 Share Posted January 8, 2012 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
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 Nothing is Displayed in the chat box. Link to comment
Klesh Posted January 8, 2012 Share Posted January 8, 2012 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
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 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
Klesh Posted January 8, 2012 Share Posted January 8, 2012 The code dont have any sense, what you want to do with that? Link to comment
myonlake Posted January 8, 2012 Share Posted January 8, 2012 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
Al3grab Posted January 8, 2012 Share Posted January 8, 2012 setTimer(start, 1000,1, player) you have to define who is player here Link to comment
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 EDIT: SOrry I did not see the previous posts myonlake, I wanted it so it starts a timer automatically when the resource starts. Link to comment
SDK Posted January 8, 2012 Share Posted January 8, 2012 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? Link to comment
Klesh Posted January 8, 2012 Share Posted January 8, 2012 To make the script start when resource is started, put this: addEventHandler("onClientResourceStart", getRootElement(), start) Link to comment
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 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
Castillo Posted January 8, 2012 Share Posted January 8, 2012 That's because you named your function as "setTimer". function onStart() -- Here. setTimer(start, 1000, 1, player) end addEventHandler("onClientResourceStart", resourceRoot, onStart) Link to comment
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 That works SolidSnake, but I get 1 more error saying "Expected function at argument 1, got resource-data" setTimer(start, 1000, 1, player) Link to comment
Klesh Posted January 8, 2012 Share Posted January 8, 2012 Post your whole code, and meta. Link to comment
Castillo Posted January 8, 2012 Share Posted January 8, 2012 Mind explaining what exactly are you trying to achieve? because I can't really help if I don't know what are you up to. Link to comment
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 Nevermind its fixed, I forgot to remove something. Thank you all that helped me! < I forgot to delete: addEventHandler("onClientResourceStart", getRootElement(), setTimer) Link to comment
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 Sorry for the double post, but no one would read it if I didn't: local team = getPlayerTeam(player) bad "player" pointer at getPlayerTeam Link to comment
Castillo Posted January 8, 2012 Share Posted January 8, 2012 Post your script, how do you expect us to help if you don't? Link to comment
Xeno Posted January 8, 2012 Author Share Posted January 8, 2012 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
Klesh Posted January 8, 2012 Share Posted January 8, 2012 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
Castillo Posted January 8, 2012 Share Posted January 8, 2012 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
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