Vehicle System Help
#1

Issue: No matter what I do, vehicles are not being assigned properly when creating new vehicles, and this causes certain vehicles to spawn bugged. I am trying to have vehicles despawn and respawn when a player connects/disconnects (if they are the owner). So far that works, when a vehicle file is created successfully.

At this point, it's a guess and check game, and I'm getting no where.

Example:

pawn Код:
CMD:vcreate(playerid, params[])
{
    if(pInfo[playerid][pAdmin] >= 3)
    {
        new model, color1, color2, Float:x, Float:y, Float:z, Float:a, target;
        if(sscanf(params, "iiiu", model, color1, color2, target)) return SCM(pid,COLOR_DO, "USAGE:{FFFFFF} /vcreate [model] [color1] [color2] [playerid] (playerid = owner)");
        if(!(400 <= model <= 611)) return SCM(pid,COLOR_GREY, "Invalid Model.");
        if(!(-1 <= color1 <= 255)) return SCM(pid,COLOR_GREY, "Invalid Color. (color1)");
        if(!(-1 <= color2 <= 255)) return SCM(pid,COLOR_GREY, "Invalid Color. (color2)");
        if(!IsPlayerConnected(target)) return SCM(pid,COLOR_GREY, "Invalid Playerid.");
        GetPlayerPos(playerid, x, y, z);
        GetXYInFrontOfPlayer(playerid, x, y, 2);
        GetPlayerFacingAngle(playerid, a);
        for(new i=1; i<MAX_VEHICLES; i++)
        {
            if(!fexist(VPath(i)))
            {
                VID[i] = GetNextVehicleID();
                AddVehicle(model,x,y,z,a+90,color1,color2,-1);
                vInfo[i][vOwner] = GetName(target);
                vInfo[i][vHasKeys] = GetName(target);
                new string[128];
                format(string,sizeof(string), "AdmCmd: {FFFFFF}%s %s has created vehicle %i.", GetAdminLvlName(playerid), GetName(playerid), i);
                SCMA(COLOR_LIGHTGREEN, string);
                break;
            }
        }
    }
    else SCM(pid,COLOR_GREY,ERROR);
    return 1;
}

stock AddVehicle(model,Float:x,Float:y,Float:z,Float:a,color1,color2,respawndelay)
{
    new vehicleid1;
    for(new i=1; i<MAX_VEHICLES; i++)
    {
        if(!fexist(VPath(i)))
        {
            vehicleid1 = i;
            break;
        }
    }
    new INI:file = INI_Open(VPath(vehicleid1));
    INI_SetTag(file, "Vehicle Data");
    INI_WriteInt(file,"Model", model);
    INI_WriteInt(file,"Color1", color1);
    INI_WriteInt(file,"Color2", color2);
    INI_WriteBool(file,"Locked", true);
    INI_WriteBool(file,"Alarm", false);
    INI_WriteInt(file,"Paintjob", 0);
    INI_WriteInt(file,"Fuel", 100);
    INI_WriteFloat(file,"Health", 1000);
    INI_WriteString(file,"Owner", "AngelPine");
    INI_WriteString(file,"HasKeys", "AngelPine");
    INI_WriteFloat(file,"SpawnX", x);
    INI_WriteFloat(file,"SpawnY", y);
    INI_WriteFloat(file,"SpawnZ", z);
    INI_WriteFloat(file,"SpawnA", a);
    INI_WriteFloat(file,"LastX", x);
    INI_WriteFloat(file,"LastY", y);
    INI_WriteFloat(file,"LastZ", z);
    INI_WriteFloat(file,"LastA", a);
    INI_WriteInt(file,"StockPrice", 20000);
    INI_WriteInt(file,"Part1", 0);
    INI_WriteInt(file,"Part2", 0);
    INI_WriteInt(file,"Part3", 0);
    INI_WriteInt(file,"Part4", 0);
    INI_WriteInt(file,"Part5", 0);
    INI_WriteBool(file,"Dead", false);
    INI_WriteInt(file,"Interior", 0);
    INI_WriteBool(file,"Reserve", false);
    INI_WriteInt(file,"PanelDamage", 0);
    INI_WriteInt(file,"DoorDamage", 0);
    INI_WriteInt(file,"LightDamage", 0);
    INI_WriteInt(file,"TireDamage", 0);
    INI_Close(file);
    INI_ParseFile(VPath(vehicleid1),"LoadVehicle", .bExtra = true, .extra = vehicleid1);
    VID[vehicleid1] = GetNextVehicleID();
    AddStaticVehicleEx(vInfo[vehicleid1][vModel],vInfo[vehicleid1][vLastX],vInfo[vehicleid1][vLastY],vInfo[vehicleid1][vLastZ],vInfo[vehicleid1][vLastA],vInfo[vehicleid1][vColor1],vInfo[vehicleid1][vColor2],respawndelay);
    LinkVehicleToInterior(VID[vehicleid1], vInfo[vehicleid1][vInterior]);
    AddVehicleComponent(VID[vehicleid1], vInfo[vehicleid1][vPart1]);
    AddVehicleComponent(VID[vehicleid1], vInfo[vehicleid1][vPart2]);
    AddVehicleComponent(VID[vehicleid1], vInfo[vehicleid1][vPart3]);
    AddVehicleComponent(VID[vehicleid1], vInfo[vehicleid1][vPart4]);
    AddVehicleComponent(VID[vehicleid1], vInfo[vehicleid1][vPart5]);
    UpdateVehicleDamageStatus(VID[vehicleid1], vInfo[vehicleid1][vPanelDamage], vInfo[vehicleid1][vDoorDamage], vInfo[vehicleid1][vLightDamage], vInfo[vehicleid1][vTireDamage]);
    printf("Vehicle %i Created!", vehicleid1);
   
    // Veh Vars
    FuelCount[vehicleid1] = 0;
    return 1;
}
Reply
#2

Well i actually didn't get your point. But i can suggest you is that you can use "playername_numberofvehicle" ... Explain your problem again didnt get you.

Ps: i can see you are trying to create files as per as their id. But as soon as a car is deleted the slot gets free and if a file of that thing exists no matter what you do your search will be for the current vehicle id if you are doing it as per as vehicle id
Reply
#3

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
Well i actually didn't get your point. But i can suggest you is that you can use "playername_numberofvehicle" ... Explain your problem again didnt get you.

Ps: i can see you are trying to create files as per as their id. But as soon as a car is deleted the slot gets free and if a file of that thing exists no matter what you do your search will be for the current vehicle id if you are doing it as per as vehicle id
I'm attempting to create files based on if a file doesnt exist. I'll keep looking at it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)