Questions
1-How does this work? How does this save the information?
2-Can you give some examples:
-Creating a column if it doesn't exist
-Reading and writing to columns named "xp"(integer) "name"(string)
Suggestions
1-Can you remove 'add'(bool) and add 'todo'(string) to DB_SetInfo? ('todo' can be 'set', 'inc' or 'dec')
2-Saving and reading to custom ID's:
PHP Code:
public bool:BuildDB()
{
if(!DB_CheckIDTable("shamans_plugin_players")) //Checks the table for existance (This means there will be multi-table support.)
{
DB_CreateIDTable("shamans_plugin_players"); //Creates a table
DB_SelectIDTable("shamans_plugin_players"); //Selects the table
DB_CreateIDTableColumn("xp"); //Creates new column named "xp"
DB_CreateIDTableColumn("money"); //Creates new column named "money"
DB_CreateID("default"); //Creates a new id named "default"
DB_SetIDValue("default", "xp", "100"); //Sets "xp" to "100" for id named "default"
DB_SetIDValue("default", "money", "200"); //Sets "money" to "200" for id named "default"
return true;
}
return false;
}
public CheckXP(client)
{
if(!DB_SelectIDTable("shamans_plugin_players")) //Tries to select the table
{
PrintToChatAll("Cannot select "Players" table!");
}
new xp;
new String:name[MAX_NAME_LENGHT];
GetClientName(client, name, MAX_NAME_LENGHT);
if(!DB_CheckID(name)) //Checks id for existance
{
DB_CreateIDFromOtherID(name, "default"); //Creates a new id using values from id "default"
DB_GetIDValue(name, "xp", s_xp, sizeof(s_xp)); //Gets the value of "xp"
xp= StringToInt(s_xp);
PrintToChat(client, "Account not found. Created new account with %i xp!", xp);
}
else
{
new String:s_xp[32];
DB_GetIDValue(name, "xp", s_xp, sizeof(s_xp)); //Gets the value of "xp"
xp= StringToInt(s_xp);
PrintToChat(client, "Account found. Your xp is %i!", xp);
if(xp<100)
{
new bool:luck= bool:GetRandomInt(0, 1);
if(!luck)
{
PrintToChat(client, "Your XP is too low. Account deleted!");
DB_DeleteID(name); //Deletes the id
xp= -1;
}
else
{
PrintToChat(client, "Your XP is too low; but you are lucky!");
DB_EmptyID(name); //Sets all values for the id to "0"
DB_SetIDValueFromOtherID(name, "xp", "default"); //Copies "xp" value from "default"
xp= 100;
}
}
}
return xp;
}
The second suggestion will be better for everybody; because it's more flexible. ID's can be a player's name, ip or steam id. Maybe it can be a setting for a plugin like "DB_CreateID("simple_plugin_enabled");".
__________________