SA-MP Forums Archive
OnPlayerStateChange - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerStateChange (/showthread.php?tid=252559)



OnPlayerStateChange - marko94 - 01.05.2011

I have a problem with the OnPlayerStateChange function. Nothing is working while I get into a car.

Here is the full public code:

http://pastebin.com/bKU97sLv

I'll show you a few examples where the problem is:

pawn Код:
else if(newcar >= 112 && newcar <= 130)
        {

            if (HireCar[playerid] != newcar)
            {
                format(string, sizeof(string), "Vehicle Rental:Rent a vehicle for $%d /rentcar",SBizzInfo[1][sbEntranceCost]);
                SendClientMessage(playerid,COLOR_WHITE,string);
                SendClientMessage(playerid,COLOR_GREEN,"Rent a vehicle,and you will be able to /rlock your car");
                TogglePlayerControllable(playerid, 0);
                VehAsk[playerid] = 1;

            }
        }
pawn Код:
if(IsABus(newcar))
        {
            if(PlayerInfo[playerid][pJob] != 14)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_GREY,"You don't have keys to this bus.");
                TogglePlayerControllable(playerid,true);
                VehAsk[playerid] = 0;
            }
            else
            {
                if(JobDelay[playerid] > 0)
                {
                    RemovePlayerFromVehicle(playerid);
                    TogglePlayerControllable(playerid,true);
                    VehAsk[playerid] = 0;
                    SendClientMessage(playerid, COLOR_GREY," You need to wait for Your last route time to reduce !");
                }
                else if(BusRoute[playerid] == 0)
                {
                    ShowMenuForPlayer(BusRoutesM, playerid);
                    BusRoute[playerid] = 1;
                    gPlayerCheckpointStatus[playerid] = CHECKPOINT_BUSROUTE;
                    BusRouteS[playerid] = 0;
                }
            }
        }
pawn Код:
else if(IsATowcar(newcar))
        {
            if(PlayerInfo[playerid][pJob] != 7)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_GREY,"You don't have keys of this vehicle.");
                TogglePlayerControllable(playerid,true);
                VehAsk[playerid] = 0;
            }
        }

So, when I go IG and I try to enter a bus or a rental vehicle for exmaple, it will let me drive it without saying that I don't have the keys, or I don't have the job.


Re: OnPlayerStateChange - park4bmx - 01.05.2011

Don't put it underOnPlayerStateChange
Try put it under onplaerentervehicle then just do GetPlayerVehicleid and so onn


Re: OnPlayerStateChange - marko94 - 01.05.2011

Well, I did that and it worked. The thing is, I don't want it like that. I want the message to be displayed after the player enters the car, not exactly after he presses F/Enter if you know what I'm talking about.


Re: OnPlayerStateChange - park4bmx - 01.05.2011

Then do it under OnPlayerUpdate
Then do if(IsPlayerInAnyVehicle(playerid))
The get the players states if he is the driver and put ur message and code there. Sorry that I can't give an example I am on my phone.


Re: OnPlayerStateChange - marko94 - 09.05.2011

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
Then do it under OnPlayerUpdate
Then do if(IsPlayerInAnyVehicle(playerid))
The get the players states if he is the driver and put ur message and code there. Sorry that I can't give an example I am on my phone.
Uhm, yeah but my question is, why is not working under OnPlayerStateChange because there's nothing wrong with the code as far as I see/know.


Re: OnPlayerStateChange - Backwardsman97 - 09.05.2011

Well for one thing, why do you get the player's vehicle id twice at the top? Secondly, I wouldn't use else if's and you checked twice if the player was in the state 'driver'. That's probably why.


Re: OnPlayerStateChange - marko94 - 11.05.2011

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
Well for one thing, why do you get the player's vehicle id twice at the top? Secondly, I wouldn't use else if's and you checked twice if the player was in the state 'driver'. That's probably why.
Alright, I did what you said but still, it doesn't work.


Right, now PLAYER_STATE_DRIVER is defined only once. GetPlayerVehicleID(playerid); is also gotten once. I tried changing else if into if but still nothing.


Re: OnPlayerStateChange - marko94 - 14.05.2011

I tried with OnPlayerEnterVehicle, it works but there's a massive spam when I enter the bike and I have to job.




Re: OnPlayerStateChange - LetsOWN[PL] - 14.05.2011

Quote:
Originally Posted by marko94
Посмотреть сообщение
I tried with OnPlayerEnterVehicle, it works but there's a massive spam when I enter the bike and I have to job.

You've to make a condition.

Код:
enum pInfo
{
bool:ConditionAAA[MAX_PLAYERS]
}
Код:
OnPlayerConnect(playerid)
{
Player[playerid][ConditionAAA] = false;
return 1;
}
and to make you "imagine" what I mean, heres simple COMMAND:

Код:
COMMAND:whattodo(playerid,params[])
{
if(Player[playerid][ConditionAAA])
// If condition is true, nothing will happen.
return 1;
}

// If not, then server will send message.
SendClientMessage(playerid,COLOR_WHITE,"Bla bla");
return 1;
}
PS. If You can, give part of the script, where's
"SendClientMessage(playerid,0xFFFFFFFF,"Type /dealpizza to start your mission");"
It'll help me to help you


Re: OnPlayerStateChange - marko94 - 15.05.2011

OnPlayerEnterVehicle
pawn Код:
if (IsAPizzabike(vehicleid) && !ispassenger)
    {
        if(PlayerInfo[playerid][pJob] != 17)
        {
            SetVehicleParamsForPlayer(vehicleid,playerid,0,1);
            new Float:cx, Float:cy, Float:cz;
            GetPlayerPos(playerid, cx, cy, cz);
            SetPlayerPos(playerid, cx,  cy, cz);
            SendClientMessage(playerid,COLOR_GREY," Only Pizza Delivers can drive this bike!");
            LockCars[playerid][0] = 3;
            LockCars[playerid][1] = vehicleid;
        }
        else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            SendClientMessage(playerid, COLOR_WHITE,"Type /startpizza to begin a pizza mission.");
        }
    }
OnPlayerUpdate
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
             if (IsAPizzabike(vehicleid))
             {
                    SendClientMessage(playerid, COLOR_WHITE, "Type /startpizza to begin your mission.");
             }
        }
    }
The original job was made under OnPlayerStateChange but all the vehicle jobs from under OnPlayerStateChange are not working, only the factions vehicles(PD,GOV etc). I even tried debugging those parts and there is nothing wrong with it.

OnPlayerStateChange
pawn Код:
if(IsAPizzabike(newcar))
        {
            if(PlayerInfo[playerid][pJob] != 17)
            {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid, COLOR_GREY,"You don't have keys to this bike.");
                TogglePlayerControllable(playerid,true);
                VehAsk[playerid] = 0;
            }
            else
            {
                SendClientMessage(playerid, COLOR_WHITE,"Type /startpizza to begin a pizza mission.");
            }
        }


Thank you.