SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 03/08/2014, 05:56 PM   #1
d3ll
Big Clucker
 
Join Date: May 2014
Location: England
Posts: 93
Reputation: 17
Default Extended functions on Vehicles / Seats

Created this around 4 hours ago. There isn't really much to explain about it. Just around 8 functions that would should be useful to some people.


Function list:


pawn Code:
GetVehicleDriver(vehicleid) // Get's the driver of your current vehicle.
GetVehiclePassenger(vehicleid) // Get's the passenger seat player. (Only, the pasenger next to driver)
GetVehiclePassengers(vehicleid, &seat0 = INVALID_SEAT, &seat1 = INVALID_SEAT, &seat2 = INVALID_SEAT, &seat3 = INVALID_SEAT, &seat4 = INVALID_SEAT) // Collects the ID of everyone inside the vehicle.
GetUnusedSeat(vehicleid) // Returns the ID of a seat avaiable inside a specific vehicle
IsSeatUsed(vehicleid, seatid) // Simply checks if the vehicle seat is occupied.
GetLastPlayer(vehicleid) // Get's the ID of a player who last used this vehicle (Passenger / Driver)
GetDriverHP(vehicleid) // Self explanatory..
GetEveryoneHP(vehicle) // Get's the health of everyone inside the vehicle (In one, kinda useless.. but I needed it..)

Example:

pawn Code:
COMMAND:getdriver(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new iStr [ 128 ] ;
        if(GetVehicleDriver(vehicleid) != -1) format(iStr, sizeof(iStr), " Driver: %s", PlayerName(GetVehicleDriver(vehicleid)));
        else format(iStr, sizeof(iStr), " Driver: None");
        SendClientMessage(playerid, -1, iStr);
    }
    else return SendClientError(playerid, "No..");
    return 1;
}

Downloads:


Pastebin

Alt:

pawn Code:
/*****************************************************************************************************
    All by d3ll
******************************************************************************************************/


//native IsValidVehicle(vehicleid);

#undef MAX_VEHICLES
#define MAX_VEHICLES 2000

new LastPlayerToEnter[MAX_VEHICLES] = -1;

#define INVALID_SEAT 128
#define PlayerLoop(%1) for(new %1 = 0; %1 < MAX_PLAYERS; %1++) if(IsPlayerConnected(%1) && !IsPlayerNPC(%1))

stock GetVehicleDriver(vehicleid)
{
    if(IsValidVehicle(vehicleid) == 0) return -1;
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(IsPlayerConnected(p) != 1 || IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerState(p) != PLAYER_STATE_DRIVER) continue;
        return p;
    }
    return -1;
}

stock GetVehiclePassenger(vehicleid)
{
    if(IsValidVehicle(vehicleid) == 0) return -1;
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(IsPlayerConnected(p) != 1 || IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerVehicleSeat(p) != 1) continue;
        return p;
    }
    return -1;
}

stock GetVehiclePassengers(vehicleid, &seat0 = INVALID_SEAT, &seat1 = INVALID_SEAT, &seat2 = INVALID_SEAT, &seat3 = INVALID_SEAT, &seat4 = INVALID_SEAT)
{
    PlayerLoop(p)
    {
        if(IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != cehicleid) continue;
        if(GetPlayerVehicleSeat(p) == 128 || GetPlayerVehicleSeat(p) == -1) continue;
        if(GetPlayerVehicleSeat(p) == 0) seat0 = p;
        if(GetPlayerVehicleSeat(p) == 2) seat1 = p;
        if(GetPlayerVehicleSeat(p) == 3) seat2 = p;
        if(GetPlayerVehicleSeat(p) == 4) seat3 = p;
        if(GetPlayerVehicleSeat(p) >= 5) seat4 = p;
    }
}

stock GetUnusedSeat(vehicleid)
{
    new UsedSeats[6] = -1;
    PlauyerLoop(p)
    {
        if(IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerVehicleSeat(p) == 128 || GetPlayerVehicleSeat(p) == -1) continue;
        for(new c = 0; c < sizeof(UsedSeats); c++)
        {
            if(GetPlayerVehicleSeat(p) == c) UsedSeats[c] = 1;
            if(UsedSeats[c] != 1) return c;
        }
    }
    return -1;
}

