OnPlayerStateChange not working at all
#1

Well... I've found that ALL the codes under OnPlayerStateChange doesn't work at all - Tried to find the problem but i failed :S

So.. Here it is..


PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    new 
string[128];
    if(
newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new 
newcar GetPlayerVehicleID(playerid);
         if(
GetVehicleModel(newcar) != 509 && GetVehicleModel(newcar) != 481)  // BMX & Bike
        
{
            
RadioChoose(playeridRadio[newcar]);
        }
        return 
1;
    }
    if(
oldstate == PLAYER_STATE_DRIVER)
    {
        new 
model GetVehicleModel(gLastCar[playerid]);
        if(
IsACopCar(gLastCar[playerid]) || model == 457)
        {
            
SetPlayerWeapons(playerid);
        }
    }
    
/*if (newstate == 2)
    {
        if (oldstate == 1)
        {
            new
                vID = GetPlayerVehicleID(playerid);
            if (IsRentableCar(vID))
            {
                if (!IsRentedCar(vID))
                {
                    new
                        String[128];
                    format(String, 128, "~p~~n~rent cost: ~b~%d~n~~w~type ~b~/rentcar~n~~w~to exit it type~n~~p~/exitrental", RENT_COST);
                    GameTextForPlayer(playerid, String, 30000, 4);
                    SendClientMessage(playerid, COLOR_YELLOW,"Type {3399CC}/rentcar{FFFFFF} to rent this car");
                    SendClientMessage(playerid, -1, "Type {3399CC}/exitrental{FFFFFF} to exit this rental car.");
                    TogglePlayerControllable(playerid, 0);
                }
                else if (IsRentedCar(vID))
                {
                    if (GetPVarInt(playerid, "CarRentID") == vID)
                    {
                        return SendClientMessage(playerid, -1, "{3399CC}Welcome{FFFFFF} to your rented car.");
                    }
                    else if (GetPVarInt(playerid, "CarRentID") != vID)
                    {
                        new
                            String[128];
                        format(String, 128, "This vehicle is rented by: {3399CC}%s{FFFFFF}", RentedBy[vID]);
                        SendClientMessage(playerid, -1, String);
                        SendClientMessage(playerid, -1, "Use {3399CC}/exitrental{FFFFFF} to exit this vehicle.");
                         return 1;
                    }
                }
            }
        }
    }*/
    
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new 
newcar GetPlayerVehicleID(playerid);
        new 
