Store playerid in vehicle (Please Help)
#1

Hello everyone from this big community, i want done a simple script and not work really..

I want store the id of the player in a vehicle example

I create the global variable..
Код:
new OwnerId[MAX_VEHICLES];
When the player enter in the vehicle the playerid need be stored
Код:
OwnerId[getPlayerVehicleID] = playerid;
But this not work, what is the best method?
Thanks in advance
Reply
#2

GetPlayerVehicleID(playerid) is the correct usage of that function.
Reply
#3

pawn Код:
OwnerId[GetPlayerVehicleID(playerid)] = playerid;
//or
format(OwnerId[GetPlayerVehicleID(playerid)], 4, "%d", playerid);
You should also place these under OnPlayerStateChange since when OnEnterVehicle is called, you're not in the vehicle but you're currently entering it.
Reply
#4

Thanks alot for both replies, i miss write the function without erros, let me test
Reply
#5

Not work that give me "0"
Reply
#6

If it outputs 0, and your player ID is 0, it works?
However, this will set the variable to -1 and then to playerid, so if it says 0 now it works (if you have the player id 0):

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        OwnerId[GetPlayerVehicleID(playerid)] = -1;
        OwnerId[GetPlayerVehicleID(playerid)] = playerid;
    }
    return 1;
}
Also, you can use this to DEBUG if you haven't done yet:

pawn Код:
new string[10];
format(string, sizeof(string), "ID: %d", OwnerId[GetPlayerVehicleID(playerid)]);
SendClientMessage(playerid, -1, string);
Will output the player ID if it has been saved to the variable.
Reply
#7

I have a dialog, when i select the first option the playerid need be added in OwnerId[GetPlayerVeh....]

check this
Код:
switch(listitem) {
		        case 0:
			{
                            OwnerId[GetPlayerVehicleID(playerid)] = playerid;
                        }
...
Then when the player enter in the car, the car give the info of the owner of the car but nothing work ;(


Код:
	new carid = GetPlayerVehicleID(playerid);
			if(OwnerId[carid] != 0)
			{
				new name[MAX_PLAYER_NAME+1];
				GetPlayerName(OwnerId[carid], name, sizeof(name));

				format(szMessage, sizeof(szMessage), "The owner of this car is: %s", name);
 		 		SendClientMessage(playerid, COLOR_WHITE, szMessage);
			}
EDIT: TESTING! xD
Reply
#8

Thanks alot SKAzini it work without problems, have a nice day!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)