AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   One problem (https://forums.alliedmods.net/showthread.php?t=63289)

conrad 11-17-2007 05:28

One problem
 
Hello guys.
I have problem with my script.
Source:

Code:

#include <amxmodx>
#include <amxmisc>
#include <dbi>

#define PLUGIN "plugin"
#define VERSION "1.0"
#define AUTHOR "By conrad"

new Sql:dbc;
new Result:res;

public plugin_init() {
 register_plugin(PLUGIN, VERSION, AUTHOR)
 register_dictionary("csbank.txt")
 register_clcmd("say /money", "saymoney", 0, "- displays hoe much money I have ")
 
 // Add your code here...
}


public sql_init()
{

dbc = dbi_connect("localhost", "login", "password", "db")
   
    if (dbc == SQL_FAILED)
    {
        server_print("[AMXX] %L", LANG_SERVER, "SQL_SERVER_DOWN")
    }
    else
    {
      server_print("[AMXX] %L", LANG_SERVER, "SQL_SERVER_UP")
    }
   
}


public saymoney(id)
{
  new szAuthid[32], szName[32], szMoney[32];
  get_user_authid( id, szAuthid, 31 );
  get_user_name( id, szName, 31 );
 

res = dbi_query(dbc, "SELECT `money` FROM table where name='%s' ", szName);


 while (dbi_nextrow(res) > 0)
 { 
  dbi_result(res, "money", szMoney, 31)
 }
 


client_print(0,print_chat, szMoney);
 
}

It doesn't return any result back. What is the problem?

kim_perm 11-17-2007 16:39

Re: One problem
 
Hello. May be
Code:
client_print(id, print_chat, szMoney);
?

Alka 11-17-2007 17:23

Re: One problem
 
1. I don't see where you store money in table.
2. szMoney is a string, so you should do
Code:

client_print(id, print_chat, "%d", str_to_num(szMoney));
3.I think you should make szMoney a integer.

[ --<-@ ] Black Rose 11-17-2007 21:26

Re: One problem
 
Quote:

Originally Posted by Alka (Post 554012)
2. szMoney is a string, so you should do
Code:

client_print(id, print_chat, "%d", str_to_num(szMoney));

So you think he should convert the string to an int, to fit it in a string?

Alka 11-18-2007 04:14

Re: One problem
 
Wut? In sql table you can put integers too...lawl. So will be:
Code:

new iResult;
iResult = dbi_result(retsult, "Name");

Oh, nvm, why not Black Rose ?! o.O

conrad 11-18-2007 05:32

Re: One problem
 
1. Money there is by default in the table.
2. It's integer. Why do you think, that there is a string? In the table there is an integer.

About ID - while I'm testing, I'm using ID 0 - if ID is null, the message shows to all players.


Alka it aint working.

Alka 11-18-2007 06:01

Re: One problem
 
Quote:

Originally Posted by conrad (Post 554174)
1. Money there is by default in the table.
2. It's integer. Why do you think, that there is a string? In the table there is an integer.

Alka it aint working.

If money is a int then you must do my way. Take a look at wiki, "dbi_result"...

conrad 11-18-2007 07:15

Re: One problem
 
Error:
Quote:

warning 217: loose indentation
warning 217: loose indentation
warning 217: loose indentation
warning 217: loose indentation
error 035: argument type mismatch (argument 3)
warning 204: symbol is assigned a value that is never used: "iResult"


Code:

public saymoney(id)
{
  new szAuthid[32], szName[32];
  new iResult;
  get_user_authid( id, szAuthid, 31 );
  get_user_name( id, szName, 31 );
 

res = dbi_query(dbc, "SELECT `money` FROM table where name='%s' ", szName);


 while (dbi_nextrow(res) > 0)
 {
 
  iResult = dbi_result(res, "money");
 
 }
 


client_print(0,print_chat, iResult);
 
}


Alka 11-18-2007 08:52

Re: One problem
 
Duh...this is my first time when i use "dbi" lol , but with wiki i've maded this...

Code:

#include <amxmodx>
#include <dbi>
 
#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"
 
new Sql:Dbc;
 
public plugin_init() {
 
 register_plugin(PLUGIN, VERSION, AUTHOR);
 
 register_clcmd("say /money", "ShowMoney");
}
 
public plugin_cfg()
{
 Dbc = dbi_connect("localhost", "login", "password", "db");
 
 if(Dbc == SQL_FAILED)
 {
  dbi_close(Dbc);
  return;
 }
}
 
public plugin_end()
 dbi_close(Dbc);
 
public ShowMoney(id)
{
 new szName[32];
 get_user_name(id, szName, sizeof szName - 1);
 
 new Result:HandleR, iResult;
 HandleR = dbi_query(Dbc, "SELECT `money` FROM table where name='%s' ", szName);
 
 while(dbi_nextrow(HandleR) > 0)
 {
  iResult = dbi_result(HandleR, "money");
 }
 
 if(iResult > 0)
  client_print(id, print_chat, "%d", iResult);
}



All times are GMT -4. The time now is 01:12.

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