Vehicle Problem
#1

fixed
Reply
#2

Sorry for bump but same problem I had with actors...
Reply
#3

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
Reply
#4

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
Well technically, LoadVehicle function will create all vehicles on map right?
Reply
#5

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
Sorry for bumping but I did what you told me but it`s not working, airplane is not spawned
Reply
#6

Here is the server log, I debugged my variables, they are good:
Код:
[19:30:06] ModelID: 53, PosX: 1328.619995, PosY:1612.250000, PosZ: 11.743700, Angle: 270.000000, Color1: 1, Color2: 1
Reply
#7

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

Quote:
Originally Posted by Sanady
Посмотреть сообщение
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...
You mean the print is Printing right data but vehicle is not getting created?
Or it not being called?
Reply
#10

Quote:
Originally Posted by jlalt
Посмотреть сообщение
You mean the print is Printing right data but vehicle is not getting created?
Or it not being called?
Yea, data is priting correctly, but vehicle is not created in game.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)