Dynamic Job/Faction Vehicles
#1

So my friend has made me a dynamic job/faction vehicles and it has been filled with lots of issues but I think he fell asleep so I'm just going to ask here.

Basically it will create the car, but won't save to each faction/job..... It's weird.

SaveDynamicVehicles & LoadDynamicVehicles
pawn Код:
stock SaveDynamicVehicles()
{
    if (!fexist("dynamicvehicles.cfg"))
        return fremove("dynamicvehicles.cfg");

    new
        File:file = fopen("dynamicvehicles.cfg", io_append),
        str[128]
    ;
    for (new i = 0; i < MAX_DYNAMIC_VEHICLES; i ++) {
        format(str, sizeof(str), "%d|%d|%.4f|%.4f|%.4f|%.4f|%d|%d|%d|%d\r\n",
            VehicleInfo[i][vExists],
            VehicleInfo[i][vModel],
            VehicleInfo[i][vPosX],
            VehicleInfo[i][vPosY],
            VehicleInfo[i][vPosZ],
            VehicleInfo[i][vPosA],
            VehicleInfo[i][vColor1],
            VehicleInfo[i][vColor2],
            VehicleInfo[i][vFaction],
            VehicleInfo[i][vJob]
        );
        fwrite(file, str);
    }
    fclose(file);
    return 1;
}

stock LoadDynamicVehicles()
{
    if (!fexist("dynamicvehicles.cfg"))
        return 0;

    new
        File:file = fopen("dynamicvehicles.cfg", io_read),
        strRead[128],
        arrData[10][16]
    ;
    if (file)
    {
        for (new i = 0; i < MAX_DYNAMIC_VEHICLES; i ++) {
            fread(file, strRead, sizeof(strRead));

            split(strRead, arrData, '|');

            VehicleInfo[i][vExists] = strval(arrData[0]);
            VehicleInfo[i][vModel] = strval(arrData[1]);
            VehicleInfo[i][vPosX] = floatstr(arrData[2]);
            VehicleInfo[i][vPosY] = floatstr(arrData[3]);
            VehicleInfo[i][vPosZ] = floatstr(arrData[4]);
            VehicleInfo[i][vPosA] = floatstr(arrData[5]);
            VehicleInfo[i][vColor1] = strval(arrData[6]);
            VehicleInfo[i][vColor2] = strval(arrData[7]);
            VehicleInfo[i][vFaction] = strval(arrData[8]);
            VehicleInfo[i][vJob] = strval(arrData[9]);

            if (VehicleInfo[i][vExists] && VehicleInfo[i][vModel] >= 400)
            {
                VehicleInfo[i][vRealID] = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPosX], VehicleInfo[i][vPosY], VehicleInfo[i][vPosZ], VehicleInfo[i][vPosA], VehicleInfo[i][vColor1], VehicleInfo[i][vColor2], -1);
            }
        }
    }
    fclose(file);
    return 1;
}

All the cmds associated with it
pawn Код:
CMD:savecar(playerid, params[])
{
    new factionid, jobid, vehicleid = GetPlayerVehicleID(playerid), string[128];

    if (PlayerInfo[playerid][pAdmin] < 5)
        return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");

    if (!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, COLOR_GREY, "You are not inside any admin vehicle (/veh).");

    if (sscanf(params, "dI(0)", factionid, jobid))
        return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /savecar [factionid] [jobid]");

    for (new i = 0; i < MAX_CUSTOM_VEHICLES; i ++) if (vehicleid == cVeh[i])
    {
        for (new j = 0; j < MAX_DYNAMIC_VEHICLES; j ++) if (!VehicleInfo[j][vExists])
        {
            VehicleInfo[j][vModel] = GetVehicleModel(vehicleid);
            VehicleInfo[j][vColor1] = gVehicleColors[cVeh[i]][0];
            VehicleInfo[j][vColor2] = gVehicleColors[cVeh[i]][1];

            GetVehiclePos(vehicleid, VehicleInfo[j][vPosX], VehicleInfo[j][vPosY], VehicleInfo[j][vPosZ]);
            GetVehicleZAngle(vehicleid, VehicleInfo[j][vPosA]);

            VehicleInfo[j][vFaction] = factionid;
            VehicleInfo[j][vJob] = jobid;
            VehicleInfo[j][vExists] = 1;
            VehicleInfo[i][vRealID] = vehicleid;

            cVeh[i] = 0;
            SaveDynamicVehicles();

            format(string, sizeof(string), "* You have saved this %s (ID: %d)", GetVehicleName(vehicleid), vehicleid);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
            return 1;
        }
    }
    SendClientMessage(playerid, COLOR_GREY, "The limit has been reached, or you aren't inside any admin vehicle.");
    return 1;
}

