Trying Checkpoints :)
#1

Hello!

So, I tried to make a checkpoint...Everything is working fine, but checkpoint doesn't want to show again after 5 seconds : (

Code:

pawn Код:
new money[MAX_PLAYERS];

forward GiveMoney(playerid);

public GiveMoney(playerid)
{
    GivePlayerMoney(playerid, 2500);
    SendClientMessage(playerid, -1, "You have earned 2500 cash!");
    DisablePlayerCheckpoint(playerid);
    return 1;
}
forward EnableMoney(playerid);

public EnableMoney(playerid)
{
    money[playerid] = SetPlayerCheckpoint(playerid, 1958.3783, 1343.1572, 15.3746, 2.0);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    money[playerid] = SetPlayerCheckpoint(playerid, 1958.3783, 1343.1572, 15.3746, 2.0);
    return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
    if(money[playerid])
    {
      SendClientMessage(playerid, -1, "Stay in Checkpoint for 10 seconds!");
      SetTimerEx("GiveMoney", 10000, false, "i", playerid);
    }
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    SetTimerEx("EnableMoney", 5000, false, "i", playerid);
    return 1;
}
Thanks for help
Reply
#2

Well, because simply when somebody enters a ckeckpoint, a timer of 10 seconds starts, but when he leave it another one of 5 seconds starts, now the 5 seconds one recreates the checkpoint for the player, but when the 10 seconds is finished, the checkpoint will be destroyed and the "OnPlayerLeaveCheckpoint" callback wouldnt be called anymore to recreate it, its just a logical opration

i suggest that you start the "EnableMoney" timer inside the "GiveMoney" one, like that you make sure that the checkpoint gets destroyed and recreated after 5 seconds
Reply
#3

something like this i guess ?
pawn Код:
new money[MAX_PLAYERS];
new MoneyTimer[MAX_PLAYERS];

forward GiveMoney(playerid);
public GiveMoney(playerid)
{
    if(money[playerid]==0) return 0;
    GivePlayerMoney(playerid, 2500);
    SendClientMessage(playerid, -1, "You have earned 2500 cash!");
    DisablePlayerCheckpoint(playerid);
    //EnableMoney(playerid);/*use this to restart the checkpoint! after they have waited the 10sec*/
    return 1;
}
forward EnableMoney(playerid);
public EnableMoney(playerid)
{
    money[playerid]=0;
    DisablePlayerCheckpoint(playerid);
    SetPlayerCheckpoint(playerid, 1958.3783, 1343.1572, 15.3746, 2.0);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerCheckpoint(playerid, 1958.3783, 1343.1572, 15.3746, 2.0);
    return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
      money[playerid]=1;
      SendClientMessage(playerid, -1, "Stay in Checkpoint for 10 seconds!");
      MoneyTimer[playerid] = SetTimerEx("GiveMoney", 10000, false, "i", playerid);
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    SendClientMessage(playerid, -1, "You Left The Checkpoint!");
    money[playerid]=0;
    KillTimer(MoneyTimer[playerid]);
    EnableMoney(playerid);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)