Flight Script, ID 0 always getting teleported to LS
#1

I know this is a very long code, but i can't see why ID 0 is always getting tele'd to LS or whatever city.
Please help me.

pawn Код:
#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 player;
new Timer;

forward PlaneTime();
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(fly, 3, cmdtext);
    return 0;
}
pawn Код:
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);
        player = playerid;

        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 = SetTimer("PlaneTime", 1000, true);

        new name[MAX_PLAYER_NAME+1];
        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 Код:
public PlaneTime()
{
    new string[128];
   
    if(FlightTime[player] == 0) {
      KillTimer(Timer);
     
        switch (Destination[player])
        {
            case 1:
            {
                printf("ID %d: Successfully Arrived At Los Santos!", player);
                SetPlayerInterior(player, 0);
                SetPlayerPos(player, 1686.3303, -2324.8582, 13.5469);
                GameTextForPlayer(player, "~g~Welcome to ~b~~h~~h~Los Santos!", 3000, 0);
            }
           
            case 2:
            {
                printf("ID %d: Successfully Arrived At San Fierro!", player);
                SetPlayerInterior(player, 0);
                GameTextForPlayer(player, "~g~Welcome to ~b~~h~~h~San Fierro!", 3000, 0);
            }
            case 3:
            {
        printf("ID %d: Successfully Arrived At Las Venturas!", player);
        SetPlayerInterior(player, 0);
        GameTextForPlayer(player, "~g~Welcome to ~b~~h~~h~Las Venturas!", 3000, 0);
            }
        }

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

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

Where's player in public PlaneTime() ?
Reply
#3

**BUMP**

Need help!!!
Reply
#4

Marcel asked a question. answer before you bump.
Reply
#5

At the top of the script , player is defined, so it can be used everywhere. Now i need help
Reply
#6

Please
Reply
#7

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 Код:
#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 Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(fly, 3, cmdtext);
    return 0;
}
pawn Код:
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 Код:
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.
Reply
#8

So with this, i can have 2 players at different times in a plane, like i get in a plane, and the other person gets in 2 seconds later, we both have seperate fly times, and we both get seperatly teleported to LS or whatever city?
Reply
#9

That is how its supposed to work, yes.

Although its completely untested, I see no obvious reason it wouldn't work.
Reply
#10

Quote:

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

What?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)