Vehicules spawning (mysql)
#1

Hey guys look at this

As you can see, there are some NRJ-500 spawning in the street; yes one time i've create them but




As you can see here, there aren't anymore in the database ! What can i do ?


Reply
#2

Show the loading function. Your loop is badly coded because it can't handle the gap between id 13 and 20 in your database and thus spawning 6 additional vehicles.
Reply
#3

check your CreateVehicle code, post it here
Reply
#4

But the vehicles which were between id 13 and 20 were this nrj-500 and now they are spawn there..

creating vehicle code:
pawn Код:
if(strcmp(subcmd, "creer", true) == 0)
        {
            if(!pack_isAdmin(playerid, 1))
                {SendClientMessage(playerid, COLOR_ADMIN, noAcces); return 1;}
            tmp = strtok(cmdtext, idx);
            if (!strlen(tmp))
                {SendClientMessage(playerid, COLOR_USAGE, "{8BD51B}[Action]{218CC1} /v creer <modelId>"); return 1;}
            new modelId = strval(tmp);
            if (modelId<400 || modelId>611)
                {SendClientMessage(playerid, COLOR_ADMIN, "[Admin] modelId doit кtre entre 400 et 611"); return 1;}
            // Position
            new Float:x, Float:y, Float:z, query[MAX_STRING];
            GetPlayerPos(playerid, x, y, z);
            // Id
            format(query, sizeof(query), "SELECT COUNT(*) FROM vehicules");
            mysql_query(query);
            ////SQLLog(query);
            mysql_store_result();
            mysql_fetch_row(result);
            new newCarId = strval(result) + 1;
            mysql_free_result();
            if (newCarId>=MAX_CAR)
                {SendClientMessage(playerid, COLOR_ADMIN, "[Admin] Maximum de voiture atteint."); return 1;}
            new idname = modelId - 400;
            // Insertion en db
            format(query, sizeof(query), "INSERT INTO vehicules SET id=%d, model=%d, x=%f, y=%f, z=%f, description='%s'", newCarId, modelId, x, y, z, VehiclesName[idname]);
            debug_sendMsg(playerid, query);
            mysql_query(query);
            ////SQLLog(query);
            // crйation ingame
            CarInfo[newCarId][cModel] = modelId;
            CarInfo[newCarId][cLocationx] = x;
            CarInfo[newCarId][cLocationy] = y;
            CarInfo[newCarId][cLocationz] = z;
            CarInfo[newCarId][cAngle] = 0;
            CarInfo[newCarId][cColorOne] = -1;
            CarInfo[newCarId][cColorTwo] = -1;
            memcpy(CarInfo[newCarId][cOwner], NOMDEFAULT, 0, MAX_PLAYER_NAME*4, MAX_PLAYER_NAME*4);
            memcpy(CarInfo[newCarId][cDescription], VehiclesName[idname], 0, 8*4, 8*4);
            CarInfo[newCarId][cValue] = 0;
            CarInfo[newCarId][cWindow] = 0;
            CarInfo[newCarId][cRegistration] = 0;
            CarInfo[newCarId][cOwned] = 0;
            CarInfo[newCarId][cLock] = 0;
            CarInfo[newCarId][cRespawnTime] = 3600;
            CarInfo[newCarId][cStatus] = 1;
            CarInfo[newCarId][cType] = 0;
            CarInfo[newCarId][cFamily] = 255;
            CarInfo[newCarId][cFaction] = 255;
            CarInfo[newCarId][cHouse] = 25555;
            CarInfo[newCarId][cArme1] = 0;
            CarInfo[newCarId][cArme2] = 0;
            CarInfo[newCarId][cArme3] = 0;
            CarInfo[newCarId][cArme4] = 0;
            CarInfo[newCarId][cArme5] = 0;
            CarInfo[newCarId][cAmo1] = 0;
            CarInfo[newCarId][cAmo2] = 0;
            CarInfo[newCarId][cAmo3] = 0;
            CarInfo[newCarId][cAmo4] = 0;
            CarInfo[newCarId][cAmo5] = 0;
            CarInfo[newCarId][cDrugs] = 0;
            CarInfo[newCarId][cHero] = 0;
            CarInfo[newCarId][cMatos] = 0;
            CarInfo[newCarId][cJob] = 0;
            CarInfo[newCarId][tPaintJob] = -1;
            CarInfo[newCarId][tExhausts] = -1;
            CarInfo[newCarId][tFrontBumper] = -1;
            CarInfo[newCarId][tRearBumper] = -1;
            CarInfo[newCarId][tRoof] = -1;
            CarInfo[newCarId][tSpoilers] = -1;
            CarInfo[newCarId][tSideBumper] = -1;
            CarInfo[newCarId][tWheels] = -1;
            CarInfo[newCarId][tHydraulics] = -1;
            CarInfo[newCarId][tNeon] = -1;
            CarInfo[newCarId][tNitro] = -1;
            CarInfo[newCarId][tSideBumper2] = -1;
            memcpy(CarInfo[newCarId][cPlaque], "-1", 0,8*4,8*4);

            CreateVehicle(modelId, x, y, z, 0, -1, -1, -1);
            totalcars++;

            SendClientMessage(playerid, COLOR_ADMIN, "[Admin] Vehicule crйй.");
            return 1;
        }
