Dynamic vehicle creation bugged.
#1

Issue: When new vehicle is created, it is not assigned properly to its data. When a player enters the bugged vehicle, their client crashes. (possibly unrelated)

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=0; 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);
                if(Debugging[playerid] == true)
                {
                    VehInfo[i] = CreatePlayer3DTextLabel(playerid,"",COLOR_DO, x, y, z,150.0,-1, i, 1);
                }
                break;
            }
        }
    }
    else SCM(pid,COLOR_GREY,ERROR);
    return 1;
}

stock AddVehicle(model,Float:px,Float:py,Float:pz,Float:pa,color1,color2,respawndelay)
{
    #pragma unused respawndelay
    new v;
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        if(!fexist(VPath(i)))
        {
            v = i;
            break;
        }
    }
    new INI:file = INI_Open(VPath(v));
    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", 3); // no paintjob
    INI_WriteInt(file,"Fuel", 100);
    INI_WriteFloat(file,"Health", 1000);
    INI_WriteString(file,"Owner", "AngelPine");
    INI_WriteString(file,"HasKeys", "AngelPine");
    INI_WriteFloat(file,"SpawnX", px);
    INI_WriteFloat(file,"SpawnY", py);
    INI_WriteFloat(file,"SpawnZ", pz);
    INI_WriteFloat(file,"SpawnA", pa);
    INI_WriteFloat(file,"LastX", px);
    INI_WriteFloat(file,"LastY", py);
    INI_WriteFloat(file,"LastZ", pz);
    INI_WriteFloat(file,"LastA", pa);
    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);
    ResetVehicle(v);
    return 1;
}

stock ResetVehicle(vehicleid)
{
    if(IsValidVehicle(VID[vehicleid]))
    {
        DestroyVehicle(VID[vehicleid]);
        VID[vehicleid] = 0;
    }
    VID[vehicleid] = GetNextVehicleID();
    INI_ParseFile(VPath(vehicleid),"LoadVehicle", .bExtra = true, .extra = vehicleid);
    AddStaticVehicleEx(vInfo[vehicleid][vModel],vInfo[vehicleid][vSpawnX],vInfo[vehicleid][vSpawnY],vInfo[vehicleid][vSpawnZ],vInfo[vehicleid][vSpawnA],vInfo[vehicleid][vColor1],vInfo[vehicleid][vColor2],-1);
    ChangeVehiclePaintjob(VID[vehicleid], vInfo[vehicleid][vPaintjob]);
    LinkVehicleToInterior(VID[vehicleid], vInfo[vehicleid][vInterior]);
    AddVehicleComponent(VID[vehicleid], vInfo[vehicleid][vPart1]);
    AddVehicleComponent(VID[vehicleid], vInfo[vehicleid][vPart2]);
    AddVehicleComponent(VID[vehicleid], vInfo[vehicleid][vPart3]);
    AddVehicleComponent(VID[vehicleid], vInfo[vehicleid][vPart4]);
    AddVehicleComponent(VID[vehicleid], vInfo[vehicleid][vPart5]);
    UpdateVehicleDamageStatus(VID[vehicleid], vInfo[vehicleid][vPanelDamage], vInfo[vehicleid][vDoorDamage], vInfo[vehicleid][vLightDamage], vInfo[vehicleid][vTireDamage]);
    return 1;
}

stock GetNextVehicleID()
{
    for(new i=1; i<MAX_VEHICLES;i++)
    {
        if(!IsValidVehicle(i)) return i;
    }
    return 1;
}
Reply
#2

I think you can't create label with empty string ""
Reply
#3

Quote:

their client crashes.

That's because of the textlabel.

Always read the important notes on the wiki.
Reply
#4

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
That's because of the textlabel.

Always read the important notes on the wiki.
That's not what is causing the issue, at least not that specific line. And in no other part do I use "" in 3Dtextlabels.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)