SA-MP Forums Archive
How to put a mysql integrer in a message? - 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: How to put a mysql integrer in a message? (/showthread.php?tid=620606)



How to put a mysql integrer in a message? - MineiriinHo - 01.11.2016

Hi, I want to put a mysql var in a text message in my server.
Ex: I want to get the vehicle owner name and put it in a client message...


Okay, this is the command:

PHP код:
CMD:checarplaca(playeridparams[])
{
    static
        
id 0;
    if (
GetFactionType(playerid) != FACTION_POLICE)
        return 
SendErrorMessage(playerid"Vocк precisa ser um policial.");
    if (
sscanf(params"d"id))
        return 
SendSyntaxMessage(playerid"/checarplaca [vehicleid]");
    if (!
IsValidVehicle(id) || Car_GetID(id) == -1)
        return 
SendErrorMessage(playerid"You specified an invalid ID.");
    
SendClientMessage(playerid, -1"The owner of this vehicle is %s :)"//, the syntax of the mysql here?);
    // And the mysql var here :p
    
return 1;

Enum
PHP код:
enum carData {
    
carID,
    
carExists,
    
carModel,
    
carOwner,
    
Float:carPos[4],
    
carColor1,
    
carColor2,
    
carPaintjob,
    
carLocked,
    
carMods[14],
    
carImpounded,
    
carImpoundPrice,
    
carFaction,
    
carWeapons[5],
    
carAmmo[5],
    
carVehicle
}; 
MySQL examples
PHP код:
forward Car_Load();
public 
Car_Load()
{
    static
        
rows,
        
fields,
        
str[128];
    
cache_get_data(rowsfieldsg_iHandle);
    for (new 
0rows++) if (MAX_DYNAMIC_CARS)
    {
        
CarData[i][carExists] = true;
        
CarData[i][carID] = cache_get_field_int(i"carID");
        
CarData[i][carModel] = cache_get_field_int(i"carModel");
        
CarData[i][carOwner] = cache_get_field_int(i"carOwner");
        
CarData[i][carPos][0] = cache_get_field_float(i"carPosX");
        
CarData[i][carPos][1] = cache_get_field_float(i"carPosY");
        
CarData[i][carPos][2] = cache_get_field_float(i"carPosZ");
        
CarData[i][carPos][3] = cache_get_field_float(i"carPosR");
        
CarData[i][carColor1] = cache_get_field_int(i"carColor1");
        
CarData[i][carColor2] = cache_get_field_int(i"carColor2");
        
CarData[i][carPaintjob] = cache_get_field_int(i"carPaintjob");
        
CarData[i][carLocked] = cache_get_field_int(i"carLocked");
        
CarData[i][carImpounded] = cache_get_field_int(i"carImpounded");
        
CarData[i][carImpoundPrice] = cache_get_field_int(i"carImpoundPrice");
        
CarData[i][carFaction] = cache_get_field_int(i"carFaction");
        for (new 
014++)
        {
            if (
5)
            {
                
format(strsizeof(str), "carWeapon%d"1);
                
CarData[i][carWeapons][j] = cache_get_field_int(istr);
                
format(strsizeof(str), "carAmmo%d"1);
                
CarData[i][carAmmo][j] = cache_get_field_int(istr);
            }
            
format(strsizeof(str), "carMod%d"1);
            
CarData[i][carMods][j] = cache_get_field_int(istr);
        }
        
Car_Spawn(i);
    }
    for (new 
0MAX_DYNAMIC_CARS++) if (CarData[i][carExists]) {
        
format(strsizeof(str), "SELECT * FROM `carstorage` WHERE `ID` = '%d'"CarData[i][carID]);
        
mysql_tquery(g_iHandlestr"OnLoadCarStorage""d"i);
    }
    return 
1;
}
format(stringsizeof(string), "DELETE FROM `plants` WHERE `plantID` = '%d'"PlantData[plantid][plantID]); 



Re: How to put a mysql integrer in a message? - AndySedeyn - 01.11.2016

When using specifiers (%s, %d, %i, ...) in a string, you must format it:
PHP код:
new formatString[45];
format(formatStringsizeof(formatString), "The owner of this vehicle is %s""A person's name");
SendClientMessage(playerid, -1formatString); 
%s in this example is replaced by "A person's name" and then put into the format variable called formatString (minus the quotation marks, of course).

You will have to do exactly that but instead of having a static string, you must reuse the variable that holds the owner's name. You'll have to send an extra query to retrieve the name from the row of which the database ID is equal to CarData[id][carOwner].