0;
        while(
!= MAX_PLAYERS)
        {
            if(
IsPlayerConnected(x) && GetPlayerState(x) == PLAYER_STATE_SPECTATING && SpectatedID[x] == playerid)
               {
                   
PlayerSpectateVehicle(x,newcar);
            }
            
x++;
        }
    }
    if(
newstate == PLAYER_STATE_ONFOOT)
    {
        new 
0;
        
RadioChoose(playerid255);
        while(
!= MAX_PLAYERS)
        {
            if(
IsPlayerConnected(x) && GetPlayerState(x) == PLAYER_STATE_SPECTATING && SpectatedID[x] == playerid)
               {
                   
PlayerSpectatePlayer(x,playerid);
            }
            
x++;
        }
        if(
TransportDuty[playerid] > 0)
        {
            if(
TransportDuty[playerid] == 1)
            {
                
TaxiDrivers -= 1;
            }
            else if(
TransportDuty[playerid] == 2)
            {
                
BusDrivers -= 1;
            }
            
TransportDuty[playerid] = 0;
            
format(stringsizeof(string), "* You are now Off Duty and earned $%d."TransportMoney[playerid]);
            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
            
PlayerInfo[playerid][pCash] = PlayerInfo[playerid][pCash]+TransportMoney[playerid];
            
GivePlayerMoney(playeridTransportMoney[playerid]);
            
TransportValue[playerid] = 0TransportMoney[playerid] = 0;
            
SetPlayerColor(playeridTCOLOR_WHITE);
            
PlayerPlaySound(playerid,1055,0.0,0.0,0.0);
        }
        if(
TransportCost[playerid] > && TransportDriver[playerid] < 999)
        {
            if(
IsPlayerConnected(TransportDriver[playerid]))
            {
                
TransportMoney[TransportDriver[playerid]] += TransportCost[playerid];
                
TransportTime[TransportDriver[playerid]] = 0;
                
TransportCost[TransportDriver[playerid]] = 0;
                
format(stringsizeof(string), "~w~The ride cost~n~~r~$%d",TransportCost[playerid]);
                
GameTextForPlayer(playeridstring50001);
                
format(stringsizeof(string), "~w~Passenger left the taxi~n~~g~Earned $%d",TransportCost[playerid]);
                
GameTextForPlayer(TransportDriver[playerid], string50001);
                
PlayerInfo[playerid][pCash] = PlayerInfo[playerid][pCash]-TransportCost[playerid];
                
GivePlayerMoney(playerid, -TransportCost[playerid]);
                
TransportCost[playerid] = 0;
                
TransportTime[playerid] = 0;
                
TransportDriver[playerid] = 999;
                
PlayerPlaySound(playerid,1083,0.0,0.0,0.0);
            }
        }
        new 
oldcar gLastCar[playerid];
        if(
oldcar >= Trucks[0] && oldcar <= Trucks[10])
        {
            if(
PlayerInfo[playerid][pJob] == 19)
            {
                if(
CP[playerid] >= 1340 && CP[playerid] <= 1347)
                {
                    
DisablePlayerCheckpoint(playerid);
                    
CP[playerid] = 0;
                    
SendClientMessage(playerid, -1,"    To finish delivery, get back in the truck.");
                }
            }
        }
    }
    if(
newstate == PLAYER_STATE_PASSENGER// TAXI & BUSSES
    
{
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridnamesizeof(name));
        new 
vehicleid GetPlayerVehicleID(playerid);
        
////foreach(Player, i)
        
for(new ii<MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(
IsPlayerInVehicle(ivehicleid) && GetPlayerState(i) == && TransportDuty[i] > 0)
                {
                    if(
PlayerInfo[playerid][pCash] < TransportValue[i])
                    {
                        
format(stringsizeof(string), "* You need $%d to enter."TransportValue[i]);
                        
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
                        
RemovePlayerFromVehicle(playerid);
                    }
                    else
                    {
                        if(
TransportDuty[i] == 1)
                        {
                            
format(stringsizeof(string), "* You paid $%d to the Taxi Driver."TransportValue[i]);
                            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
                            if(
PlayerInfo[i][pMask] == 1)
                            {
                                
format(stringsizeof(string), "* Stranger has entered your taxi.");
                            }
                            else
                            {
                                
format(stringsizeof(string), "* %s has entered your taxi."name);
                            }
                            
SendClientMessage(iCOLOR_LIGHTBLUEstring);
                            
TransportTime[i] = 1;
                            
TransportTime[playerid] = 1;
                            
TransportCost[playerid] = TransportValue[i];
                            
TransportCost[i] = TransportValue[i];
                            
TransportDriver[playerid] = i;
                        }
                        else if(
TransportDuty[i] == 2)
                        {
                            
format(stringsizeof(string), "* You paid $%d to the Bus Driver."TransportValue[i]);
                            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
                            if(
PlayerInfo[i][pMask] == 1)
                            {
                                
format(stringsizeof(string), "* Stranger has entered your bus.");
                            }
                            else
                            {
                                
format(stringsizeof(string), "* %s has entered your bus."name);
                            }
                            
SendClientMessage(iCOLOR_LIGHTBLUEstring);
                        }
                        
PlayerInfo[playerid][pCash] = PlayerInfo[playerid][pCash]-TransportValue[i];
                        
GivePlayerMoney(playerid, - TransportValue[i]);
                        
TransportMoney[i] += TransportValue[i];
                    }
                }
            }
        }
    }
    if(
newstate == PLAYER_STATE_WASTED//PLAYER DIES
    
{
        if(
PlayerInfo[playerid][pJailed] == 0)
        {
            
PlayerInfo[playerid][pHospital] = 1;
        }
    }
     if(
oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
    {
        if(
playing[playerid]) StopAudioStreamForPlayer(playerid);
    }
    if(
oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        new 
Float:V1XFloat:V1YFloat:V1Z;
        new 
newcar GetPlayerVehicleID(playerid);
        new 
Model GetVehicleModel(newcar);
        new 
oldcar gLastCar[playerid];
        if(
IsABoat(newcar))
        {
            if(
PlayerInfo[playerid][pBoatLic] < 1)
            {
                
SendClientMessage(playeridCOLOR_GREY"   You don't know how to Sail yet, so you left the Boat !");
                
RemovePlayerFromVehicle(playerid);
            }
        }
        else
        {
            if(
PlayerInfo[playerid][pCarLic] < 1)
            {
                
SendClientMessage(playeridCOLOR_GREY"   You don't know how to Drive yet, so you left the Car !");
                
RemovePlayerFromVehicle(playerid);
            }
        }
        
/*if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 525)
        {
            GameTextForPlayer(playerid, "~w~press ~r~~k~~TOGGLE_SUBMISSIONS~~w~ to tow a car.", 3000, 4);
        }*/
        
if(GetPlayerVehicleID(playerid) >= Trucks[0] && GetPlayerVehicleID(playerid) <= Trucks[10])
        {
            
SendClientMessage(playerid, -1"   Type /loadtruck to load the goods on your truck.");
        }
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 519)
        {
            
GameTextForPlayer(playerid"~w~use ~r~(/int)ercom~w~ to speak with your passengers."30004);
        }
        if(
IsACopCar(newcar))
        {
            if(
PlayerInfo[playerid][pMember] == || PlayerInfo[playerid][pLeader] == ||PlayerInfo[playerid][pLeader] == ||    PlayerInfo[playerid][pMember] == || PlayerInfo[playerid][pMember] == || PlayerInfo[playerid][pLeader] == 3)
            {
            }
            else
            {
                
SendClientMessage(playeridCOLOR_GREY"You don't have the keys for this vehicle [Hint : LSPD-SASD-FBI Vehicles]");
                
ClearAnimations(playerid);
            }
        }
        if(
IsANGCar(newcar))
        {
            if(
IsANG(playerid)){}
            else{ 
SendClientMessage(playeridCOLOR_GREY"You don't have the Keys for this vehicle [Hint : DoC Members Vehicles]"); ClearAnimations(playerid); }
        }
        
/*if(newcar >= thugCars[0] && newcar <= thugCars[2])
        {
            if(PlayerInfo[playerid][pFMember] != 1)
            {
                SendClientMessage(playerid,COLOR_GREY," You're not in 'Thugs of Smoke'!");
                RemovePlayerFromVehicle(playerid);
            }
        }*/
        
else if(IsATaxiCar(newcar))
        {
            if(
PlayerInfo[playerid][pMember] == 10 || PlayerInfo[playerid][pLeader] == 10 || PlayerInfo[playerid][pJob] == 14) { }
            else { 
SendClientMessage(playerid,COLOR_GREY,"   You don't have the keys for this vehicle [Taxi Cab Company Vehicles]"); ClearAnimations(playerid); }
        }
        else if(
IsABus(newcar))
        {
            if(
PlayerInfo[playerid][pMember] == 10 || PlayerInfo[playerid][pLeader] == 10 || PlayerInfo[playerid][pJob] == 14) { }
            else { 
SendClientMessage(playerid,COLOR_GREY,"   You don't have the keys for this vehicle [Bus Company Vehicles]"); ClearAnimations(playerid); }
        }
        else if(
IsANewsCar(newcar))
        {
            if(
PlayerInfo[playerid][pMember] == || PlayerInfo[playerid][pLeader] == 9) { }
            else { 
SendClientMessage(playerid,COLOR_GREY,"   You don't have the keys for this vehicle [SA-News Agency Vehicles]"); ClearAnimations(playerid); }
        }
        else if(
IsAnAmbulance(newcar))
        {
            if(
PlayerInfo[playerid][pMember] == || PlayerInfo[playerid][pLeader] == 4) { }
            else { 
SendClientMessage(playerid,COLOR_GREY,"   You don't have the keys for this vehicle [E.M.S Vehicles]!"); ClearAnimations(playerid); }
        }
        else if(
newcar >= SSVehicles[0] && newcar <= SSVehicles[5])
        {
               if(!(
PlayerInfo[playerid][pMember] == 7))
            {
                
SendClientMessage(playerid,COLOR_GREY,"   You don't have the keys for this vehicle [Secret Service Vehicles]!");
                
ClearAnimations(playerid);
            }
        }
        else if(
newcar >= Trucks[0] && newcar <= Trucks[10])
        {
            if(
PlayerInfo[playerid][pJob] == 19)
            {
                if(
CP[playerid] == && TruckGoods[newcar] == 0)
                {
                    if(
TruckGoods[newcar] == 1)
                    {
                        
SetPlayerCheckpoint(playerid1499.6423,-1589.6134,13.38283.0);
                         
CP[playerid] = 1340;
                    }
                    if(
TruckGoods[newcar] == 2)
                    {
                        
SetPlayerCheckpoint(playerid1194.1232,-1323.2413,13.39843.0);
                        
CP[playerid] = 1341;
                    }
                    if(
TruckGoods[newcar] == 3)
                    {
                        
SetPlayerCheckpoint(playerid816.3569,-1391.6063,13.40653.0);
                        
CP[playerid] = 1342;
                    }
                    if(
TruckGoods[newcar] == 4)
                    {
                        
SetPlayerCheckpoint(playerid481.9336,-1499.8834,20.32043.0);
                        
CP[playerid] = 1343;
                    }
                    if(
TruckGoods[newcar] == 5)
                    {
                        
SetPlayerCheckpoint(playerid1360.2253,-1279.8677,13.38283.0);
                        
CP[playerid] = 1344;
                    }
                    if(
TruckGoods[newcar] == 6)
                    {
                        
SetPlayerCheckpoint(playerid1099.5890,-1210.1484,17.37463.0);
                        
CP[playerid] = 1345;
                    }
                    if(
TruckGoods[newcar] == 7)
                    {
                        
SetPlayerCheckpoint(playerid1361.7418,-1650.9559,13.38283.0);
                        
CP[playerid] = 1346;
                    }
                    if(
TruckGoods[newcar] == 8)
                    {
                        
SetPlayerCheckpoint(playerid1897.3386,-1866.8689,13.14123.0);
                        
CP[playerid] = 1347;
                    }
                }
                else
                {
                    
SendClientMessage(playeridCOLOR_GRAD2"  This truck is loaded, but you already have an active checkpoint");
                    
SendClientMessage(playerid, -1"   To finish this delivery, lose the old checkpoint first or destroy it(/destroycp)");
                }
            }
            else
            {
                
SendClientMessage(playerid,COLOR_GREY,"   You're not a trucker!");
                
RemovePlayerFromVehicle(playerid);
            }
        }
////////CARS
        
if(oldcar != PlayerVehicleID1[playerid])
        {
            
UnLockCar(oldcar);
        }
        else if(
oldcar != PlayerVehicleID2[playerid])
        {
            
UnLockCar(oldcar);
        }
        else if(
oldcar != PlayerVehicleID3[playerid])
        {
            
UnLockCar(oldcar);
        }
        else if(
oldcar != PlayerVehicleID4[playerid])
        {
            
UnLockCar(oldcar);
        }
        else if(
oldcar != PlayerVehicleID5[playerid])
        {
            
UnLockCar(oldcar);
        }
        new 
Float:playerhp;
        if(
VehicleInfo[newcar][VehicleDealership] == 1)
        {
            if(
newcar == PlayerVehicleID1[playerid] || newcar == PlayerVehicleID2[playerid] || newcar == PlayerVehicleID3[playerid] || newcar == PlayerVehicleID4[playerid] || newcar == PlayerVehicleID5[playerid])
            {
                
format(string,sizeof(string),"    You are the owner of this %s.",vehName[Model-400]);
                
SendClientMessage(playerid,COLOR_GREY,string);
                return 
1;
            }
            else
            {
                if(
VehicleInfo[newcar][VehicleLock] == 2)
                   {
                    if(
VehicleInfo[newcar][VehicleLocked] == 1)
                    {
                        
GetVehiclePos(newcar,V1X,V1Y,V1Z);
                        
SetPlayerPos(playeridV1X,V1Y,V1Z+2);
                        
GetPlayerHealth(playerid,playerhp);
                        
SetPlayerHealth(playerid,playerhp-15.0);
                        
GameTextForPlayer(playerid"~r~STUNNED"40003);
                    }
                       else
                    {
                        
format(string,sizeof(string),"    Warning: This Vehicle Is Owned By: %s.",VehicleInfo[newcar][VehicleOwner]);
                        
SendClientMessage(playerid,COLOR_GREY,string);
                    }
                }
                else
                {
                    
format(string,sizeof(string),"    Warning: This Vehicle Is Owned By: %s.",VehicleInfo[newcar][VehicleOwner]);
                    
SendClientMessage(playerid,COLOR_GREY,string);
                }
            }
        }
        for(new 
0sizeof(CarInfo); i++)
        {
            if(
CarInfo[i][CarID] == newcar)
            {
                if(
CarInfo[i][DealerShipCar] == 1)
                {
                    new 
carstring[256];
                    
format(carstring,sizeof(carstring),"Would you like to buy this %s ?\n This vehicles costs $%d",vehName[CarInfo[i][CarModel]-400],CarInfo[i][CarPrice]);
                    
ShowPlayerDialog(playerid9001DIALOG_STYLE_MSGBOX"For Sale!"carstring"Buy""Cancel");
                    
TempCarID[playerid] = i;
                }
            }
        }
        if(
Model == 427 && !IsACop(playerid)) // enforcer armor exploit fix
        
{
            
SetPlayerArmour(playeridStoreArmour[playerid]);
        }
        
gLastCar[playerid] = newcar;
    }
    if(
newstate == PLAYER_STATE_SPAWNED)
    {
        if(
PlayerInfo[playerid][pWantedLevel] > 0)
        {
            new 
points PlayerInfo[playerid][pWantedLevel];
            new 
wlevel;
            if(
points == 1) { wlevel 1; }
            else if(
points == 2) { wlevel 2; }
            else if(
points == 3) { wlevel 3; }
            else if(
points == 4) { wlevel 4; }
            else if(
points == 5) { wlevel 5; }
            else if(
points == 6) { wlevel 6SetPlayerColor(playeridTCOLOR_WANTED); }
            
SetPlayerWantedLevel(playeridwlevel);
        }
    }
    return 
1;

Reply
#2

Debug.
Reply
#3

Well - I know that this is an Idiotic Question , But.. if i use
PHP код:
if(newstate == PLAYER_STATE_DRIVER
more than 1 time under OnPlayerStateChange - Would that effect the script ?


- Sorry , can't help you Breto
Reply
#4

Quote:
Originally Posted by Breto
Посмотреть сообщение
Well... I've found that ALL the codes under OnPlayerStateChange doesn't work at all - Tried to find the problem but i failed :S

So.. Here it is..


pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[128];
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new newcar = GetPlayerVehicleID(playerid);
        if(GetVehicleModel(newcar) != 509 && GetVehicleModel(newcar) != 481)  // BMX & Bike
        {
            RadioChoose(playerid, Radio[newcar]);
        }
->      return 1;
    }
    if(oldstate == PLAYER_STATE_DRIVER)
    {
        new model = GetVehicleModel(gLastCar[playerid]);
        if(IsACopCar(gLastCar[playerid]) || model == 457)
        {
            SetPlayerWeapons(playerid);
        }
    }

    [...]
    return 1;
}
Can you spot what's wrong? You're returning 1 before hand, thus the code ends there.
Reply
#5

Not unless you use return.

pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
{
    SendClientMessage(playerid, -1, "You entered a vehicle.");
    return 1;
}

if(newstate == PLAYER_STATE_WHATEVER)
{
    // This will never be called because we returned 1 above. This stops the rest of the code from executing.
}
Reply
#6

God - I Don't know how i didn't see the return 1; - Thanks very very Much - repped +
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)