SA-MP Forums Archive
Gas up problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Gas up problem (/showthread.php?tid=89549)



Gas up problem - D3nnis - 02.08.2009

Hello Folks,
I've got a problem with some code for a reallife-script.

I've wanted to let a vehicle gas up in a checkpoint at petrol station.
I'm using the CPS by DragSta for creating the checkpoints.
My Code's the following:
pawn Код:
#define MAX_PETROLS 12

new Tankstelle[MAX_PETROLS];
new Fuel[MAX_PLAYERS];
new OLD_Fuel[MAX_PLAYERS];
new IsInCheckpoint[MAX_PLAYERS];

Sleep(time)
{
    new StartTime = GetTickCount();
    while(GetTickCount() - StartTime < time)
    {
    //do nothing
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    Tankstelle[0] = CreateCheckpoint(playerid, 132.8586,-123.9499,1.4297,8,150); // Tankstelle in der Nдhe von 0-0-0
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    IsInCheckpoint[playerid]=1;
  CheckpointCheck(playerid);
    return 1;
}

public OnPlayerEnterStreamedCheckpoint(playerid, streamid)
{
    GameTextForPlayer(playerid, "Checkpoint", 2000, 4);
  if(streamid == Tankstelle[0])
  {
        if(IsPlayerInAnyVehicle(playerid)) Tanken(playerid);
        else SendClientMessage(playerid, BLUE, "Tanken ist nur im Fahrzeug mцglich");
    }
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    IsInCheckpoint[playerid]=0;
    return 1;
}

Tanken(playerid)
{
    if(Fuel[playerid] != 100)
    {
        new string[128];
        OLD_Fuel[playerid]=Fuel[playerid];
        while(IsInCheckpoint[playerid]==1&&Fuel[playerid]<100)
        {
          Fuel[playerid]++;
            format(string, sizeof(string), "Tanken.. %i %%", Fuel[playerid]);
            SendClientMessage(playerid, GREEN, string);
            Sleep(500);
        }
        OLD_Fuel[playerid]=Fuel[playerid]-OLD_Fuel[playerid];
        format(string, sizeof(string), "Du hast %i %% getankt, das macht dann %i $", OLD_Fuel[playerid], OLD_Fuel[playerid]*3);
        GivePlayerMoney(playerid, -OLD_Fuel[playerid]*3);
    }
    else SendClientMessage(playerid, GREEN, "Dein Tank ist voll!");
}
Since I'm a German, the text's are German too, but that doesn't matter.

Now my problems are:
1. in both "format" the "%%" doesn't show a "%" in the game.
2. the fueling should stop on leaving the Checkpoint, but it doesn't.

I could fix the second problem by using SetTimer(and KillTimer). Am I right? Maybe I will test that.
But what's about the "%%" problem?

Thankful D3nnis


Re: Gas up problem - mamorunl - 02.08.2009

the percentage signs cannot be shown ingame afaik. It has been a bug for a while. Dunno if it has been fixed by someone but instead of a percentage sign it shows #


Re: Gas up problem - D3nnis - 02.08.2009

Ah.. Thanks for the tip, I've changed the "%%" into "Liter" that's ok^^

At the moment I'm rewriting the whole Script(now I'm using SetTimer)
I'll edit my results after finishing

EDIT:
My problem is fixed now (I'm using settimerex etc)