Teleport as passenger?
#1

Hi guys. Yesterday I got a simple teleport FS working via the Scoreboard, and here's the current code:

pawn Код:
#define FILTERSCRIPT

#include <a_samp>

public OnFilterScriptInit()
{
    print("\n----------------------------------------------");
    print(" Teleport-to-player via Scoreboard by WizardCM");
    print("----------------------------------------------\n");
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(clickedplayerid, X, Y, Z);
        if (IsPlayerInAnyVehicle(playerid)) SetVehiclePos(GetPlayerVehicleID(playerid), X+5, Y+5, Z);
        else SetPlayerPos(playerid, X+1, Y+1, Z);
        return 1;
}
It works as I want it, so if you are driving it teleports you as well as your car and any passengers. But...

What I'd like to do is the following:

Quote:

When teleporting to someone, check if the other player is in a car.
If they are, check if there are any passenger seats available.
If there are, teleport to their car as a passenger.
Otherwise just teleport normally.

Any help would be greatly appreciated. Thanks in advance!
Reply
#2

https://sampwiki.blast.hk/wiki/Function:PutPlayerInVehicle

i think thats what u mean
Reply
#3

Quote:
Originally Posted by Kitten
Посмотреть сообщение
Yep, so how would I go about coding that?

I'm guessing I would need to use https://sampwiki.blast.hk/wiki/GetPlayerVehicleSeat
to check if the other player is driving, then use https://sampwiki.blast.hk/wiki/PutPlayerInVehicle
to put the current player into a passenger seat.

I'm still confused. xD
Reply
#4

You can use this function, to detect where there is a free seat in the car, so no one gets kicked, if there are other passengers:

pawn Код:
GetVehiclePassengers(vehicleid, passengers[4])
{
    for(new i = 0; i < 4; i ++)
        passengers[i] = -1;
    for(new i = 0; i < MAX_PLAYERS; i ++)
        if(GetPlayerVehicleID(i) == vehicleid)
            passengers[GetPlayerVehicleSeat(i)] = i;
}
(Still did not test it, even i posted it sometimes already )

It is used like this:
pawn Код:
if(IsPlayerInAnyVehicle(player_tele_target))    //To detect if the target is in a vehicle
{
    new passengers[4];
    GetVehiclePassengers(GetPlayerVehicleID(player_tele_target), passengers);
    //GetVehicePassengers fills the array with the playerid at the specific seat (passengers[0] is the driver etc)
    //and with -1 if it is free, so check for -1 with a loop
    for(new i = 0; i < 4; i ++)
    {
        if(passengers[i] == -1) PutPlayerInVehicle(playerid, GetPlayerVehicleID(player_tele_target), i);
        //This will put the player on the first free seat
    }
}
Reply
#5

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
You can use this function, to detect where there is a free seat in the car, so no one gets kicked, if there are other passengers:

~snip
(Still did not test it, even i posted it sometimes already )

It is used like this:
~snip
Alrighty, now how do I use this? (I've only been teaching myself Pawn for the past 2 days)
Reply
#6

Well, I figured out how to use the code, but it doesn't seem to work. Here's what I'm using:

pawn Код:
#include <a_samp>

GetVehiclePassengers(vehicleid, passengers[4])
{
    for(new i = 0; i < 4; i ++)
        passengers[i] = -1;
    for(new i = 0; i < MAX_PLAYERS; i ++)
        if(GetPlayerVehicleID(i) == vehicleid)
            passengers[GetPlayerVehicleSeat(i)] = i;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(clickedplayerid, X, Y, Z);
        if(IsPlayerInAnyVehicle(clickedplayerid))    //To detect if the target is in a vehicle
{
    new passengers[4];
    GetVehiclePassengers(GetPlayerVehicleID(clickedplayerid), passengers);
    //GetVehicePassengers fills the array with the playerid at the specific seat (passengers[0] is the driver etc)
    //and with -1 if it is free, so check for -1 with a loop
    for(new i = 0; i < 4; i ++)
    {
        if(passengers[i] == -1) PutPlayerInVehicle(playerid, GetPlayerVehicleID(clickedplayerid), i);
        //This will put the player on the first free seat
    }
}
        if (IsPlayerInAnyVehicle(playerid)) SetVehiclePos(GetPlayerVehicleID(playerid), X+5, Y+5, Z);
        else SetPlayerPos(playerid, X+1, Y+1, Z);
        return 1;
}
Help?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)