OnPlayerStateChange statement ain't working
#1

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
Reply
#2

Can you show the whole code and the error?
Reply
#3

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
Reply
#4

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?
Reply
#5

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
Reply
#6

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;
}
Reply
#7

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?
Reply
#8

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.
Reply
#9

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!
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)