SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 19/02/2009, 04:46 PM   #1
Robbin237
Big Clucker
 
Join Date: Nov 2007
Posts: 170
Reputation: 0
Default Flight Script, ID 0 always getting teleported to LS

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 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 player;
new Timer;

forward PlaneTime();

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);
        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 Code:
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;
}
Robbin237 is offline  
Old 19/02/2009, 05:07 PM   #2
Marcel
Huge Clucker
 
Join Date: Nov 2007
Posts: 382
Reputation: 2
Default Re: Flight Script, ID 0 always getting teleported to LS

Where's player in public PlaneTime() ?
Marcel is offline  
Old 20/02/2009, 10:08 AM   #3
Robbin237
Big Clucker
 
Join Date: Nov 2007
Posts: 170
Reputation: 0
Default Re: Flight Script, ID 0 always getting teleported to LS

**BUMP**

Need help!!!
Robbin237 is offline  
Old 20/02/2009, 10:09 AM   #4
Nimphious
Huge Clucker
 
Join Date: Dec 2008
Posts: 371
Reputation: 2
Default Re: Flight Script, ID 0 always getting teleported to LS

Marcel asked a question. answer before you bump.
Nimphious is offline  
Old 20/02/2009, 10:15 AM   #5
Robbin237
Big Clucker
 
Join Date: Nov 2007
Posts: 170
Reputation: 0
Default Re: Flight Script, ID 0 always getting teleported to LS

At the top of the script , player is defined, so it can be used everywhere. Now i need help
Robbin237 is offline  
Old 20/02/2009, 10:26 AM   #6
Robbin237
Big Clucker
 
Join Date: Nov 2007
Posts: 170
Reputation: 0
Default Re: Flight Script, ID 0 always getting teleported to LS

Please
Robbin237 is offline  
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  
Old 20/02/2009, 10:37 AM   #8
Robbin237
Big Clucker
 
Join Date: Nov 2007
Posts: 170
Reputation: 0
Default Re: Flight Script, ID 0 always getting teleported to LS

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?
Robbin237 is offline  
Old 20/02/2009, 10:38 AM   #9
kc
Gangsta
 
kc's Avatar
 
Join Date: Aug 2007
Posts: 618
Reputation: 115
Default Re: Flight Script, ID 0 always getting teleported to LS

That is how its supposed to work, yes.

Although its completely untested, I see no obvious reason it wouldn't work.
kc is offline  
Old 20/02/2009, 10:39 AM   #10
Robbin237
Big Clucker
 
Join Date: Nov 2007
Posts: 170
Reputation: 0
Default Re: Flight Script, ID 0 always getting teleported to LS

Quote:
Theres allot more which I think should be changed, but I'm not going to do that now.
What?
Robbin237 is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Flight over TNCM airport zone FSX patchkinson Everything and Nothing 9 13/03/2010 07:02 PM
The failed Flight attendent (MadTV) HydraX Everything and Nothing 3 22/02/2010 12:55 AM
Flight Simulator X supported with Windows 7? HydraX Everything and Nothing 4 31/01/2010 07:09 PM
Rapping Flight Attendant mave_man Everything and Nothing 7 07/05/2009 10:00 PM


All times are GMT. The time now is 02:46 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.