LSPD Gate System
#1

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:

PHP код:
//objects
new lspdgate1;
new 
lspdgate2;
//checkpoints
new lspdcheckpoint;
new 
lspdgateopen=0;
//timers
new lspdgatetimer
On OnGameModeInit, I have this:
PHP код:
     //Objects
     //[LSPD]
     
lspdgate1=CreateObject(9751544.64209, -1622.2741713.99633,   0.000000.0000090.77937);
    
lspdgate2=CreateObject(9751544.68726, -1626.4851114.01554,   0.000000.0000090.39678);
    
CreateObject(9701547.58594, -1635.0065913.07822,   0.000000.0000091.75994);
    
CreateObject(9701545.51624, -1632.6993412.95227,   0.000000.000000.00000);
    
CreateObject(9751544.58704, -1619.3721914.01108,   0.000000.00000270.64969);
    
    
//Checkpoints
    //[LSPD]
     
CreateCheckpoint(GLOBAL_OWNER_IDlspdcheckpoint1544.3419,-1627.1494,13.3828);
    
UsePlayerPedAnims();
    
StartCheckpointSeeking(); 
On OnCheckpointEnter:
PHP код:
public OnCheckpointEnter(playeridcheckpointid)
{
    if(
checkpointid==lspdcheckpoint)
    {
        if(
lspdgateopen==0)
        {
            
MoveObject(lspdgate11544.64209, -1622.2741710.721361.0);
            
MoveObject(lspdgate21544.68726, -1626.4851110.721361.0);
            
lspdgatetimer=SetTimer("lspdgate"5000true);
            
lspdgateopen=1;
        }
    }
    return 
1;

A timer:
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(lspdgate11544.64209, -1622.2741713.996331.0);
        
MoveObject(lspdgate21544.68726, -1626.4851114.015541.0);
        
lspdgateopen=0;
    }
    return 
1;

OnPlayerEnterCheckpoint:
PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
    
VerifyCheckpoint(playerid);
    return 
1;

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++)
Reply
#2

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(lspdgate11544.64209, -1622.2741713.996331.0);
        
MoveObject(lspdgate21544.68726, -1626.4851114.015541.0);
        
lspdgateopen=0;
    }
    return 
1;

IsPlayerInCheckpoint(i)

This function only returns 'true', or 'false'! Therefore, it will never be equal to a checkpoint ID.

KillTimer(lspdgatetimer);

This should go at the bottom, after closing the gate.
Reply
#3

So, what should I do to check if there are any players in the checkpoint?
Reply
#4

pawn Код:
forward lspdgate();
public lspdgate()
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInDynamicCP(playerid, lspdcheckpoint))
            {
                return 1;
            }
        }
    }
    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;
    }
    KillTimer(lspdgatetimer);
    return 1;
}
I'm not sure so much without streamer, that SAMP supports the actual whole checkpoint ID thing, but streamer does. So with streamer you can simply convert, then add 'IsPlayerInDynamicCP(playerid, [checkpointid])'
Reply
#5

That function is not included in this streamer.
Can you tell me any other good checkpoint streamer?
Reply
#6

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
That function is not included in this streamer.
Can you tell me any other good checkpoint streamer?
https://sampforum.blast.hk/showthread.php?tid=102865

pawn Код:
native CreateDynamicCP(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 100.0);
native DestroyDynamicCP(checkpointid);
native IsValidDynamicCP(checkpointid);
native TogglePlayerDynamicCP(playerid, checkpointid, toggle);
native TogglePlayerAllDynamicCPs(playerid, toggle);
native IsPlayerInDynamicCP(playerid, checkpointid);
native GetPlayerVisibleDynamicCP(playerid);
Reply
#7

Thank you very much
Reply
#8

What should I give instead of OnCheckPointEnter here?

EDIT: SOLVED
Reply
#9

Can I make invisible checkpoints with this?
Reply
#10

Can you show me an example of CreateDynamicCP?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)