SA-MP Forums Archive
OnPlayerStateChange statement ain't working - 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)
+--- Thread: OnPlayerStateChange statement ain't working (/showthread.php?tid=554488)



OnPlayerStateChange statement ain't working - [CG]Milito - 04.01.2015

Hi

I've been trying to figure out why this statement is not getting called.

pawn Код:
if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
        new vehid = LastVehicle[playerid];
        if(validcar[vehid])
        {
            GetVehiclePos(vehid,CarInfo[vehid][cXPos],CarInfo[vehid][cYPos],CarInfo[vehid][cZPos]);
            printf("%f, %f, %f",CarInfo[vehid][cXPos],CarInfo[vehid][cYPos],CarInfo[vehid][cZPos]);
        }
        LastVehicle[playerid]= INVALID_VEHICLE_ID;
    }
Any kind of help will be appreciated


Re: OnPlayerStateChange statement ain't working - Sid_Alexander - 04.01.2015

Can you show the whole code and the error?


Respuesta: Re: OnPlayerStateChange statement ain't working - [CG]Milito - 04.01.2015

Quote:
Originally Posted by Sid_Alexander
Посмотреть сообщение
Can you show the whole code and the error?
Actually, thats the whole code, and I don't get any errors.
It compiles without problem, but it's not working in game


Re: Respuesta: Re: OnPlayerStateChange statement ain't working - Sid_Alexander - 04.01.2015

Quote:
Originally Posted by [CG]Milito
Посмотреть сообщение
Actually, thats the whole code, and I don't get any errors.
It compiles without problem, but it's not working in game
What are you trying to figure out? stop the audio stream and print it in the console?


Respuesta: Re: Respuesta: Re: OnPlayerStateChange statement ain't working - [CG]Milito - 04.01.2015

Quote:
Originally Posted by Sid_Alexander
Посмотреть сообщение
What are you trying to figure out? stop the audio stream and print it in the console?
Nope.
I'm trying to get vehicle coords by checking if it's an owned vehicle
To check if its owned I use the validcar variable.
Then if it's valid (Owned vehicle) save the coords into CarInfo vars


Re: Respuesta: Re: Respuesta: Re: OnPlayerStateChange statement ain't working - Sid_Alexander - 04.01.2015

Quote:
Originally Posted by [CG]Milito
Посмотреть сообщение
Nope.
I'm trying to get vehicle coords by checking if it's an owned vehicle
To check if its owned I use the validcar variable.
Then if it's valid (Owned vehicle) save the coords into CarInfo vars
Try using this OnPlayerExitVehicle, Then it may work.

Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
		new vehid = LastVehicle[playerid];
        if(validcar[vehid])
        {
            GetVehiclePos(vehid,CarInfo[vehid][cXPos],CarInfo[vehid][cYPos],CarInfo[vehid][cZPos]);
            printf("%f, %f, %f",CarInfo[vehid][cXPos],CarInfo[vehid][cYPos],CarInfo[vehid][cZPos]);
        }
        LastVehicle[playerid]= INVALID_VEHICLE_ID;
	return 1;
}



Re: OnPlayerStateChange statement ain't working - Crayder - 04.01.2015

Wait, is validcar an array of vehicles? If so you should consider making a foreach iterator. Also, honestly I have no idea what the point of this piece of code is supposed to be printing considering what vehicle, his old vehicle or the vehicle he just exited. If your trying to use the one he just exited why are you using LastVehicle as the vehicle being checked?


Respuesta: Re: OnPlayerStateChange statement ain't working - [CG]Milito - 04.01.2015

Quote:
Originally Posted by Crayder
Посмотреть сообщение
Wait, is validcar an array of vehicles? If so you should consider making a foreach iterator. Also, honestly I have no idea what the point of this piece of code is supposed to be printing considering what vehicle, his old vehicle or the vehicle he just exited. If your trying to use the one he just exited why are you using LastVehicle as the vehicle being checked?
The validcar variable gets set to true when it's an owned vehicle. So I check if the last vehicle they exit is an owned one, if so, I get the car's last position to save it in my database.
But I'm considering re-do my private vehicle system because the current one is a little bit buggy.


Re: OnPlayerStateChange statement ain't working - Crayder - 04.01.2015

I recommend re-doing, then try all this again. This time, use an iterator name OwnedVehicle. Add each owned vehicle to that iterator. If you do it correctly and stuff, you should be able to use it in a foreach loop like so:
pawn Код:
foreach(OwnedVehicle, v) if(LastVehicle[playerid] == v)
{
    //Put stuff here.
    break; //End the loop here, the match has been found!
}