RespawnVehicle command
#1

Hey guys,

How can I create a command like if I am standing near a vehicle and type /respawnvehicle it respawns?

I don't know, I want it to check if an admin is near/beside a vehicle and types /respawnvehicle it respawns or get destroyed .. How?
Reply
#2

pawn Код:
CMD:respawnvehicle(playerid,params[])
{
    new vid = GetNearestVehicle(playerid,5.0);
    SetVehicleToRespawn(vid);
    return 1;
}
that command will do it, you also need this stock, place it, like the command above, outside any callback
pawn Код:
stock GetNearestVehicle(playerid, Float:dis)
{
    new Float:L, Float:O, Float:II;
    if(GetPlayerPos(playerid, L, O, II))
    {
        new vehicleid = INVALID_VEHICLE_ID;
        for(new v, Float:temp, Float:VL, Float:VO, Float:VII; v != MAX_VEHICLES; v++)
        {
            if(GetVehiclePos(v, VL, VO, VII) && v != GetPlayerVehicleID(playerid))
            {
                VL -= L, VO -= O, VII -= II;
                temp = VL * VL + VO * VO + VII * VII;
                if(temp < dis) dis = temp, vehicleid = v;
            }
        }
        dis = floatpower(dis, 0.5);
        return vehicleid;
    }
    return INVALID_VEHICLE_ID;
}
Reply
#3

ON TOPIC:
I need /respawnall on dcmd..
To respawn all un occupied vehicles,

Can you?
Reply
#4

pawn Код:
dcmd_respawnall(playerid,params[])
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        SetVehicleToRespawn(i);
    }
    return 1;
}
Reply
#5

this is the commands.
pawn Код:
CMD:rac(playerid, params[])
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(IsVehicleOccupied(i))
        {
            DestroyVehicle(i);
        }
    }
    return 1;
}
and the stock.
pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            return 1;
        }
    }
  return 0;
}
Reply
#6

Quote:
Originally Posted by Devilxz97
Посмотреть сообщение
this is the commands.
pawn Код:
CMD:rac(playerid, params[])
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(IsVehicleOccupied(i))
        {
            DestroyVehicle(i);
        }
    }
    return 1;
}
and the stock.
pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            return 1;
        }
    }
  return 0;
}
This will not respawn the vehicles, this will simply delete them permanently. Hence the function 'DESTROYvehicle'.
Reply
#7

Then do:
pawn Код:
CMD:rac(playerid, params[])
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        if(IsVehicleOccupied(i))
        {
            SetVehicleToRespawn(i);
        }
    }
    return 1;
}
and the stock
pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            return 1;
        }
    }
  return 0;
}
This is the exact code Devilxz97 posted, but this one, will respawn the vehicle if it's unoccupied
Reply
#8

pawn Код:
if(IsVehicleOccupied(i))
        {
            SetVehicleToRespawn(i);
        }
Actually, this code is going to respawn all OCCUPIED vehicles, while he wants the NON-OCCUPIED vehicles to get respawned:
pawn Код:
if(!IsVehicleOccupied(i))
        {
            SetVehicleToRespawn(i);
        }
Reply
#9

Thanks a lot guys, it's working perfectly .
Reply
#10

Can someone post a full pawn??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)