AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Few questions from idiot (https://forums.alliedmods.net/showthread.php?t=199043)

LambdaLambda 10-23-2012 15:19

Few questions from idiot
 
Hey,

i've done my own plugin. The idea is, to work with MySQL database. To insert, select etc. data into/from it. Everything was goig right until i had to seperate the servers somehow. So i choosen the string option. Like, to put as a table name a string, which gets data from cVar.

Ookay, so i've done it.
PHP Code:

Format(testsizeof(test), "INSERT INTO %t(steamid, ingame) VALUES ('%s',1)"tablenameauth); 

It does compile, looks like it gonna work. But when i connect to the server, when the plugin have to send data to mysql, it just doesn't, and i do get errors in errorlogs.
Quote:

[0] Line 98, test.sp::OnClientAuthorized()
Native "SQL_TQuery" reported: Invalid database Handle 0 (error: 4)
Any ideas how to fix it? Or maybe it's impossible what i'm trying to do?

Powerlord 10-23-2012 15:24

Re: String as a table in MySQL part
 
%t should be %s in your Format line or you're missing arguments for your translation phrase.

Weird, I made a similar mistake in a test plugin just the other day.

LambdaLambda 10-23-2012 16:49

Re: String as a table in MySQL part
 
When i put the table name, then it works great. Saves data inside my database etc.
[PHP]Format(test, sizeof(test), "INSERT INTO fort(steamid, ingame) VALUES ('%s',1)", auth);[PHP] - it works.

But when i will put there %s, so it will look like this:
PHP Code:

Format(testsizeof(test), "INSERT INTO %s(steamid, ingame) VALUES ('%s',1)"tablenameauth); 

- then it doesn't work. Just like it was skipping.

Did you actually try to put a string as a table name? Or maybe there is other solution? :P

But i didn't told you why i need to easy change that table. It will be on more than one server, and i need to have a seperate table for each server.


Thanks for help, btw.

Root_ 10-23-2012 17:32

Re: String as a table in MySQL part
 
Add two single quotes in a string. Should looks like '%s'
A tip: in dbi stuff you should quote strings, however, no need to do it for float, bool or integer

Mitchell 10-23-2012 17:38

Re: String as a table in MySQL part
 
Quote:

Originally Posted by LambdaLambda (Post 1824334)
%s(steamid, ingame)

O_o i'm no professional when it comes to SQL, but i think there needs to be a space between the table name and the values column names..
Only other thing that i could recommend is that you make it FailState when it gets an error on the callback. and See what's happening.

Root_ 10-23-2012 17:41

Re: String as a table in MySQL part
 
Quote:

Originally Posted by Mitchell (Post 1824361)
but i think there needs to be a space between the table name and the values column names..

If database is not defined as "table " :D

Mitchell 10-23-2012 17:52

Re: String as a table in MySQL part
 
Quote:

Originally Posted by Root_ (Post 1824364)
If database is not defined as "table " :D

Then shame on the code for:
1. not having a logical variable, thus making it harder to find the problem if you forget that space. and
2. for not even telling use the variable string he is inputting.

LambdaLambda 10-25-2012 20:08

Re: String as a table in MySQL part
 
Okay guys. Sorry for not answear, my work didn't allow me for it. I did it, that was only a fucked up string.

PS there's quotes like this ' ' doesn't work in MySQL, you have to use ` `. That's why i had a little mish mash in my head, because i did try quotes, but the first ones. :D

Now, to not opening new topic will ask shortly. I did download that plugin http://forums.alliedmods.net/showthread.php?p=1824790 (version light). And i did try to change it. It works like that, if i have buyed a slot, then that menu dont allow me to buy a slot again, because it says me the rest of my slot's time. It's okay, but i did try to change it. That what i wanted to do is to allow you to click a slot to buy, but if you already have it, it says you that. I thought it gonna work, but when compiling theres no others errors than one "Error 100: Function Prototypes do not match"

And that what i've changed is:

This:
PHP Code:

public Action:CommandLP(clientargs)
{
    new 
Handle:menu CreateMenu(MenuHandler);
    
SetMenuTitle(menu"Loyalty Point System");
    
AddMenuItem(menu"1""Show LP");
    
    if (
HaveClientRS(client))
    {
        new 
String:s_menu5[100];
        new 
client_rsmin GetRSMIN(client);
        if (
client_rsmin <= 60)
        {
            
Format(s_menu5sizeof(s_menu5), "Your RS access end in %i min"GetRSMIN(client));
        }
        else if (
client_rsmin <= 1440)
        {
            
Format(s_menu5sizeof(s_menu5), "Your RS access end in %i h"GetRSMIN(client)/60);
        }
        else
        {
            
Format(s_menu5sizeof(s_menu5), "Your RS access end in %i d"GetRSMIN(client)/1440);
        }
        
AddMenuItem(menu"6"s_menu5ITEMDRAW_DISABLED);
    }
    else
    {
        
AddMenuItem(menu"7""Reserved Slot");
    }
    
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;


To this:
PHP Code:

public Action:CommandLP(clientargs)
{
    new 
Handle:menu CreateMenu(MenuHandler);
    
SetMenuTitle(menu"Loyalty Point System");
    
AddMenuItem(menu"1""Show LP");
    
AddMenuItem(menu"7""Reserved Slot");

    return 
Plugin_Handled;



And this:
PHP Code:

public MenuRS(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select)
    {
        new 
String:info[32];
        
GetMenuItem(menuparam2infosizeof(info));
        
        new 
lp GetLP(param1)
        
        switch(
StringToInt(info))
        {
            case 
1:
            {
                if (
lp >= price_rs_1day)
                {
                    
RemoveLP(param1price_rs_1day)
                    
GiveRS(param11440);
                    
                    if (
IsClientInGame(param1))
                    {
                        
PrintToChat(param1"\x04[LP]\x01 You have bought RS! If Server is full, connect by console to use your reserved slot.")
                    }
                }
                else 
                {
                    
PrintToChat(param1"\x04[LP]\x01 You have %i lp, but you need %i for 1 Day RS!"lpprice_rs_1day);
                }
            }
            case 
2:........ 

To this:
PHP Code:

public MenuRS(Handle:menuMenuAction:actionparam1param2client)
{
    if (
action == MenuAction_Select)
    {
        new 
String:info[32];
        
GetMenuItem(menuparam2infosizeof(info));
        
        new 
lp GetLP(param1)
        
        switch(
StringToInt(info))
        {
            case 
1:
            {if (
HaveClientRS(client))
            {
                    
PrintToChat(param1"You already have a slot");
            }
            else
            {
                    if (
lp >= price_rs_1day)
                    {
                        
RemoveLP(param1price_rs_1day)
                        
GiveRS(param11440);
                    
                        if (
IsClientInGame(param1))
                        {
                            
PrintToChat(param1"\x04[LP]\x01 You have bought RS! If Server is full, connect by console to use your reserved slot.")
                        }
                    }
                    else 
                    {
                        
PrintToChat(param1"\x04[LP]\x01 You have %i lp, but you need %i for 1 Day RS!"lpprice_rs_1day);
                    }
                }
            }
            case 
2:... 

The full code of that plugin you can check in the link above. Can anyone tell me how to fix it?

FaTony 10-26-2012 07:47

Re: String as a table in MySQL part
 
Why did you change the prototype of MenuRS?

LambdaLambda 10-26-2012 14:24

Re: Few questions from idiot
 
coz i'm idiot. Thanks. :D

One more, and last one.

IMO, this should check if in table pfield_content is filled in field_11, and if it's client's steamid. And if there is filled in, to get member_id. And then if it has found steamid in there to send as a true, or if not to send as a false. The point is, it doesn't work. It do connects to database etc. And the error console says is "[0] Line 529, testytest.sp::ForumAccount()"
PHP Code:

bool:ForumAccount(client)
{
    if (
IsClientInGame(client))
    {
        new 
String:steamid[50];
        
GetClientAuthString(clientsteamidsizeof(steamid))
        new 
String:sqlstring[200];
        
Format(sqlstringsizeof(sqlstring), "SELECT member_id FROM pfields_content WHERE field_11 = %s "steamid);
        
SQL_LockDatabase(dbconipb);
        new 
Handle:sql SQL_Query(dbconipbsqlstring);
        new 
forumek_bool SQL_GetRowCount(sql);
        
CloseHandle(sql);
        
SQL_UnlockDatabase(dbconipb);
        
        if (
forumek_bool)
        {
            return 
true;
        }
        else
        {
            return 
false;
        }
    }
    
    return 
true;


What's wrong in here?


All times are GMT -4. The time now is 11:44.

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