Jump to content

Wait, Pause, whatever.


lordkabab

Recommended Posts

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

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

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

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

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