SA-MP Forums Archive
Help me please - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help me please (/showthread.php?tid=663342)



Help me please - akib - 28.01.2019

Why OnDealerCarsLoad not loading all datas available in database?

OnDealerCarsLoad:
PHP код:
public OnDealerCarsLoad(){
    new 
num_fields,num_rows,m[512];
    
cache_get_data(num_rows,num_fields,dbhandle);
    if(!
num_rows)return 1;
    for(new 
i=0; i<num_rows; i++)
    {
        new 
id=GetFreeDSVehiceID();
        
DSVehicle[id][vehicle_sqlid]=cache_get_field_content_int(i, "id", dbhandle);
        
DSVehicle[id][vehicle_pos][0]=cache_get_field_content_float(i, "x", dbhandle);
        
DSVehicle[id][vehicle_pos][1]=cache_get_field_content_float(i, "y", dbhandle);
        
DSVehicle[id][vehicle_pos][2]=cache_get_field_content_float(i, "z", dbhandle);
        
DSVehicle[id][vehicle_model]=cache_get_field_content_int(i, "model", dbhandle);
        
DSVehicle[id][vehicle_price]=cache_get_field_content_int(i, "price", dbhandle);
        
DSVehicle[id][vehicle_dealer]=cache_get_field_content_int(i, "dealer", dbhandle);
        
format(m, sizeof(m), "This Vehicle Is For Sell!\nVehicle Name : %s\nPrice : $%i\nDealership : %s", VehicleNames[DSVehicle[id][vehicle_model]-400],DSVehicle[id][vehicle_price],GetDealershipName(DSVehicle[id][vehicle_dealer]));
        
DSVehicle[id][vehicle_text]=CreateDynamic3DTextLabel(m ,COLOR_ORANGE, DSVehicle[id][vehicle_pos][0], DSVehicle[id][vehicle_pos][1], DSVehicle[id][vehicle_pos][2],30.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0);
        
DSVehicle[id][vehicle_veh] = CreateVehicle(DSVehicle[id][vehicle_model], DSVehicle[id][vehicle_pos][0], DSVehicle[id][vehicle_pos][1], DSVehicle[id][vehicle_pos][2], DSVehicle[id][vehicle_angle], 0, 0, -1, 0);
    }
return 
1;
} 
It's loading only one data from MySql and it's only first data(1)

MySQL Table



Re: Help me please - akib - 29.01.2019

Quote:
Originally Posted by ******
Посмотреть сообщение
Can't say without seeing your query.
GetFreeDSVehiceID
PHP код:
GetFreeDSVehiceID()
{
    for(new 
i=1; i<MAX_DSVEHICLES; i++)
    {
        if(
DSVehicle[i][vehicle_sqlid]==0)return i;
    }
    return 
0;
} 
My query
PHP код:
format(query, sizeof(query), "SELECT * FROM dealercars");
    
mysql_function_query(dbhandle, query, true, "OnDealerCarsLoad", ""); 



Re: Help me please - akib - 29.01.2019

so using debugger(print) i found that the bug is on creating label text

PHP код:
format(m, sizeof(m), "This Vehicle Is For Sell!\nVehicle Name : %s\nPrice : $%i\nDealership : %s", VehicleNames[DSVehicle[id][vehicle_model]-400],DSVehicle[id][vehicle_price],GetDealershipName(DSVehicle[id][vehicle_dealer]));
        
DSVehicle[id][vehicle_text]=CreateDynamic3DTextLabel(m ,COLOR_ORANGE, DSVehicle[id][vehicle_pos][0], DSVehicle[id][vehicle_pos][1], DSVehicle[id][vehicle_pos][2],30.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 7.0); 
GetDealershipName
PHP код:
GetDealershipName(sqlid){
    new 
query[128], name[64];
    
mysql_format(dbhandle, query, sizeof(query), "SELECT name FROM `dealerships` WHERE ID = '%d'", sqlid);
    new 
Cache:result = mysql_query(dbhandle, query);
    
cache_get_field_content(0, "name", name, dbhandle, 64);  //or what ever your players name saves as
    
cache_delete(result);
    return 
name;
} 
tried with CreateDynamic3DTextLabel and Create3DTextLabel, it's stopping the code, only printing the first dealer info


Re: Help me please - Calisthenics - 29.01.2019

If DSVehicle[id][vehicle_model] is not between 400 and 611, it will try to access negative index when subtracting 400 from it in `VehicleNames` array.

Install crashdetect plugin with -d3 flag, it will make it a lot easier to catch run time errors.


Re: Help me please - fiki574 - 29.01.2019

I forgot what's the proper procedure to retrieve vehicle names from model IDs, but try this.

PHP код:
format(m, sizeof(m), "This Vehicle Is For Sell!\nVehicle Name : %s\nPrice : $%i\nDealership : %s", VehicleNames[DSVehicle[id][vehicle_model - 400]],DSVehicle[id][vehicle_price],GetDealershipName(DSVehicle[id][vehicle_dealer]));