20.01.2017, 04:19
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:
P.s. I have used a similar method in the past which worked successfully.
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;
}