/respawnallvehicles - Making vehicles spawn with same ID
#1

I'd like to recreate the vehicles in the SAME ID so I don't need to reload the vehicle variables. How do I do this?
pawn Код:
CMD:respawnallvehicles(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(AdminLevel[playerid] < 1) return SendClientMessage(playerid, COLOUR_GREY, "You are not authorized to use this command.");
    new string[128], vehid;
    for(new v = 1; v  < GetVehiclePoolSize()+1; v++)
    {
        if(GetVehicleModel(v) != 510 && !IsATrailer(v) && !IsVehicleInUse(v))
            {
            vehid = v;
                        DestroyVehicle(v);
                        CreateVehicle(VehModel[vehid], VehSpawnX[vehid], VehSpawnY[vehid], VehSpawnZ[vehid],             VehSpawnAngle[vehid], VehColour1[vehid], VehColour2[vehid], 0, VehSiren[vehid]);
            SetVehicleNumberPlate(vehid, VehPlate[vehid]);
            new vehicleid = vehid;
            if(VehOwner[vehicleid] > 0 || VehicleFaction[vehicleid] > 0)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 1, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
            if(VehJob[vehicleid] > 0 || VehDealership[vehicleid] > 0 || RentVeh[vehicleid] == 1)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 0, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
        }
    }
    format(string, sizeof(string), ""COL_GREEN"All Vehicles Respawned.");
    SendClientMessage(playerid, COLOUR_WHITE, string);
    SendClientMessageToAll(COLOUR_WHITE, "All vehicles have been respawned.");
    return 1;
}
I think this may be slightly bugged due to ID's being messed up and this command below duplicates vehicles.
pawn Код:
CMD:frespawnall(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    new string[128], id;
    if(FRank[playerid] < 5 && AdminLevel[playerid] < 1)return SendClientMessage(playerid, COLOUR_GREY, "You must be at least rank 5 to use this.");
    for(new v = 1; v < GetVehiclePoolSize()+1; v++)
    {
        if(VehicleFaction[v] == Faction[playerid])
        {
            id = v;
            DestroyVehicle(v);
            CreateVehicle(VehModel[id], VehSpawnX[id], VehSpawnY[id], VehSpawnZ[id], VehSpawnAngle[id], VehColour1[id], VehColour2[id], 0, VehSiren[id]);
            format(string, sizeof(string), "Vehicle: "COL_WHITE"%d Respawned.", id);
            SetVehicleNumberPlate(id, VehPlate[id]);
            new vehicleid = id;
            if(VehOwner[vehicleid] > 0 || VehicleFaction[vehicleid] > 0)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 1, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
            if(VehJob[vehicleid] > 0 || VehDealership[vehicleid] > 0 || RentVeh[vehicleid] == 1)
            {
                SetVehicleParamsEx(vehicleid, 0, 0, 0, 0, 0, 0, 0);
                SetVehicleParamsCarDoors(vehicleid, 0,0,0,0);
                SetVehicleParamsCarWindows(vehicleid, 1,1, 1, 1);
            }
        }
    }
    format(string, sizeof(string), "ALL FACTION VEHICLES RESPAWNED.");
    SendClientMessage(playerid, COLOUR_ORANGE, string);
    return 1;
}
Reply
#2

SetVehicleToRespawn() maybe?
Reply
#3

That won't set the ZAngle.
Reply
#4

Respawning vehicles in same id is not an option unless you do something like this:
PHP код:
new tempvehs[MAX_VEHICLES];
for(new 
v;v<=GetVehiclePoolSize()+1;v++)
{
 if(
IsValidVehicle(v)) continue;
 if(
v!=vehidtempvehs[v]=!!(CreateVehicle(...create something temp here));
 else 
  {
  
CreateVeh
  
for(new i;i<GetVehiclePoolSize();i++) if(tempvehs[i]) DestroyVehicle(i);
  }

However, I urge you not to use VehID as array ID, but rather save the vehid in an array variable.
Reply
#5

SetVehicleToRespawn + timerex in OnVehicleSpawn for setting pos again and angle
Reply
#6

Example:
pawn Код:
// ** INCLUDES

#include <a_samp>
#include <zcmd>

// ** ARRAYS AND ENUMERATORS

enum eVehicleInfo
{
    Float:vehicle_info_x,
    Float:vehicle_info_y,
    Float:vehicle_info_z,
    Float:vehicle_info_angle
};

new aVehicleInfo[MAX_VEHICLES][eVehicleInfo];

// ** MAIN

main()
{
    print("Loaded \"vehicle_angle_fix_park.amx\".");
}

// ** CALLBACKS

public OnGameModeInit()
{
    new vehicle_id = AddStaticVehicle(400, 132.1159, -92.7907, 1.5220, 291.6237, 123, 1);
    GetVehiclePos(vehicle_id, aVehicleInfo[vehicle_id][vehicle_info_x], aVehicleInfo[vehicle_id][vehicle_info_y], aVehicleInfo[vehicle_id][vehicle_info_z]);
    GetVehicleZAngle(vehicle_id, aVehicleInfo[vehicle_id][vehicle_info_angle]);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    SetVehiclePos(vehicleid, aVehicleInfo[vehicleid][vehicle_info_x], aVehicleInfo[vehicleid][vehicle_info_y], aVehicleInfo[vehicleid][vehicle_info_z]);

    SetTimerEx("SetVehicleZAngleAfterSpawn", 1500, false, "i", vehicleid);
    return 1;
}

// ** COMMANDS

CMD:respawnvehicles(playerid, params[])
{
    for(new i = 1, j = GetVehiclePoolSize(); i <= j; i ++)
    {
        SetVehicleToRespawn(i);
    }
    return 1;
}

CMD:park(playerid, params[])
{
    new vehicle_id = GetPlayerVehicleID(playerid);
    GetVehiclePos(vehicle_id, aVehicleInfo[vehicle_id][vehicle_info_x], aVehicleInfo[vehicle_id][vehicle_info_y], aVehicleInfo[vehicle_id][vehicle_info_z]);
    GetVehicleZAngle(vehicle_id, aVehicleInfo[vehicle_id][vehicle_info_angle]);
    return 1;
}

// ** FUNCTIONS

forward SetVehicleZAngleAfterSpawn(vehicle_id);
public SetVehicleZAngleAfterSpawn(vehicle_id)
{
    SetVehicleZAngle(vehicle_id, aVehicleInfo[vehicle_id][vehicle_info_angle]);
    return 1;
}
Reply
#7

Thanks for the help! I've resorted to just reloading the vars.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)