SA-MP Forums Archive
[Include] GetVehicleDriver(vehicleid) - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] GetVehicleDriver(vehicleid) (/showthread.php?tid=271321)



GetVehicleDriver(vehicleid) - smeti - 23.07.2011

Download:
http://solidfiles.com/d/ed99/

v1.1
http://solidfiles.com/d/4a198/

Not for loop.

Test script:
pawn Код:
#include <a_samp>

#define FILTERSCRIPT
#include <zcmd>
#include <getvehicledriver>

#if defined FILTERSCRIPT
public
    OnFilterScriptInit()
{
#else
public
    OnGameModeInit()
{
#endif
    return 1;
}  
   
// test command
COMMAND:getvehicledriver(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, -1, "Usage: /getvehicledriver [vehicleid 1 - 2000]");
    new
        str[128],
        player1 = GetVehicleDriver(strval(params));
    if(player1 != INVALID_PLAYER_ID)
    {
        new
            PlayerN[MAX_PLAYER_NAME];
        GetPlayerName(player1, PlayerN, 24);
        format(str, sizeof str, "VehicleDriver  vehicleid: %d | playerid: %d | PlayerName: %s", GetPlayerVehicleID(player1), player1, PlayerN);
        SendClientMessage(playerid, -1, str);
    } else {
        SendClientMessage(playerid, -1, "No player is the driver as"); // Sorry ****** translate
    }
    return 1;
}

/*
//old code:
stock
    GetVehicleDriver(vehicleid) by.: forum.sa-mp.com user
{
    for(new i; i < 500; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
        if(GetPlayerVehicleID(i) == vehicleid)
        {
            return i;
        }
    }
    return -1;
}
*/



Example code put in OnGameModeInit Or OnFilterScriptInit

pawn Код:
#include <a_samp>
/*
    GetVehicleDriver function by Zsolesszka aka Phento v1.1
    Date 2011.07.23
    Example put In OnGameModeInit Or OnFilterScriptInit
*/

static
    VehicleDriverPlayerid[MAX_VEHICLES] = { INVALID_PLAYER_ID, ... };
   
//------------------------------------------------------------------------------
stock
    GetVehicleDriver(vehicleid)
{
    if(vehicleid < 1 || vehicleid > sizeof(VehicleDriverPlayerid)) return INVALID_PLAYER_ID; // invalid array
    if(VehicleDriverPlayerid[vehicleid - 1] != INVALID_PLAYER_ID  && IsPlayerInVehicle(VehicleDriverPlayerid[vehicleid - 1], vehicleid) && GetPlayerVehicleSeat(VehicleDriverPlayerid[vehicleid - 1]) == 0)
        return VehicleDriverPlayerid[vehicleid - 1]; // return playerid vehicledriver
    return VehicleDriverPlayerid[vehicleid - 1] = INVALID_PLAYER_ID;
}
       
//------------------------------------------------------------------------------
public
    OnPlayerStateChange(playerid, newstate, oldstate)
{
// ->
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new
            vehicleid = GetPlayerVehicleID(playerid);
        if(vehicleid)
        {
            VehicleDriverPlayerid[vehicleid - 1] = playerid;
        }
    }
//-<
    return 1;
}

//------------------------------------------------------------------------------



Respuesta: GetVehicleDriver(vehicleid) - [DOG]irinel1996 - 24.07.2011

Really good, I mean, amazing. :O
Thanks a lot!


Re: GetVehicleDriver(vehicleid) - =WoR=Varth - 24.07.2011

Well not a bad idea.
Good job to' there's GetVehicleDriverID in uf.inc.


Re: GetVehicleDriver(vehicleid) - Deskoft - 24.07.2011

Why make it a include when you can just publish it as a stock?


Re: GetVehicleDriver(vehicleid) - FireCat - 02.10.2011

Quote:
Originally Posted by Sandra18[NL]
Посмотреть сообщение
GetVehicleDriver(vehicleid)
Returns the ID of the player driving in the vehicle. Returns '-1' if nobody is driving in the vehicle.
Код:
stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == 2)
      {
    		return i;
      }
	}
  }
  return -1;
}
....


Re: GetVehicleDriver(vehicleid) - wups - 02.10.2011

Quote:
Originally Posted by FireCat
Посмотреть сообщение
....
Check the script first! This method he's using is MUCH more effective, than the stock looping function.
And no, this couldn't be released as a stock.


Re: GetVehicleDriver(vehicleid) - Michael@Belgium - 02.10.2011

Hmm i can use this for my derby server ... like: "You hitted <players> vehicle with x damage!"
But good include !