Vehicle Problem
#8

Quote:
Originally Posted by ikey07
Посмотреть сообщение
Put vInfo[vehicleid][VehicleVar] = CreateVehicle(... line under mysql_get_field("Color2", tmp); vInfo[vehicleid][vColor2] = strval(tmp); and remove stock CreateNewVehicle(vehicleid) at all, including at OnGamemodeInit

mysql_query_callback function was designed to deal with rest of the code in your callback, which in your case is that LoadVehicle
Quote:
Originally Posted by jlalt
Посмотреть сообщение
Try this:
PHP код:
//==============================================================================
//--->>> Dynamic Car System
//==============================================================================
#include <a_samp>
#include <YSI\y_hooks>
//==============================================================================
//--->>> Config
//==============================================================================
#define MAX_SPAWN_VEHICLES          300
#define PLATES                      "SA-ONLINE"
//==============================================================================
//==============================================================================
//--->>> Forward
//==============================================================================
forward LoadVehicle(query[], vehicleidconnectionHandle);
//==============================================================================
//--->>> Variables
//==============================================================================
enum VehicleEnum
{
    
vID,
    
Float:vPosX,
    
Float:vPosY,
    
Float:vPosZ,
    
Float:vAngle,
    
vColor1,
    
vColor2,
    
VehicleVar
};
new 
vInfo[MAX_SPAWN_VEHICLES][VehicleEnum];
//==============================================================================
//==============================================================================
//--->>> Publics
//==============================================================================
public LoadVehicle(query[], vehicleidconnectionHandle)
{
    
mysql_store_result();
    if(
mysql_num_rows())
    {
        new 
tmp[156];
        while(
mysql_retrieve_row())
        {
               
mysql_get_field("svID"tmp); vehicleid strval(tmp);
            
mysql_get_field("VehicleID"vInfo[vehicleid][vID]);
            
mysql_get_field("PosX"tmp); vInfo[vehicleid][vPosX] = floatstr(tmp);
            
mysql_get_field("PosY"tmp); vInfo[vehicleid][vPosY] = floatstr(tmp);
            
mysql_get_field("PosZ"tmp); vInfo[vehicleid][vPosZ] = floatstr(tmp);
            
mysql_get_field("Angle"tmp); vInfo[vehicleid][vAngle] = floatstr(tmp);
            
mysql_get_field("Color1"tmp); vInfo[vehicleid][vColor1] = strval(tmp);
            
mysql_get_field("Color2"tmp); vInfo[vehicleid][vColor2] = strval(tmp);
        }
    }
    
mysql_free_result();
    for(new 
0MAX_SPAWN_VEHICLESi++)
    {
        
CreateNewVehicle(i);
    }
    return 
1;
}
//==============================================================================
//==============================================================================
//--->>> Stocks
//==============================================================================
stock SaveVehicle(vehicleid)
{
    new 
Query[512];
    
format(Querysizeof(Query), "UPDATE `Vehicles` SET\
                                `VehicleID` = %d,\
                                `PosX` = %d\
                                `PosY` = %f,\
                                `PosZ` = %f,\
                                `Angle` = %f, \
                                `Color1` = %d, \
                                `Color2` = %d \
                                WHERE svID = %d"
,
                                
vInfo[vehicleid][vID],
                                
vInfo[vehicleid][vPosX],
                                
vInfo[vehicleid][vPosY],
                                
vInfo[vehicleid][vPosZ],
                                
vInfo[vehicleid][vAngle],
                                
vInfo[vehicleid][vColor1],
                                
vInfo[vehicleid][vColor2],
                                
vehicleid);
    return 
1;
}
stock CreateNewVehicle(vehicleid)
{
    
vInfo[vehicleid][VehicleVar] = CreateVehicle(vInfo[vehicleid][vID], vInfo[vehicleid][vPosX], vInfo[vehicleid][vPosY], vInfo[vehicleid][vPosZ], vInfo[vehicleid][vAngle], vInfo[vehicleid][vColor1], vInfo[vehicleid][vColor2], 120);
    
printf("Vehicle id: %d, Model: %d, Pos X: %f, Pos Y %f, Pos Z: %f, Angle: %f, color1: %d, color2: %d",vInfo[vehicleid][VehicleVar],vInfo[vehicleid][vID], vInfo[vehicleid][vPosX], vInfo[vehicleid][vPosY], vInfo[vehicleid][vPosZ], vInfo[vehicleid][vAngle], vInfo[vehicleid][vColor1], vInfo[vehicleid][vColor2]);
    
//SetVehicleNumberPlate(vInfo[vehicleid][VehicleVar], ""#PLATES"");
    
return 1;
}
//==============================================================================
//==============================================================================
//--->>> Hooks
//==============================================================================
hook OnGameModeInit()
{
    
mysql_query_callback(0"SELECT * FROM Vehicles""LoadVehicle");
    
/*for(new i = 0; i < MAX_SPAWN_VEHICLES; i++)
    {
        CreateNewVehicle(i);
    }*/
    
return 1;
}
hook OnGameModeExit()
{
    return 
1;

if yet not spawning, Reply what is it printing please.
I tried your version before you post it here, but it`s the same, output in console is working fine, I mean variables are working good, just function which must spawn vehicle is not working, why? I don`t know, maybe it`s problem becouse of hook, maybe not, I don`t know, no body gave me right answer...
Reply


Messages In This Thread
Vehicle Problem - by Sanady - 21.01.2016, 16:09
Re: Vehicle Problem - by Sanady - 21.01.2016, 16:39
Re: Vehicle Problem - by ikey07 - 21.01.2016, 16:39
Re: Vehicle Problem - by Sanady - 21.01.2016, 16:43
Re: Vehicle Problem - by Sanady - 21.01.2016, 16:49
Re: Vehicle Problem - by Sanady - 21.01.2016, 18:37
Re: Vehicle Problem - by jlalt - 21.01.2016, 18:46
Re: Vehicle Problem - by Sanady - 21.01.2016, 18:55
Re: Vehicle Problem - by jlalt - 21.01.2016, 19:00
Re: Vehicle Problem - by Sanady - 21.01.2016, 19:12

Forum Jump:


Users browsing this thread: 5 Guest(s)