stock IsSeatUsed(vehicleid, seatid)
{
    PlayerLoop(p)
    {
        if(IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleSeat(p) == seatid && GetPlayerVehicleID(p) == vehicleid) return 1;
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        LastPlayerToEnter[vehicleid] = playerid;
    }
    #if defined DLL_OnPlayerStateChange
        DLL_OnPlayerStateChange(playerid, newstate, oldstate);
    #endif
   
    return 1;
}

stock GetLastPlayer(vehicleid) return LastPlayerToEnter[vehicleid];

stock Float:GetDriverHP(vehicleid)
{
    if(IsValidVehicle(vehicleid) == 0) return -1;
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(IsPlayerConnected(p) != 1 || IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerState(p) != PLAYER_STATE_DRIVER) continue;
        new Float:hP;
        GetPlayerHealth(p, hP);
        return hP;
    }
    return -1;
}

stock Float:GetEveryoneHP(vehicle)
{
    if(IsValidVehicle(vehicleid) == 0) return -1;
    new Float:hP = -1.0;
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(IsPlayerConnected(p) != 1 || IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerState(p) != PLAYER_STATE_DRIVER) continue;
        new Float:pHP;
        GetPlayerHealth(p, pHP);
        hP = (hP + pHP);
    }
    return hP;
}

#if defined _ALS_OnPlayerStateChange
    #undef OnPlayerStateChange
#else
    #define _ALS_OnPlayerStateChange
#endif

#define OnPlayerStateChange DLL_OnPlayerStateChange

#if defined DLL_OnPlayerStateChange
    forward DLL_OnPlayerStateChange(playerid, newstate, oldstate);
#endif

I will update this, in near future. I did this simply for revision :/ Don't like it don't comment.
__________________
Hi, if your reading this I love you.
d3ll is offline   Reply With Quote
Old 03/08/2014, 06:01 PM   #2
Dignity
High-roller
 
Dignity's Avatar
 
Join Date: May 2013
Location: Belgium
Posts: 1,635
Reputation: 1179
Default Re: Extended functions on Vehicles / Seats

Should've used foreach instead of regular loops and that particular define.

Cool sauce regardless.
Dignity is offline   Reply With Quote
Old 03/08/2014, 06:03 PM   #3
iFarbod
Gangsta
 
Join Date: Jan 2014
Location: Los Santos (HD Universe)
Posts: 610
Reputation: 59
Default Re: Extended functions on Vehicles / Seats

Some vehicles has more that 7 seats. at-400, bus, coach
iFarbod is offline   Reply With Quote
Old 04/08/2014, 06:25 AM   #4
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 248
Reputation: 116
Default Re: Extended functions on Vehicles / Seats

pawn Code:
stock Float:GetEveryoneHP(vehicle)
{
    if(IsValidVehicle(vehicleid) == 0) return -1;
    new Float:hP = 0.0; //This should be "0.0" instead of "-1.0"
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(IsPlayerConnected(p) != 1 || IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerState(p) != PLAYER_STATE_DRIVER) continue;
        new Float:pHP;
        GetPlayerHealth(p, pHP);
        hP = (hP + pHP); //If hP is equal to "-1.0" it will deduct "1.0" from the first instance.
    }
    return hP;
}

EDIT:

pawn Code:
stock GetVehiclePassenger(vehicleid)
{
    if(IsValidVehicle(vehicleid) == 0) return -1;
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(IsPlayerConnected(p) != 1 || IsPlayerInAnyVehicle(p) != 1) continue;
        if(GetPlayerVehicleID(p) != vehicleid) continue;
        if(GetPlayerVehicleSeat(p) != 1) continue;
        return p;
    }
    return -1;
}

I think it will just return the id of the very first passenger in a car/bus. What if all the seats are occupied by passengers ?

Last edited by codectile; 04/08/2014 at 06:56 AM.
codectile 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
[Include] Extended vehicle functions Emmet_ Includes 63 21/11/2016 09:00 PM
[Include] FCNPC Extended Functions Pottus Includes 3 27/05/2014 04:37 AM
[Include] exobjects - Extended object functions kristo Includes 2 11/12/2013 07:01 PM
[Include] FileEx (Extended file functions controlling and debugging script) BigETI Includes 4 28/08/2013 12:47 PM
How can I make some cars driving seats locked for players but passengers seats not? jueix Scripting Help 10 24/09/2012 12:10 PM


All times are GMT. The time now is 03:36 AM.


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