Check if object fully closed or opened
#4

A timer is un-necessary and I recommend using the following callback, which is called when an object finishes moving..

https://sampwiki.blast.hk/wiki/OnObjectMoved

A similar callback is available for player objects and dynamic objects.

I assume you're using something like the following function to open/close it:

https://sampwiki.blast.hk/wiki/MoveObject

When using the move object function, I would set a variable belonging to the gate to indicate it is moving (not fully opened or closed). Then at the OnObjectMoved callback, set the variable to some number to indicate opened/closed position. For example, some psuedo code of how I might do it:

PHP код:
//Some Defines
#define GATE_POS_CLOSED 0
#define GATE_POS_OPENING 1
#define GATE_POS_OPEN 2
#define GATE_POS_CLOSING 3
//Some Variables
new myGate CreateObject(...);
new 
myGatePos;
public 
OnObjectMoved(objectid)
{
    if (
objectid == myGate)
    {
        
//Check if object was opening..
        
if (myGatePos == GATE_POS_OPENING)
        {
            
myGatePos GATE_POS_OPEN;    //Mark gate as now open
        
}
        
        
//Check if object was closing
        
else if (myGatePos == GATE_POS_CLOSING)
        {
            
myGatePos GATE_POS_CLOSED;    //Mark gate as now closed
        
}
    }    
    return 
1;
}
SomeGateMovingFunction(...)
{    
    if (
myGatePos == GATE_POS_OPEN)
    {
        
MoveObject(myGate, ... to closed coordinates ...);    //Mov object toward closed pos
        
myGatePos GATE_POS_CLOSING;                //Mark object as closing
        
    
}
    
    else if (
myGatePos == GATE_POS_CLOSED)
    {
        
MoveObject(myGate, ... to closed coordinates ...);    //Move gate toward open pos
        
myGatePos GATE_POS_OPENING;                //Mark object as opening
    
}    
    return 
value;
        

P.s. I have used a similar method in the past which worked successfully.
Reply


Messages In This Thread
Check if object fully closed or opened - by MerryDeer - 20.01.2017, 03:32
Re: Check if object fully closed or opened - by AndreiWow - 20.01.2017, 03:58
Re: Check if object fully closed or opened - by MerryDeer - 20.01.2017, 04:04
Re: Check if object fully closed or opened - by Nate4 - 20.01.2017, 04:19
Re: Check if object fully closed or opened - by Sew_Sumi - 20.01.2017, 04:31
Re: Check if object fully closed or opened - by Nate4 - 20.01.2017, 04:39
Re: Check if object fully closed or opened - by Sew_Sumi - 20.01.2017, 04:42

Forum Jump:


Users browsing this thread: 1 Guest(s)