'EasyData' (MySQL) Problem
#8

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
Alright. I'll keep your post in bookmark. Thanks.
I seem barely but.. I'm trying to do my best. x)
This code doesn't work.
PHP код:
CMD:garer(playerid)
{
    if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playerid_false);
    new 
vehicleid GetPlayerVehicleID(playerid),
        
Float:x,
        
Float:y,
        
Float:z;
    if(
vehicleid == INVALID_VEHICLE_ID) return ErrorMsg(playerid"Vous devez кtre dans un vйhicule.");
    
GetVehiclePos(vehicleidxyz);
    
DB::Fetch("Vehicle"___"`ID` = '%d'"vehicleid);
    if (
fetch_rows_count() > 0)
    {
        
AdminMessage(playerid"Changement des stats du vйhicule ID: %i."vehicleid);
        
DB::Update("ID"vStats[vehicleid][vSQLIB], 3,
                    
"x"FLOATx,
                    
"y"FLOATy,
                    
"z"FLOATz);
    }
    else
    {
        
vStats[vehicleid][vSQLIB] = fetch_row_id();
        
DB::CreateRow("Vehicle",
            
"ID"INTEGERvStats[vehicleid][vSQLIB],
             
"Model"INTEGERGetVehicleModel(vehicleid),
             
"VehicleID"INTEGERvehicleid);
        
AdminMessage(playerid"Vйhicule ID:%i en cours de crйation ..."vehicleid);
        
AdminMessage(playerid"Enregistrement des donnйes ...");
        
vStats[vehicleid][vSQLIB] = fetch_row_id();
         
vStats[vehicleid][vID] = vehicleid;
         
vStats[vehicleid][vX] = x;
         
vStats[vehicleid][vY] = y;
         
vStats[vehicleid][vZ] = z;
         
vStats[vehicleid][vColor1] = random(150);
         
vStats[vehicleid][vColor2] = random(150);
         
vStats[vehicleid][vHealth] = 1500.0;
         
vStats[vehicleid][vModel] = GetVehicleModel(vehicleid);
         
vStats[vehicleid][vRespawn] = 1800;
         
format(vStats[vehicleid][vPlate], 10GetARandomPlate());
        
AdminMessage(playerid"Donnйes enregistrйes. Attributions des nouvelles donйes au vйhicule.");
         
ChangeVehicleColor(vehicleidvStats[vehicleid][vColor1], vStats[vehicleid][vColor2]);
         
RepairVehicle(vehicleid);
         
SetVehicleHealth(vehicleidvStats[vehicleid][vHealth]);
         
SaveVehicleStats(vehicleid);
        
AdminMessage(playerid"Attributions terminйes.");
    }
    
fetcher_close();
    return 
1;

If you need english translate, say it. Sorry. '-'
Since SAMP has a limit on vehicles, you cannot use vehicle ids as array's indexes as long as you don't keep the vehicle when the owner disconnects.

Anyways, here is how you should detect the ID:
PHP код:
GetVehicleArrayID(vehicleid)
{
    for (new 
iMAX_VEHICLESi++)
    {
        if (
vStats[i][vID] == vehiclid)
            return 
i;
    }
    return -
1;

So you have to use this function to get a vehicle's index in an array every time you want to update the data.

PHP код:
CMD:garer(playerid)
{
    if(
pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playerid_false);
    new 
vehicleid GetPlayerVehicleID(playerid);
    if(
vehicleid == INVALID_VEHICLE_ID) return ErrorMsg(playerid"Vous devez кtre dans un vйhicule.");
    new 
FloatxFloatyFloatz;
    
GetVehiclePos(vehicleidxyz);
    new 
idx GetVehicleArrayID(vehicleid);
    if (
idx != -1)
    {
        
AdminMessage(playerid"Changement des stats du vйhicule ID: %i."vehicleid);
        
DB::Update("Vehicle"vStats[idx][vSQLIB], 1,
                    
"x"FLOATx,
                    
"y"FLOATy,
                    
"z"FLOATz);
        return 
1;
    }
    
    for (new 
iMAX_VEHICLESi++)
    {
        if (
vStats[vehicleid][vSQLIB] == 0)
        {
            
idx i;
            break;
        }
    }
    if (
idx == -1)
    {
        
// for some reason the array isn't empty
        // make sure you set the "vSQLIB" to 0 when the owner disconnects or vehicle is destroyed
        
return 1;
    }
    
AdminMessage(playerid"Vйhicule ID:%i en cours de crйation ..."vehicleid);
    
AdminMessage(playerid"Enregistrement des donnйes ...");
    
vStats[idx][vID] = vehicleid;
    
vStats[idx][vX] = x;
    
vStats[idx][vY] = y;
    
vStats[idx][vZ] = z;
    
vStats[idx][vColor1] = random(150);
    
vStats[idx][vColor2] = random(150);
    
vStats[idx][vHealth] = 1500.0;
    
vStats[idx][vModel] = GetVehicleModel(vehicleid);
    
vStats[idx][vRespawn] = 1800;
    
format(vStats[idx][vPlate], 10GetARandomPlate());
    
DB::CreateRow("Vehicle",
        
"x"FLOATvStats[idx][vX],
        
"y"FLOATvStats[idx][vY],
        
"z"FLOATvStats[idx][vZ],
        
"Angle"FLOAT90.0,
        
"color1"INTEGERvStats[idx][vColor1],
        
"color2"INTEGERvStats[idx][vColor2],
        
"Health"FLOATvStats[idx][vHealth],
        
"Model"INTEGERvStats[idx][vModel],
        
"Plate"STRINGvStats[idx][vPlate]
    );
    
DB::Fetch("Vehicle"1__"`x` = %f, `y` = %f, `z` = %f"xyz);
    
vStats[idx][vSQLIB] = fetch_row_id();
    
fetcher_close();
    
AdminMessage(playerid"Donnйes enregistrйes. Attributions des nouvelles donйes au vйhicule.");
    
ChangeVehicleColor(vehicleidvStats[vehicleid][vColor1], vStats[vehicleid][vColor2]);
    
RepairVehicle(vehicleid);
    
SetVehicleHealth(vehicleidvStats[vehicleid][vHealth]);
    
SaveVehicleStats(vehicleid);
    
AdminMessage(playerid"Attributions terminйes.");
    return 
1;

Reply


Messages In This Thread
'EasyData' (MySQL) Problem - by Dayrion - 15.09.2016, 21:01
Re: 'EasyData' (MySQL) Problem - by Dayrion - 16.09.2016, 14:10
Re: 'EasyData' (MySQL) Problem - by Konstantinos - 16.09.2016, 14:17
Re: 'EasyData' (MySQL) Problem - by Gammix - 16.09.2016, 14:29
Re: 'EasyData' (MySQL) Problem - by Dayrion - 16.09.2016, 15:16
Re: 'EasyData' (MySQL) Problem - by Gammix - 16.09.2016, 15:41
Re: 'EasyData' (MySQL) Problem - by Dayrion - 16.09.2016, 16:25
Re: 'EasyData' (MySQL) Problem - by Gammix - 16.09.2016, 21:32
Re: 'EasyData' (MySQL) Problem - by Dayrion - 17.09.2016, 09:37

Forum Jump:


Users browsing this thread: 3 Guest(s)