Reply
#5

I asked for the LOADING function, not the saving function. You might want to use auto_increment on your id field as well.
Reply
#6

sorry, here is the code of vehicles loading function:

pawn Код:
public LoadVehiclesFromSQL()
{
    new sql[64], fields[58][MAX_PLAYER_NAME], row[320];
    new Float:park_x, Float:park_y, Float:park_z, Float:park_a;

    format(sql, sizeof(sql), "SELECT COUNT(*) FROM vehicules");
    mysql_query(sql);
    mysql_store_result();
    mysql_fetch_row(row);
    totalcars = strval(row);
    mysql_free_result();
    for (new i=1; i<=totalcars; i++)
    {
        format(sql, sizeof(sql), "SELECT * FROM vehicules WHERE id=%d", i);
        mysql_query(sql);
        mysql_store_result();
        mysql_fetch_row(row);
        split(row, fields, '|');
        CarInfo[i][cModel] = strval(fields[1]);
        CarInfo[i][cLocationx] = floatstr(fields[2]);
        CarInfo[i][cLocationy] = floatstr(fields[3]);
        CarInfo[i][cLocationz] = floatstr(fields[4]);
        CarInfo[i][cAngle]     = floatstr(fields[5]);
        park_x = floatstr(fields[6]);
        park_y = floatstr(fields[7]);
        park_z = floatstr(fields[8]);
        park_a = floatstr(fields[9]);
        if (park_x != 0 && park_y != 0 && park_z != 0)
        {
            CarInfo[i][cLocationx] = park_x;
            CarInfo[i][cLocationy] = park_y;
            CarInfo[i][cLocationz] = park_z;
            CarInfo[i][cAngle] = park_a;
        }
        CarInfo[i][cColorOne] = strval(fields[10]);
        CarInfo[i][cColorTwo] = strval(fields[11]);
        CarInfo[i][cOwned] = strval(fields[12]);
        memcpy(CarInfo[i][cOwner], fields[13], 0, MAX_PLAYER_NAME*4, MAX_PLAYER_NAME*4);
        memcpy(CarInfo[i][cOldOwner], fields[14], 0, MAX_PLAYER_NAME*4, MAX_PLAYER_NAME*4);
        CarInfo[i][cFaction] = strval(fields[15]);
        CarInfo[i][cFamily] =  strval(fields[16]);
        CarInfo[i][cType] = strval(fields[17]);
        memcpy(CarInfo[i][cDescription], fields[18], 0, 8*4, 8*4);
        CarInfo[i][cValue] = strval(fields[19]);
        CarInfo[i][cStatus] = strval(fields[20]);
        if(CarInfo[i][cStatus]==3) // Cela ne sauvegarde pas la position du garage, donc, on remet а defaut
        {CarInfo[i][cStatus]=1;}
        CarInfo[i][cRespawnTime] = 3600;
        CarInfo[i][cWindow] = 0;
        CarInfo[i][cLock] = strval(fields[21]);
        CarInfo[i][cHouse] = strval(fields[23]);
        CarInfo[i][cArme1] = strval(fields[24]);
        CarInfo[i][cArme2] = strval(fields[25]);
        CarInfo[i][cArme3] = strval(fields[26]);
        CarInfo[i][cArme4] = strval(fields[27]);
        CarInfo[i][cArme5] = strval(fields[28]);
        CarInfo[i][cAmo1] = strval(fields[29]);
        CarInfo[i][cAmo2] = strval(fields[30]);
        CarInfo[i][cAmo3] = strval(fields[31]);
        CarInfo[i][cAmo4] = strval(fields[32]);
        CarInfo[i][cAmo5] = strval(fields[33]);
        CarInfo[i][cDrugs] = strval(fields[34]);
        CarInfo[i][cHero] = strval(fields[35]);
        CarInfo[i][cMatos] = strval(fields[36]);
        CarInfo[i][cJob] = strval(fields[37]);
        CarInfo[i][tPaintJob] = strval(fields[38]);
        CarInfo[i][tExhausts] = strval(fields[39]);
        CarInfo[i][tFrontBumper] = strval(fields[40]);
        CarInfo[i][tRearBumper] = strval(fields[41]);
        CarInfo[i][tRoof] = strval(fields[42]);
        CarInfo[i][tSpoilers] = strval(fields[43]);
        CarInfo[i][tSideBumper] = strval(fields[44]);
        CarInfo[i][tWheels] = strval(fields[45]);
        CarInfo[i][tHydraulics] = strval(fields[46]);
        CarInfo[i][tNitro] = strval(fields[47]);
        CarInfo[i][tSideBumper2] = strval(fields[48]);
        CarInfo[i][tNeon] = strval(fields[49]);
        memcpy(CarInfo[i][cPlaque], fields[50], 0,8*4,8*4);
        memcpy(CarInfo[i][cFaussePlaque], fields[51], 0,8*4,8*4);
        CarInfo[i][cKilometre] = strval(fields[52]);
        CarInfo[i][cMetre] = strval(fields[53]);
        CarInfo[i][cVidange] = strval(fields[54]);
        CarInfo[i][cDistri] = strval(fields[55]);
        //CarInfo[i][cLimiteur] = strval(fields[57]);
        CarInfo[i][cClefVol] = strval(fields[56]);
        CarInfo[i][cClefMise] = strval(fields[57]);
        mysql_free_result();

        if (carsreloaded==0)
        {
            AddStaticVehicleEx(CarInfo[i][cModel], CarInfo[i][cLocationx], CarInfo[i][cLocationy], CarInfo[i][cLocationz], CarInfo[i][cAngle], CarInfo[i][cColorOne], CarInfo[i][cColorTwo], -1);
            tuning_resetFacture(i);
            tuning_applyDbTuning(i);
            if(CarInfo[i][cVin]==0)
            {
                new newVin[14];
                vin_create(newVin);
                memcpy(CarInfo[i][cVin], newVin, 0, 8*14,8*14);
                SaveVehiclesFromSQL(i,true);
            }
        }
        else
            {car_respawn(i,false);}
        CreatePlate(i,1);
        tuning_applyDbTuning(i);
        if(CarInfo[i][cType]==CARTYPE_RENTABLE)
        {SetVehicleNumberPlate(i, "{017FFD}Location");}
        if(CarInfo[i][cFaction]==FACT_MECA)
        {SetVehicleNumberPlate(i, "{A5F701}Racer'Z");}
        if(CarInfo[i][cVin]==0)
        {
            new newVin[14];
            vin_create(newVin);
            memcpy(CarInfo[i][cVin], newVin, 0, 8*14,8*14);
            SaveVehiclesFromSQL(i,true);
        }
    }
    carsreloaded++;
}
Reply
#7

bump
Reply
#8

nobody ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)