View Single Post
Old 20/02/2009, 10:31 AM   #7
kc
Gangsta
 
kc's Avatar
 
Join Date: Aug 2007
Posts: 618
Reputation: 115
Default Re: Flight Script, ID 0 always getting teleported to LS

well first of all, you should have used SetTimerEx to give the PlaneTime function the playerid parameter.

The method you are using is quite frankly horrible. e.g. what would happen if a player typed /fly while another player was already flying? the player variable would be overwritten by the new players id.

Your timer variable would also get overwritten, so you would effectively have a 1 second timer, that you can not stop (without a restart / gmx) that does nothing apart from wasting resources.

_________________________________________________

pawn Code:
#include <a_samp>
#include <dini>
#include <dutils>

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define rand(%1,%2) (random(%2 - %1 - 1) + %1 + 1)

#define COLOR_RED           0xAA3333AA
#define COLOR_PINK          0xFF66FFAA
#define COLOR_LIGHTBLUE     0x33CCFFAA

#define FLTime_LosSantos  58
#define FLTime_SanFierro  43
#define FLTime_LasVenturas 41

new InPlane[MAX_PLAYERS];
new FlightTime[MAX_PLAYERS];
new Destination[MAX_PLAYERS];
new Timer[MAX_PLAYERS];

forward PlaneTime(playerid);

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(fly, 3, cmdtext);
    return 0;
}

pawn Code:
dcmd_fly(playerid, params[])
{
  #pragma unused params
  #pragma unused playerid
 
    if (strval(params) < 1 || strval(params) > 3)
    {
        SendClientMessage(playerid, 0xAA0000FF, "Usage: /fly [1-3]");
        SendClientMessage(playerid, 0xAA0000FF, "1 - Los Santos");
        SendClientMessage(playerid, 0xAA0000FF, "2 - San Fierro");
        SendClientMessage(playerid, 0xAA0000FF, "3 - Las Venturas");
        return 0;
    }
   
    switch (strval(params))
    {
        case 1: Destination[playerid] = 1;
        case 2: Destination[playerid] = 2;
        case 3: Destination[playerid] = 3;
    }

    if(InPlane[playerid] == 1)
    {
        GameTextForPlayer(playerid, "Already in plane!", 3000, 4);
    } else {
        InPlane[playerid] = 1;
        SetPlayerInterior(playerid, 1);
        SetPlayerPos(playerid, 1.2649, 26.3358, 1199.5938);

        switch (Destination[playerid])
        {
            case 1: FlightTime[playerid] = FLTime_LosSantos;
            case 2: FlightTime[playerid] = FLTime_SanFierro;
            case 3: FlightTime[playerid] = FLTime_LasVenturas;
        }

    new string[128];
    format(string, sizeof(string), "~w~Flight Time: ~g~00:%d", FlightTime[playerid]);

        GameTextForPlayer(player, string, 3000, 4);
        Timer[playerid] = SetTimerEx("PlaneTime", 1000, true, "d", playerid);

        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "Name: %s (%d)", name, playerid);
      SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

        switch (Destination[playerid])
        {
            case 1: SendClientMessage(playerid, COLOR_LIGHTBLUE, "Destination: Los Santos");
            case 2: SendClientMessage(playerid, COLOR_LIGHTBLUE, "Destination: San Fierro");
            case 3: SendClientMessage(playerid, COLOR_LIGHTBLUE, "Destination: Las Venturas");
        }
        format(string, sizeof(string), "Flight Time: %d Seconds", FlightTime[playerid]);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
       
        // **Flight Information ** //
        GetPlayerName(playerid, name, sizeof(name));
   
        print("\n\n** New Flight**");
        printf("Name: %s (%d)", name, playerid);
       
        switch (Destination[playerid])
        {
            case 1: print("Destination: Los Santos");
            case 2: print("Destination: San Fierro");
            case 3: print("Destination: Las Venturas");
        }
       
        printf("Flight Time: %d Seconds", FlightTime[playerid]);
    }
    return 1;
}

pawn Code:
public PlaneTime(playerid)
{
    new string[128];
   
    if(FlightTime[playerid] == 0) {
      KillTimer(Timer[playerid]);
     
        switch (Destination[playerid])
        {
            case 1:
            {
                printf("ID %d: Successfully Arrived At Los Santos!", playerid);
                SetPlayerInterior(playerid, 0);
                SetPlayerPos(playerid, 1686.3303, -2324.8582, 13.5469);
                GameTextForPlayer(playerid, "~g~Welcome to ~b~~h~~h~Los Santos!", 3000, 0);
            }
           
            case 2:
            {
                printf("ID %d: Successfully Arrived At San Fierro!", playerid);
                SetPlayerInterior(playerid, 0);
                GameTextForPlayer(playerid, "~g~Welcome to ~b~~h~~h~San Fierro!", 3000, 0);
            }
            case 3:
            {
        printf("ID %d: Successfully Arrived At Las Venturas!", playerid);
        SetPlayerInterior(playerid, 0);
        GameTextForPlayer(playerid, "~g~Welcome to ~b~~h~~h~Las Venturas!", 3000, 0);
            }
        }

        InPlane[playerid] = 0;
    } else {
        FlightTime[playerid] -= 1;
        printf("ID %d: %d Seconds Left Until Arrival.", playerid, FlightTime[playerid]);

        if(FlightTime[playerid] > 9)
        {
            format(string, sizeof(string), "~w~Flight Time: ~g~00:%d", FlightTime[playerid]);
        } else {
          format(string, sizeof(string), "~w~Flight Time: ~g~00:0%d", FlightTime[playerid]);
        }
        GameTextForPlayer(playerid, string, 3000, 4);
    }
    return 1;
}

Theres allot more which I think should be changed, but I'm not going to do that now.
kc is offline