Help me please
#1

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=0i<num_rowsi++)
    {
        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(msizeof(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(,COLOR_ORANGEDSVehicle[id][vehicle_pos][0], DSVehicle[id][vehicle_pos][1], DSVehicle[id][vehicle_pos][2],30.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -17.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], 00, -10);
    }
return 
1;

It's loading only one data from MySql and it's only first data(1)

MySQL Table
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Can't say without seeing your query.
GetFreeDSVehiceID
PHP код:
GetFreeDSVehiceID()
{
    for(new 
i=1i<MAX_DSVEHICLESi++)
    {
        if(
DSVehicle[i][vehicle_sqlid]==0)return i;
    }
    return 
0;

My query
PHP код:
format(querysizeof(query), "SELECT * FROM dealercars");
    
mysql_function_query(dbhandlequerytrue"OnDealerCarsLoad"""); 
Reply
#3

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

PHP код:
format(msizeof(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(,COLOR_ORANGEDSVehicle[id][vehicle_pos][0], DSVehicle[id][vehicle_pos][1], DSVehicle[id][vehicle_pos][2],30.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -17.0); 
GetDealershipName
PHP код:
GetDealershipName(sqlid){
    new 
query[128], name[64];
    
mysql_format(dbhandlequerysizeof(query), "SELECT name FROM `dealerships` WHERE ID = '%d'"sqlid);
    new 
Cache:result mysql_query(dbhandlequery);
    
cache_get_field_content(0"name"namedbhandle64);  //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
Reply
#4

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.
Reply
#5

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

PHP код:
format(msizeof(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])); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)