Raised This Month: $51 Target: $400
 12% 

[DB] Database Manager


Post New Thread Reply   
 
Thread Tools Display Modes
Stinkyfax
BANNED
Join Date: Aug 2007
Old 09-11-2007 , 11:25   Re: [DB] Database Manager
Reply With Quote #21

nice plugin, i'm using it on my server now in case it's required by bank.
I hope you write more awesome plugins )
Stinkyfax is offline
Shaman
Senior Member
Join Date: Dec 2006
Location: Istanbul, Turkey
Old 09-11-2007 , 11:45   Re: [DB] Database Manager
Reply With Quote #22

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");".
__________________
Shaman is offline
Send a message via ICQ to Shaman Send a message via AIM to Shaman Send a message via MSN to Shaman Send a message via Yahoo to Shaman
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-11-2007 , 14:42   Re: [DB] Database Manager
Reply With Quote #23

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
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 09-11-2007 at 16:00.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Shaman
Senior Member
Join Date: Dec 2006
Location: Istanbul, Turkey
Old 09-11-2007 , 16:39   Re: [DB] Database Manager
Reply With Quote #24

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.
__________________
Shaman is offline
Send a message via ICQ to Shaman Send a message via AIM to Shaman Send a message via MSN to Shaman Send a message via Yahoo to Shaman
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-11-2007 , 17:10   Re: [DB] Database Manager
Reply With Quote #25

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
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 09-11-2007 at 17:51.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
tkaway69
Senior Member
Join Date: Dec 2004
Location: Millbrook Alabama
Old 09-12-2007 , 23:23   Re: [DB] Database Manager
Reply With Quote #26

Yea even I am lost on that comment.
__________________
tkaway69 is offline
Send a message via AIM to tkaway69 Send a message via MSN to tkaway69 Send a message via Yahoo to tkaway69
mooshotty
New Member
Join Date: Sep 2007
Old 09-15-2007 , 02:56   Re: [DB] Database Manager
Reply With Quote #27

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
mooshotty is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-15-2007 , 02:58   Re: [DB] Database Manager
Reply With Quote #28

The same way you setup a plugin...
Just put both .smx files into your plugins folder
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
tkaway69
Senior Member
Join Date: Dec 2004
Location: Millbrook Alabama
Old 10-01-2007 , 13:04   Re: [DB] Database Manager
Reply With Quote #29

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
__________________

Last edited by tkaway69; 10-01-2007 at 13:13.
tkaway69 is offline
Send a message via AIM to tkaway69 Send a message via MSN to tkaway69 Send a message via Yahoo to tkaway69
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 10-01-2007 , 20:30   Re: [DB] Database Manager
Reply With Quote #30

Change to SQLite
Apparently your MySQL is not being able to make complete requests, and failing in gathering player data
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:26.


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