Get Vehicle's Driver
#1

How to get the vehicle's driver name, id, anything
Reply
#2

Just this:

PHP код:
stock GetVehicleDriverID(vehicleid)
{
    for(new 
i,l=GetPlayerPoolSize()+1i<li++) if(GetPlayerState(i) == PLAYER_STATE_DRIVER && IsPlayerInVehicle(i,vehicleid)) return i;
    return -
1;

So if it returns -1, the vehicle has no driver
Reply
#3

So if I want to give him money or do anything I have to
PHP код:
GivePlayerMoney(GetVehicleDriverID(vehicleid), 1); 
Right?
Reply
#4

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
Right?
Nah make sure, the driver exist, so do this:

PHP код:
new driver GetVehicleDriverID(vehicleid);
if(
driver == -1) return 1//Here no driver exist!
GivePlayerMoney(driver1); 
Reply
#5

It is quite simple actually.

pawn Код:
stock GetVehicleDriver(vehicleid)
{
     for(new i=0;i<MAX_PLAYERS;i++) //Or I would personally recommend using foreach.
     {
          if(GET_PLAYER_STATE(i) == PLAYER_STATE_DRIVER)
          {
               new vid = GetPlayerVehicleID(i);
               if(vid == vehicleid) return i;
          }
     }
     return -1;
}
And then to give money:

pawn Код:
GivePlayerMoney(GetVehicleDriver(vehicleid), 100); //Change 100 to the amount.
Reply
#6

Quote:
Originally Posted by nmader
Посмотреть сообщение
It is quite simple actually.
Dude! Read the thread..i postet a better function...

Becuase in your code, if nobody in the vehicle..you return playerid 0..but this is a valid id!!!

And..u didn't checked if the player is a driver
Reply
#7

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Dude! Read the thread..i postet a better function...

Becuase in your code, if nobody in the vehicle..you return playerid 0..but this is a valid id!!!

And..u didn't checked if the player is a driver
I was posting a more readable version of the code. And that was a quick type up, all I have to do is switch return 0 to -1. And I just noticed I forgot to check if the player was a driver haha xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)