06.12.2014, 06:40
I want to make a gate system. It opens when a player comes near it and closes when player goes away from it. I uses checkpoint to trigger this. I uses a checkpoint streamer: https://sampforum.blast.hk/showthread.php?tid=70963
My code is:
On OnGameModeInit, I have this:
On OnCheckpointEnter:
A timer:
OnPlayerEnterCheckpoint:
The problem is, the gate doesn't close when a player goes away from it.
It opens when a player enter that checkpoint, but doesn't close.
Also, if I stay in the checkpoint for 5 seconds, it closes, just opposite to what i wanted.
Please help me. (Rep++)
My code is:
PHP код:
//objects
new lspdgate1;
new lspdgate2;
//checkpoints
new lspdcheckpoint;
new lspdgateopen=0;
//timers
new lspdgatetimer;
PHP код:
//Objects
//[LSPD]
lspdgate1=CreateObject(975, 1544.64209, -1622.27417, 13.99633, 0.00000, 0.00000, 90.77937);
lspdgate2=CreateObject(975, 1544.68726, -1626.48511, 14.01554, 0.00000, 0.00000, 90.39678);
CreateObject(970, 1547.58594, -1635.00659, 13.07822, 0.00000, 0.00000, 91.75994);
CreateObject(970, 1545.51624, -1632.69934, 12.95227, 0.00000, 0.00000, 0.00000);
CreateObject(975, 1544.58704, -1619.37219, 14.01108, 0.00000, 0.00000, 270.64969);
//Checkpoints
//[LSPD]
CreateCheckpoint(GLOBAL_OWNER_ID, lspdcheckpoint, 1544.3419,-1627.1494,13.3828);
UsePlayerPedAnims();
StartCheckpointSeeking();
PHP код:
public OnCheckpointEnter(playerid, checkpointid)
{
if(checkpointid==lspdcheckpoint)
{
if(lspdgateopen==0)
{
MoveObject(lspdgate1, 1544.64209, -1622.27417, 10.72136, 1.0);
MoveObject(lspdgate2, 1544.68726, -1626.48511, 10.72136, 1.0);
lspdgatetimer=SetTimer("lspdgate", 5000, true);
lspdgateopen=1;
}
}
return 1;
}
PHP код:
forward lspdgate();
public lspdgate()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInCheckpoint(i)==lspdcheckpoint)
{
return 1;
}
}
}
KillTimer(lspdgatetimer);
if(lspdgateopen==1)
{
MoveObject(lspdgate1, 1544.64209, -1622.27417, 13.99633, 1.0);
MoveObject(lspdgate2, 1544.68726, -1626.48511, 14.01554, 1.0);
lspdgateopen=0;
}
return 1;
}
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
VerifyCheckpoint(playerid);
return 1;
}
It opens when a player enter that checkpoint, but doesn't close.
Also, if I stay in the checkpoint for 5 seconds, it closes, just opposite to what i wanted.
Please help me. (Rep++)