Dynamic Checkpoint
#1

Hey guys, I started to create a Dynamic Entrance System, with checkpoints. And this is my code:
pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    Loop(i, MAX_ENTRANCES)
    {
        if(checkpointid == Entrance[i][EnterCP])
        {
            Ent[playerid] = i;
            SetPlayerPosEx(playerid, Entrance[i][Exit][0], Entrance[i][Exit][1], Entrance[i][Exit][2], Entrance[i][Interior], i);
            break;
        }
        else if(checkpointid == Entrance[i][ExitCP])
        {
            Ent[playerid] = 0;
            SetPlayerPosEx(playerid, Entrance[i][Enter][0], Entrance[i][Enter][1], Entrance[i][Enter][2], 0, 0);
            break;
        }
    }
    return 1;
}
The problem is, if I enter an entrance, it will be automatically do enter-exit loop.
Does anyone know whats wrong with my code ?
Reply
#2

Well, I suppose there's nothing wrong with your code; it does what you ask it to do.

Quote:

it will be automatically do enter-exit loop.

You've made so it will execute the function as soon as someone enters either enter CP or exit one; which will cause you exiting whatever instantly as you enter.
You might want to do /enter-/exit commands.
Or make a timer to set that a variable that the user has just entered/exited and will clear it after X seconds. (I'd suggest /enter /exit tho)
Reply
#3

telport players in front of checkpoit
because if you teleport player in checkpint exit position, player again will tp exit of interior and again tp to interior and loop
or you can make a variable !
when player teleport to interior set it to 1 and if that variable value was 1, checkpoint don't teleport player and when player leave checkpoint set variable to 0.
i hope you undrestand...
i'll give you an example

pawn Код:
new DebugCP[MAX_PLAYERS];


public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    Loop(i, MAX_ENTRANCES)
    {
      if(DebugCP[playerid] == 0)
      {
         if(checkpointid == Entrance[i][EnterCP])
         {
            DebugCP[playerid] = 1; //Set variable to 1. this mean player teleported and don't teleport player until player didn't leave CP
            Ent[playerid] = i;
            SetPlayerPosEx(playerid, Entrance[i][Exit][0], Entrance[i][Exit][1], Entrance[i][Exit][2], Entrance[i][Interior], i);
            break;
         }
         else if(checkpointid == Entrance[i][ExitCP])
         {
            DebugCP[playerid] = 1;
            Ent[playerid] = 0;
            SetPlayerPosEx(playerid, Entrance[i][Enter][0], Entrance[i][Enter][1], Entrance[i][Enter][2], 0, 0);
            break;
         }
      }
    }
    return 1;
}
public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
    Loop(i, MAX_ENTRANCES)
    {
      if(DebugCP[playerid] == 1)
      {
         if(checkpointid == Entrance[i][EnterCP])
         {
            DebugCP[playerid] = 0; //Set variable to 0. when player enter a CP again, teleport him !
         }
         else if(checkpointid == Entrance[i][ExitCP])
         {
            DebugCP[playerid] = 0;
         }
      }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)