Get Vehicle's Driver - 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: Get Vehicle's Driver (
/showthread.php?tid=580330)
Get Vehicle's Driver -
nezo2001 - 04.07.2015
How to get the vehicle's driver name, id, anything
AW: Get Vehicle's Driver -
Kaliber - 04.07.2015
Just this:
PHP код:
stock GetVehicleDriverID(vehicleid)
{
for(new i,l=GetPlayerPoolSize()+1; i<l; i++) if(GetPlayerState(i) == PLAYER_STATE_DRIVER && IsPlayerInVehicle(i,vehicleid)) return i;
return -1;
}
So if it returns -1, the vehicle has no driver
Re: Get Vehicle's Driver -
nezo2001 - 04.07.2015
So if I want to give him money or do anything I have to
PHP код:
GivePlayerMoney(GetVehicleDriverID(vehicleid), 1);
Right?
AW: Re: Get Vehicle's Driver -
Kaliber - 04.07.2015
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(driver, 1);
Re: Get Vehicle's Driver -
nmader - 04.07.2015
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.
AW: Re: Get Vehicle's Driver -
Kaliber - 04.07.2015
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
Re: AW: Re: Get Vehicle's Driver -
nmader - 04.07.2015
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