AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [DB] Database Manager (https://forums.alliedmods.net/showthread.php?t=60036)

Stinkyfax 09-11-2007 11:25

Re: [DB] Database Manager
 
nice plugin, i'm using it on my server now in case it's required by bank.
I hope you write more awesome plugins )

Shaman 09-11-2007 11:45

Re: [DB] Database Manager
 
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(clientnameMAX_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_xpsizeof(s_xp)); //Gets the value of "xp"
        
xpStringToInt(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_xpsizeof(s_xp)); //Gets the value of "xp"
        
xpStringToInt(s_xp);
        
PrintToChat(client"Account found. Your xp is %i!"xp);
        if(
xp<100)
            {
            new 
bool:luckbool:GetRandomInt(01);
            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"
                
xp100;
                }
            }
        }
    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");".

Nican 09-11-2007 14:42

Re: [DB] Database Manager
 
Well, the whole idea of the plugin is people don't have to select tables, create users and bla bla bla...

SM Bank: MySQL is the only published plugin I finished that is based on this:
http://forums.alliedmods.net/showthread.php?t=60110

I tried to make it as easy as possible... for example, for get player XP, you can just:

PHP Code:

new row_xp;
public 
DB_OnRowsUpdated(){
       
//This will automatically create a int row called PluginXP
    
row_xp DB_GetColumnId("PluginXP"truetrueDB_INT);
    if(
row_xp == -1)
        
SetFailState("Fail state: Could not create row!");
}

stock GetPlayerXP(client){
   return 
DB_GetColumnclientrow_xp );
}

//The 4 argument, "add", if set to true it will add to the old value
//For exemple, if the player XP is 100, and you use SetPlayerXP(client, 50, true);, now player XP will be 150
stock SetPlayerXP(clientamountbool:add=false){
   
DB_SetInfoclientrow_xpamount,add);
}

//Called when clients connect and his data is prefetched from the table
public DB_OnClientUpdate(client){
   if(
GetPlayerXP(client) == 0)
       
SetPlayerXP(client100);


I do like the idea of setting a default value... I think I will add that later
and maybe a cvar changing what player id will be

Shaman 09-11-2007 16:39

Re: [DB] Database Manager
 
But you use "client". So it's saved with Name, IP or SteamID and it's not enough. Players' change names, some players have dynamic IP's and this can't be used to save plugin settings.

Nican 09-11-2007 17:10

Re: [DB] Database Manager
 
if SteamID is not enough, I wonder how you are keeping data :O

and player data are saved when they disconnected, with their Steam_id as id

tkaway69 09-12-2007 23:23

Re: [DB] Database Manager
 
Yea even I am lost on that comment.

mooshotty 09-15-2007 02:56

Re: [DB] Database Manager
 
i'm sorry. i'm a complete noobie to SourceMod. A mani transfer over.

So I'm trying to set up the bank.

I have no idea how to setup mysql. So i'm not sure if I have a database made somewhere on my server, nor do I know if I dont have a db, what I do to set one up. If somebody could give me damn near a step by step instruction to installing both bank and the database manager I would really appreciate it

Nican 09-15-2007 02:58

Re: [DB] Database Manager
 
The same way you setup a plugin...
Just put both .smx files into your plugins folder

tkaway69 10-01-2007 13:04

Re: [DB] Database Manager
 
Hey "Nican" how can I get rid of this error. Thanks for your help. We are still using a "free" Mysql Database. I was thinking maybe the database was being slow or something.

L 10/01/2007 - 00:19:45: [SM] Native "SQL_FetchRow" reported: Invalid query Handle 0 (error: 4)
L 10/01/2007 - 00:19:45: [SM] Debug mode is not enabled for "a_mysql.smx"
L 10/01/2007 - 00:19:45: [SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug 6 on

Nican 10-01-2007 20:30

Re: [DB] Database Manager
 
Change to SQLite
Apparently your MySQL is not being able to make complete requests, and failing in gathering player data


All times are GMT -4. The time now is 18:51.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.