Little Help, Please - Dini or something else.
#1

Hello everyone,

So I'm making car system (not really good one). So I made something like this:
Quote:

stock CreateVehicleEx(modelid, Float, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[20])
{
new carid = GetFreeVehicleSlot();
CarInfo[carid][model] = modelid;
CarInfo[carid][xspawn] = x;
CarInfo[carid][yspawn] = y;
CarInfo[carid][zspawn] = z;
CarInfo[carid][anglespawn] = angle;
CarInfo[carid][col1] = color1;
CarInfo[carid][col2] = color2;
CarInfo[carid][respawn] = respawntime;
CarInfo[carid][owner] = ownername;
validcar[carid] = true;
CreateVehicle(modelid, x, y, z, angle, color1, color2, respawntime);
return carid;
}

And then when I create new vehicle like this:
Quote:

CreateVehicleEx(dini_Int(filename, "Model"), dini_Float(filename, "XSpawn"), dini_Float(filename, "YSpawn"), dini_Float(filename, "ZSpawn"), dini_Float(filename, "Angle"), dini_Int(filename, "COL1"), dini_Int(filename, "COL2"),dini_Int(filename, "Respawn"), dini_Get(filename, "Owner") );

Compieler gives me an error like this:

Quote:

blablablablabla......\gamemodes\car.pwn(412) : error 047: array sizes do not match, or destination array is too small

I'm kinda dumb at scripting (and english) so can anyone say what's wrong here?
Reply
#2

The destination size for strings with dini is 255, so you'll need to change the owner name variable size. As well as using strcat to extract 24 characters from your 'ownername' string, to avoid the same error. The code I've changed below should work.

pawn Код:
stock CreateVehicleEx(modelid, Float, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[])
{
        new carid = GetFreeVehicleSlot();
    CarInfo[carid][model] = modelid;
    CarInfo[carid][xspawn] = x;
    CarInfo[carid][yspawn] = y;
    CarInfo[carid][zspawn] = z;
    CarInfo[carid][anglespawn] = angle;
    CarInfo[carid][col1] = color1;
    CarInfo[carid][col2] = color2;
    CarInfo[carid][respawn] = respawntime;
    //CarInfo[carid][owner] = ownername;
    strcat(CarInfo[carid][owner], ownername, MAX_PLAYER_NAME);
    validcar[carid] = true;
    CreateVehicle(modelid, x, y, z, angle, color1, color2, respawntime);
    return carid;
}
Reply
#3

NEW PROBLEM (RESPAWN):
I made somethig like this:
pawn Код:
stock LoadAllVehicles()
{
    new fname[36];
    new index = 1;
    format(fname, sizeof(fname), "/vehicles/%d.ini", index);
    while(fexist(fname))
    {
        LoadVehicle(fname);
        index ++;
        format(fname, sizeof(fname), "/vehicles/%d.ini", index);
    }
}

stock DestroyAllVehicles()
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        DestroyVehicle(i);
    }
stock SaveAllVehicles()
{
    new saveindex = 1;
    new fname[36];
    for(new i = 1; i < MAX_VEHICLES; i ++)
    {
        if(validcar[i])
        {
            format(fname, sizeof(fname), "/vehicles/%d.ini", saveindex);
            SaveVehicle(i, fname);
            saveindex ++;
        }
    }
}
And I made cmd like this:
pawn Код:
if (strcmp("/respawnvehicles", cmdtext, true, 10) == 0)
    {
        SaveAllVehicles();
        DestroyAllVehicles();
        LoadAllVehicles();
        return 1;
    }
So the problem is that, when I write the cmd In-Game all cars gets doubled (Before respawn there was 1 car and after respawn there is 2 cars at the same position).
Any ideas how to fix it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)