playerstate bug
#1

Code:
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    new 
vehicle GetPlayerVehicleID(playerid);
    if(
VehicleInfo[vehicle][vType] == 2)
    {
        if(
newstate == PLAYER_STATE_DRIVER)
        {
            if(
PlayerInfo[playerid][pLanguage] == 1)
            {
                
SendClientMessage(playeridCOLOR_GREY"| This is a Spawn Vehicle | Respawn time: 200 seconds |");
            }
            else
            {
                
SendClientMessage(playeridCOLOR_GREY"| Acesta este un vehicul de la Spawn | Timp de respawn: 200 seconds |");
            }
        }
    }
    else if(
VehicleInfo[vehicle][vType] == 1)
    {
        if(
newstate == PLAYER_STATE_DRIVER)
        {
            if(
strcmp(VehicleInfo[vehicle][vOwner],"Noone"true))
            {
                if(
PlayerInfo[playerid][pLanguage] == 1)
                {
                    new 
string[40 MAX_PLAYER_NAME];
                    
format(stringsizeof(string), "| This vehicle is owned by %s |"VehicleInfo[vehicle][vOwner]);
                    
SendClientMessage(playeridCOLOR_GREYstring);
                }
                else
                {
                    new 
string[40 MAX_PLAYER_NAME];
                    
format(stringsizeof(string), "| Acest vehicul este detinut de catre %s |"VehicleInfo[vehicle][vOwner]);
                    
SendClientMessage(playeridCOLOR_GREYstring);
                }
            }
            else
            {
                if(
PlayerInfo[playerid][pLanguage] == 1)
                {
                    new 
string[80];
                    
format(stringsizeof(string),"| This vehicle is for sale, Price: %d COINS |"VehicleInfo[vehicle][vPrice]);
                    
SendClientMessage(playeridCOLOR_GREYstring);
                }
                else
                {
                    new 
string[80];
                    
format(stringsizeof(string),"| Acest vehicul este de vanzare, Pret: %d COINS |"VehicleInfo[vehicle][vPrice]);
                    
SendClientMessage(playeridCOLOR_GREYstring);
                }
            }
        }
    }
    else if(
VehicleInfo[vehicle][vType] == 3)
    {
        if(
newstate == PLAYER_STATE_DRIVER)
        {
            if(
DrivingTest[playerid] == false)
            {
                 
SCM(playeridCOLOR_GREY"| This is a Driving School Vehicle and you are not allowed to freely drive it |");
            }
        }
    }
    if(
newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new 
fuel_string[5];
        
PlayerTextDrawShow(playeridspeedo[0][playerid]);
        
PlayerTextDrawShow(playeridspeedo[1][playerid]);
        
PlayerTextDrawShow(playeridspeedo[2][playerid]);
        
PlayerTextDrawShow(playeridspeedo[3][playerid]);
        
PlayerTextDrawShow(playeridspeedo[4][playerid]);
        
format(fuel_stringsizeof(fuel_string), "%i"VehicleInfo[vehicle][vFuel]);
        
PlayerTextDrawSetString(playeridspeedo[7][playerid], fuel_string);
    }
    else if(
oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT || oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT)
    {
        
PlayerTextDrawHide(playeridspeedo[0][playerid]);
        
PlayerTextDrawHide(playeridspeedo[1][playerid]);
        
PlayerTextDrawHide(playeridspeedo[2][playerid]);
        
PlayerTextDrawHide(playeridspeedo[3][playerid]);
        
PlayerTextDrawHide(playeridspeedo[4][playerid]);
        
PlayerTextDrawSetString(playeridspeedo[7][playerid], " ");
    }
    return 
1;

If I enter a type 2 veh everything is okay, I get the right message.
If I enter a type 3 veh same, I get the right message
but if I enter a type 1 vehicle I get the message from type 3 vehicle, any idea why?
Reply
#2

First of all your code is too many you lines.

Shorten it by placing

if(newstate == PLAYER
above the other codes so it would make it short and easy to read.

and I can't help you more right now

maybe try commenting the vehicle type 3 and check what happens... if it works then there must be a missing bracket you missed..
Reply
#3

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
First of all your code is too many you lines.

Shorten it by placing

if(newstate == PLAYER
above the other codes so it would make it short and easy to read.

and I can't help you more right now

maybe try commenting the vehicle type 3 and check what happens... if it works then there must be a missing bracket you missed..
The bug is due to the way the data is loaded, trying to fix that..
Reply
#4

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
The bug is due to the way the data is loaded, trying to fix that..
If you check things more efficiently, you won't have as much code to review, and by proxy, it will become easier to read...

Check if they are a driver first before checking what type of vehicle they are in, let alone what vehicle they are in. It's called logic.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)