Get in Player Vehicle [PROBLEM]
#1

I create a Command named /giv (get in Players Vehicle)

But if I use this command the driver get out of his car :/ Can someone fix it ?

Код:
COMMAND:rov(playerid,params[])
{

    	new targetid;
    	if( sscanf( params, "u", targetid ) ) return SendClientMessage( playerid, -1, "Usage: /giv [playerid]" );
    	if( targetid == INVALID_PLAYER_ID ) return SendClientMessage( playerid, -1, "Invalid playerid!" );
    	if( !IsPlayerInAnyVehicle( targetid ) ) return SendClientMessage( playerid, -1, "This player has no vehicle!" );
    	RemovePlayerFromVehicle( targetid );
    	PutPlayerInVehicle( playerid, GetPlayerVehicleID( targetid ), 0 );
    	return 1;
}
Reply
#2

It's because of this line:

pawn Код:
RemovePlayerFromVehicle( targetid );
This means the targetid (the ID you put in /giv) gets forced out of the vehicle.
Reply
#3

replace this line--
pawn Код:
PutPlayerInVehicle( playerid, GetPlayerVehicleID( targetid ), 0 );
by this
pawn Код:
PutPlayerInVehicle( playerid, GetPlayerVehicleID( targetid ), 1 );
Reply
#4

Actually, it took me a long time to get all these details, and there's probably the same thing hidden on SA-MP forums somewhere, but I wasn't ready to look. This is my code from quite a while ago, but it will still work perfectly. I can't believe I got it to work the way it does, especially at the level I was at during the time I made this...

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <foreach>

new MaxVehicleSeats[212] =
{
    4, 2, 2, 2, 4, 4, 1, 2, 2, 4, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 4, 4, 2, 2, 2,
    1, 4, 4, 4, 2, 1, 9, 1, 2, 2, 0, 2, 9, 4, 2, 4, 1, 2, 2, 2, 4, 1,
    2, 1, 2, 0, 2, 1, 1, 1, 2, 2, 2, 4, 4, 2, 2, 1, 2, 1, 2, 4, 4, 2, 2, 4, 2, 1,
    1, 2, 2, 1, 2, 2, 4, 2, 1, 4, 3, 1, 1, 1, 4, 4, 2, 4, 2, 4, 1, 2, 2, 2, 4, 4,
    2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 1, 1, 2, 1, 1, 2, 2, 4, 2, 2, 1, 1, 2, 2, 2, 2,
    2, 2, 2, 2, 4, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 4, 2, 2, 2, 2, 2, 4, 4, 2, 2, 4,
    4, 2, 1, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 1, 2, 4, 4, 1, 0, 0, 1, 1, 2,
    1, 2, 2, 4, 2, 4, 4, 2, 4, 1, 0, 4, 2, 2, 2, 2, 0, 0, 2, 2, 1, 1,
    4, 4, 4, 2, 2, 2, 2, 2, 4, 2, 0, 0, 0, 4, 0, 0
};

CMD:gipv(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, 0xFF0000FF, "{9ACD32}[INFO]: {FFFFFF}/gipv [name/id]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "Player not found.");
    if(!IsPlayerInAnyVehicle(id)) return SendClientMessage(playerid, 0xFF0000FF, "Player is not in any vehicle.");
    if(!GetAvailableSeats(GetPlayerVehicleID(id))) return SendClientMessage(playerid, 0xFF0000FF, "This player's vehicle cannot seat any more players.");
    PutPlayerInVehicle(playerid, GetPlayerVehicleID(id), GetNextSeat(GetPlayerVehicleID(id)));
    SendClientMessage(playerid, 0xFFFF00FF, "You have teleported into the player's vehicle.");
    return 1;
}

stock GetAvailableSeats(vehicleid)
{
    new maxseats = MaxVehicleSeats[(GetVehicleModel(vehicleid) - 400)];
    foreach(Player, i)
    {
        if(IsPlayerInVehicle(i, vehicleid))
        {
            if(maxseats <= 0) break;
            maxseats--;
        }
    }
    return maxseats;
}

stock GetNextSeat(vehicleid)
{
    new available;
    new seat[10];
    foreach(Player, i)
    {
        if(IsPlayerInVehicle(i, vehicleid))
        {
            seat[GetPlayerVehicleSeat(i)] = 1;
        }
    }
    for(new v = 0; v < MaxVehicleSeats[GetVehicleModel(vehicleid) - 400]; v++)
    {
        if(seat[v] == 1) continue;
        available = v;
    }
    return available;
}
NOTE: This requires the following includes:
- ZCMD (By ZeeX)
- Foreach (By ******)
- a_samp (By The SA-MP Team)
- sscanf2 (By ******)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)