CMD:deletecar(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid), string[128];

    if (PlayerInfo[playerid][pAdmin] < 5)
        return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");

    if (!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, COLOR_GREY, "You are not inside any vehicle.");

    for (new i = 0; i < MAX_DYNAMIC_VEHICLES; i ++)
    {
        if (VehicleInfo[i][vExists] && VehicleInfo[i][vRealID] == vehicleid)
        {
            format(string, sizeof(string), "* You have destroyed this %s (ID: %d).", GetVehicleName(vehicleid), vehicleid);
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);

            DestroyVehicle(VehicleInfo[i][vRealID]);

            VehicleInfo[i][vExists] = 0;
            VehicleInfo[i][vModel] = 0;

            SaveDynamicVehicles();
            return 1;
        }
    }
    SendClientMessage(playerid, COLOR_GREY, "You are not inside any dynamic vehicle.");
    return 1;
}
Reply
#2

With savecar command you are saving all DynamicVehicles. With this you assign to all vehicles the faction that player enter as param. Do you really want to do this? The savecar cmd should assign faction etc only to vehicle that should by saved i think.
Reply
#3

Quote:
Originally Posted by papedo
Посмотреть сообщение
With savecar command you are saving all DynamicVehicles. With this you assign to all vehicles the faction that player enter as param. Do you really want to do this? The savecar cmd should assign faction etc only to vehicle that should by saved i think.
We want it to save the faction and job id's... Not following what you are saying sir.
Reply
#4

Try this

pawn Код:
CMD:savecar(playerid, params[])
{
    new factionid, jobid, vehicleid = GetPlayerVehicleID(playerid), string[128];

    if (PlayerInfo[playerid][pAdmin] < 5)
        return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");

    if (!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, COLOR_GREY, "You are not inside any admin vehicle (/veh).");

    if (sscanf(params, "dI(0)", factionid, jobid))
        return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /savecar [factionid] [jobid]");

    // Find CUSTOM_VEHICLE ID with vehicleid
    new theCustomID = -1;
    for (new i = 0; i < MAX_CUSTOM_VEHICLES; i ++)
    {
        if (vehicleid == cVeh[i])theCustomID = i;
    }
   
    // I am expecting the CUSTOM_VEHICLES are used for admin vehicle
    if (theCustomID == -1)// Custom ID not found
        return SendClientMessage(playerid, COLOR_GREY, "You are not inside any admin vehicle (/veh).");

    // Find freeID in DYNAMIC VEHICLES array
    new freeDynamicID = -1;
    for (new j = 0; j < MAX_DYNAMIC_VEHICLES; j ++)
    {
        // If slot is used
        if (!VehicleInfo[j][vExists])continue;// Check next ID

        // Slot is not used
        freeDynamicID = j;
        break;
    }
   
    // If slot wasnt found
    if(freeDynamicID == -1)
        return SendClientMessage(playerid, COLOR_GREY, "There is not enought free slots in dynamic vehicles!");

    // Store VEHICLEID data to DYNAMIC array
    VehicleInfo[freeDynamicID][vModel] = GetVehicleModel(vehicleid);
    VehicleInfo[freeDynamicID][vColor1] = gVehicleColors[cVeh[i]][0];
    VehicleInfo[freeDynamicID][vColor2] = gVehicleColors[cVeh[i]][1];

    GetVehiclePos(vehicleid, VehicleInfo[freeDynamicID][vPosX], VehicleInfo[freeDynamicID][vPosY], VehicleInfo[freeDynamicID][vPosZ]);
    GetVehicleZAngle(vehicleid, VehicleInfo[freeDynamicID][vPosA]);

    VehicleInfo[freeDynamicID][vFaction] = factionid;
    VehicleInfo[freeDynamicID][vJob] = jobid;
    VehicleInfo[freeDynamicID][vExists] = 1;
    VehicleInfo[freeDynamicID][vRealID] = vehicleid;

    // Remove from CUSTOM VEHICLES
    cVeh[theCustomID] = 0;
   
    // Save ALL vehicles
    SaveDynamicVehicles();

    format(string, sizeof(string), "* You have saved this %s (ID: %d)", GetVehicleName(vehicleid), vehicleid);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    return 1;
}
Reply
#5

Two errors saying that undefined symbol I, is it suppose to be J or should it have a "new i;"
Reply
#6

Change:
pawn Код:
VehicleInfo[freeDynamicID][vColor1] = gVehicleColors[cVeh[i]][0];
VehicleInfo[freeDynamicID][vColor2] = gVehicleColors[cVeh[i]][1];
To
pawn Код:
VehicleInfo[freeDynamicID][vColor1] = gVehicleColors[theCustomID][0];
VehicleInfo[freeDynamicID][vColor2] = gVehicleColors[theCustomID][1];
Reply
#7

Still doesn't work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)