2020-11-10, 12:27 AM
(2020-11-07, 11:20 AM)Pinch Wrote: Because cache_get_value_index_int uses column's idx while cache_get_value_name uses literal string.
cache_get_value_name(row, "collumn_name", out);
Edit:
mysql_tquery(g_SQL,query);
I don't see a callback there....? Where were you using cache functions at all...?
this is my factions code, if u want i can provide the entire code, and the tutorial i read,?
Code:
enum faction
{
ID, //Facc ID
Name[32],
Type, //Type, criminal, law, legal no weapon, legal weapons.
Rank1[32], //Rank name
Rank2[32], //Rank name
Rank3[32], //Rank name
Rank4[32] //Rank name
};
//enum initializing
new Factions[MAX_FACTIONS][faction], Total_Factions_Created, facid[MAX_PLAYERS];
forward LoadFactions();
public LoadFactions()
{
new rows, fields;
cache_get_value_index_int(rows,fields,g_SQL);
if( rows )
{
for( new i = 0; i < rows; i )
{
cache_get_value_int(i,"id",Factions[i][ID]);
cache_get_value_name(i,"name",Factions[i][Name]);
cache_get_value_name(i,"type",Factions[i][Type]);
cache_get_value_name(i,"Rank1",Factions[i][Rank1]);
cache_get_value_name(i,"Rank2",Factions[i][Rank2]);
cache_get_value_name(i,"Rank3",Factions[i][Rank3]);
cache_get_value_name(i,"Rank1",Factions[i][Rank4]);
}
}
return 1;
}
public OnGameModeInit()
{
new MySQLOpt: option_id = mysql_init_options();
mysql_set_option(option_id, AUTO_RECONNECT, true); // it automatically reconnects when loosing connection to mysql server
g_SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, option_id); // AUTO_RECONNECT is enabled for this connection handle only
if (g_SQL == MYSQL_INVALID_HANDLE || mysql_errno(g_SQL) != 0)
{
print("MySQL connection failed. Server is shutting down.");
SendRconCommand("exit"); // close the server if there is no connection
return 1;
}
new query[103];
mysql_format(g_SQL, query, sizeof query,"SELECT * FROM Factions");
mysql_tquery(g_SQL, query, "LoadFactions");
print("MySQL connection is successful.");
SetTimer("MoneyTimer", 1000, 1);
return 1;
}
//working command
CMD:fcreate(playerid,params[])
{
new string[128], query[400], fname[32];
if(sscanf(params, "s[32]", fname)) return SendClientMessage(playerid,RED_COLOR,"USAGE: /fcreate factionname");
Total_Factions_Created;
//-----------------------------------
format(Factions[Total_Factions_Created][Name], 64,"%s", fname);
Factions[Total_Factions_Created][ID] = Total_Factions_Created;
//-----------------------------------
format(string, sizeof(string),"Creaste la faccion %s(ID:%d).",Factions[Total_Factions_Created][Name],Factions[Total_Factions_Created][ID]);
SendClientMessage(playerid, SYSTEM_COLOR, string);
//-----------------------------------
format(Factions[Total_Factions_Created][Rank1], 32, "Rank 1 - Lowest");
format(Factions[Total_Factions_Created][Rank2], 32, "Rank 2");
format(Factions[Total_Factions_Created][Rank3], 32, "Rank 3");
format(Factions[Total_Factions_Created][Rank4], 32, "Rank 4 - leader");
format(query, sizeof(query), "INSERT INTO `factions` (id, name, Rank1, Rank2, Rank3, Rank4) VALUES(%d,'%s','%s','%s','%s','%s')",
Factions[Total_Factions_Created][ID], Factions[Total_Factions_Created][Name], Factions[Total_Factions_Created][Rank1],
Factions[Total_Factions_Created][Rank2], Factions[Total_Factions_Created][Rank3], Factions[Total_Factions_Created][Rank4]);
mysql_tquery(g_SQL,query);
return 1;
}
//this one prints 30 empty lines
CMD:printtest(playerid,params[])
{
new query[140];
for(new i = 0; i < MAX_FACTIONS; i)
{
format(query, sizeof(query),"SELECT * FROM Factions WHERE ID = %d",i);
mysql_tquery(g_SQL,query);
printf("%s\n", Factions[i][Name]);
}
return 1;
}