lordkabab Posted February 13, 2009 Share Posted February 13, 2009 Is there a way to use a 'wait' command or similar in my lua so it initiates afeter a set time. I know there is the setTimer thing, but starts on the script start, I want it to wait only when it's called. Link to comment
50p Posted February 13, 2009 Share Posted February 13, 2009 setTimer() is called whenever you call it not only when resource starts, like every function. Link to comment
lordkabab Posted February 13, 2009 Author Share Posted February 13, 2009 setTimer() is called whenever you call it not only when resource starts, like every function. Then why does it do it automatically when I load the script? Link to comment
robhol Posted February 13, 2009 Share Posted February 13, 2009 setTimer() is called whenever you call it not only when resource starts, like every function. Then why does it do it automatically when I load the script? Because you told it to do that. Look in your main script body and/or onResourceStart handlers, I can practically guarantee you're going to find something. Scripts don't just decide to start a couple of timers for fun, you know... Link to comment
CodeMaster Posted February 13, 2009 Share Posted February 13, 2009 A couple of examples (since you don't wanna say us what for you need this...): This code writes a delayed "Loading finished" message for an "complex script effect" like your script needs some while to load up fully: function onStart_handler() outputChatBox("Loading the script...") setTimer(outputChatBox,3000,1,"Loaded.") end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),onStart_handler) This code will make the SA-MPish command list in a delayed variant which is quite useless, and which might be the reason you're asking this at all, but should give you the idea on how to do it: function commandList_print(player,command) outputChatBox("Command List -----------") setTimer(outputChatBox,1000,1,"/USE THE GUI, SA-MP sucks 'cause it has no gui!") setTimer(outputChatBox,2000,1,"/USE THE GUI, SA-MP sucks 'cause it has no gui!") setTimer(outputChatBox,3000,1,"/USE THE GUI, SA-MP sucks 'cause it has no gui!") setTimer(outputChatBox,4000,1,"/USE THE GUI, SA-MP sucks 'cause it has no gui!") setTimer(outputChatBox,5000,1,"/USE THE GUI, SA-MP sucks 'cause it has no gui!") end addCommandHandler("commands",commandList_print) That should do the trick, and that's efficient setTimer usage, called "inline" usage. Hope this helps Link to comment
lordkabab Posted February 15, 2009 Author Share Posted February 15, 2009 Like this? theToll = createObject ( 968, -1673.86, 522.395, 38.1261, 0, -90, -45 ) theBox = createObject ( 966, -1673.86, 522.395, 37.2995, 0, 0, -45 ) theSphere = createColSphere ( -1676.54, 525.193, 37.67, 5 ) function tollUp () moveObject ( theToll, 1000, -1673.86, 522.395, 38.1261, 0, 90, 0 ) setTimer ( tollDown, 2000, 1 ) end function tollDown () moveObject ( theToll, 1000, -1673.86, 522.395, 38.1261, 0, -90, 0 ) end addCommandHandler ( "sfseup", tollUp ) addCommandHandler ( "sfsedown", tollDown ) addEventHandler ( "onColShapeHit", theSphere, tollUp ) Link to comment
[DKR]silverfang Posted February 17, 2009 Share Posted February 17, 2009 Like this? Yes that would work fine but for your purposes the onColShapeLeave Event would be more efficient. Also you might want to make it so it's only triggered by vehicles... like this: theToll = createObject ( 968, -1673.86, 522.395, 38.1261, 0, -90, -45 ) theBox = createObject ( 966, -1673.86, 522.395, 37.2995, 0, 0, -45 ) theSphere = createColSphere ( -1676.54, 525.193, 37.67, 5 ) tollOpen = false --Add variable to show the status of the toll function tollUp (theVehicle) if getElementType ( theVehicle ) == "vehicle" and (not tollOpen) then --Test to see if it is a vehicle that hit it and the toll is closed vehicleElement = theVehicle moveObject ( theToll, 1000, -1673.86, 522.395, 38.1261, 0, 90, 0 ) --setTimer ( tollDown, 2000, 1 ) tollOpen = true end end function tollDown (theElement) if theElement == vehicleElement and (tollOpen) then -- Test to see if the Element leaving and the vehicle that triggered the toll are the same and the toll is open moveObject ( theToll, 1000, -1673.86, 522.395, 38.1261, 0, -90, 0 ) tollOpen = false end end addCommandHandler ( "sfseup", tollUp ) addCommandHandler ( "sfsedown", tollDown ) addEventHandler ( "onColShapeHit", theSphere, tollUp ) addEventHandler ( "onColShapeLeave", theSphere, tollDown ) Tested and it is perfect ... Have fun. EDITS: I have edited it a few times, as when many people arrived or left the the barrier would keep moving around so you had the barrier at funny angles. Should be perfect for what ever you want it for (NOW) 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