SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 23/07/2011, 10:43 PM   #1
smeti
Huge Clucker
 
smeti's Avatar
 
Join Date: Sep 2008
Posts: 316
Reputation: 32
Default GetVehicleDriver(vehicleid)

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

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

Not for loop.

Test script:
pawn Code:
#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 Code:
#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;
}

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

Last edited by smeti; 24/07/2011 at 08:04 AM. Reason: Bug fixed
smeti is offline   Reply With Quote
Old 24/07/2011, 02:05 AM   #2
[DOG]irinel1996
High-roller
 
[DOG]irinel1996's Avatar
 
Join Date: Jan 2010
Posts: 1,693
Reputation: 288
Default Respuesta: GetVehicleDriver(vehicleid)

Really good, I mean, amazing. :O
Thanks a lot!
[DOG]irinel1996 is offline   Reply With Quote
Old 24/07/2011, 02:11 AM   #3
=WoR=Varth
High-roller
 
=WoR=Varth's Avatar
 
Join Date: Apr 2011
Location: Indonesia
Posts: 2,010
Reputation: 133
Default Re: GetVehicleDriver(vehicleid)

Well not a bad idea.
Good job to' there's GetVehicleDriverID in uf.inc.
__________________
(RETIRED)
=WoR=Varth is offline   Reply With Quote
Old 24/07/2011, 03:12 AM   #4
Deskoft
Guest
 
Posts: n/a
Default Re: GetVehicleDriver(vehicleid)

Why make it a include when you can just publish it as a stock?
  Reply With Quote
Old 02/10/2011, 09:52 AM   #5
FireCat
High-roller
 
FireCat's Avatar
 
Join Date: Jul 2010
Posts: 2,403
Reputation: 596
Default Re: GetVehicleDriver(vehicleid)

Quote:
Originally Posted by Sandra18[NL] View Post
GetVehicleDriver(vehicleid)
Returns the ID of the player driving in the vehicle. Returns '-1' if nobody is driving in the vehicle.
Code:
stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == 2)
      {
    		return i;
      }
	}
  }
  return -1;
}
....
FireCat is offline   Reply With Quote
Old 02/10/2011, 01:33 PM   #6
wups
High-roller
 
wups's Avatar
 
Join Date: Apr 2010
Location: Lithuania
Posts: 1,251
Reputation: 137
Default Re: GetVehicleDriver(vehicleid)

Quote:
Originally Posted by FireCat View Post
....
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.
wups is offline   Reply With Quote
Old 02/10/2011, 02:33 PM   #7
Michael@Belgium
High-roller
 
Michael@Belgium's Avatar
 
Join Date: Dec 2010
Location: Belgium
Posts: 3,033
Reputation: 1001
Default Re: GetVehicleDriver(vehicleid)

Hmm i can use this for my derby server ... like: "You hitted <players> vehicle with x damage!"
But good include !
__________________
Mah Github. - Need host-tab ? Contact me on discord: michaelbelgium#2759

sO aCtIvE
You last visited: 11/01/2018 at 11:21 PM
Michael@Belgium is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible vehicleid bug? FufLa Bug Reports 56 16/07/2015 04:47 AM
[SUG] GetVehicleDriver GooMan Help Archive 1 15/12/2010 10:22 AM
Vehicleid? Darekfred Help Archive 2 04/01/2010 01:00 AM
VehicleID Grex Help Archive 4 16/09/2009 06:06 PM


All times are GMT. The time now is 09:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.