AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Truncating Variables? (https://forums.alliedmods.net/showthread.php?t=26688)

Migs Davis 04-07-2006 12:39

Truncating Variables?
 
I'm making a custom plugin, needs to store steam ids and usernames to mysql database (when I get these two things down everythign else will be cake) but it truncates their steamid somewhere along the code...


Code:
#include <amxmodx> #include <amxmisc> #include <dbi> #define PLUGIN "SteamId Manager" #define VERSION "1.0" #define AUTHOR "Migs Davis" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR) } public client_connect(id) {     new user[20], len     new Sql:idList new steamId[20] new Result:checkExist new Result:addId new Result:addName idList = dbi_connect ( "host", "username", "password", "table")     if (idList < SQL_OK)     {         new err[255]         new errNum = dbi_error(idList, err, 254)         server_print("error1: %s|%d", err, errNum)     }     get_user_authid(id, steamId, 20)     server_print("Their steam ID is: %s", steamId)     //while (steamId[9]=='P')     //get_user_authid(id, steamId[], 20)     checkExist = dbi_query ( idList, "SELECT * FROM list WHERE (steamid) = ('%s')", steamId)     if (checkExist <= RESULT_NONE) {                 len = get_user_name(id,user[0],30)     server_print("Not in our database yet, %s", steamId)     addId = dbi_query(idList, "INSERT INTO list (name, steamid) values ('%s', '%d')", steamId, user)                 //These are reversed but whats strange is that it doesn't reverse them in the database         //addName = dbi_query(idList, "UPDATE list SET name='%d' WHERE steamid='%s'", user, steamId)         console_print(id, "You should be succesfully added")         dbi_free_result(addId)     }         server_print("%s is in our database under %d", user, steamId)         dbi_free_result(addName)     dbi_free_result(checkExist)         dbi_close ( idList ) }

(sorry for the somewhat messed up indents I've been up for a day or 3)

This is the server output:
Quote:

Their steam ID is: STEAM_0:1:9834747
Not in our database yet, STEAM_0:1:9834747
[ css:um ] Migs Davis is in our database under 83
This is the created fields in the table:
(^^i actually think thats correct grammar, one example, many fields?)
<list>
<name>[ css:um ] Migs Davis</name>
<id>29</id>
<steamid>83</steamid>
<roundsplayed>0</roundsplayed>
<posts>0</posts>
<css>0</css>
<blazed>0</blazed>
<zero>0</zero>
<admin>not</admin>
</list>
(of course everytime I connect it copies.)

Migs Davis 04-07-2006 13:44

Hey guys I still can't figure it out...I've tried using different mysql querries and using a different code order... still no luck. Actually, for a while, "name" appeared as 91 and steam id showed up perfectly.

Xanimos 04-07-2006 14:11

where do you get
Code:

<list>
<name>[ css:um ] Migs Davis</name>
<id>29</id>
<steamid>83</steamid>
<roundsplayed>0</roundsplayed>
<posts>0</posts>
<css>0</css>
<blazed>0</blazed>
<zero>0</zero>
<admin>not</admin>
</list>

from

Migs Davis 04-07-2006 14:15

Thats an xml export from phpmyadmin to see content excel-style or w/e... its that about 8 times after connecting 8 times.

Xanimos 04-07-2006 14:19

Code:
if (checkExist <= RESULT_NONE)
--->
Code:
if (checkExist >= RESULT_NONE)

Migs Davis 04-07-2006 14:22

Alright lets see what happens, I copied the code straight off an official tutorial (more or less)
>>>>>>>>>5 MINS LATER>>>>>>

nope... its still truncating the steamid variable sometimes between displaying and sending the query to MySQL from my steamid STEAM_0:1:9834747 to just 83
Also,
In English, for that conditional, i intended it to be If Record Doesn't Exist Then:... so is switching the operand there appropriate?

Migs Davis 04-07-2006 14:36

I was thinking something might be wrong in

Code:
"INSERT INTO list (name, steamid) values ('%s', '%d')"
because if I just do one variable it works., either name or steam.
But I can't tell :-( <-- me a nub

Migs Davis 04-07-2006 15:46

Alright. Contest. First person to help me fix this: 5 bucks via paypal.

slurpycof 04-07-2006 15:47

Try this. if it works, keep your 5 bucks for your server costs. I just modified a different plugin I had made for someone.

Code:
 #include <amxmodx>  #include <amxmisc>  #include <dbi>  new Sql:dbc  new Result:result  public plugin_init(){     register_plugin("SteamId Manager","1.0","Migs Davis ")     set_task(0.1,"sql_init")  }  public sql_init() {     new host[64], username[32], password[32], dbname[32], error[32]     get_cvar_string("amx_sql_host",host,64)     get_cvar_string("amx_sql_user",username,32)     get_cvar_string("amx_sql_pass",password,32)     get_cvar_string("amx_sql_db",dbname,32)     dbc = dbi_connect(host,username,password,dbname,error,32)     if (dbc == SQL_FAILED)     {         new err[255]         new errNum = dbi_error(dbc, err, 254)         server_print("error1: %s|%d", err, errNum)     }     else     {         dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `steamidmanager` (`steamid` VARCHAR(32) NOT NULL,`player` VARCHAR(32) NOT NULL, PRIMARY KEY(`steamid`))")     }  } public client_authorized(id){     if ( is_user_bot(id) ) {  //Do not add to database         return PLUGIN_CONTINUE     }     if (is_user_hltv(id) ) {  //Do not add to database         return PLUGIN_CONTINUE     }     new name[32]     get_user_name(id,name,31)     new authid[32]     get_user_authid(id,authid,31)     result = dbi_query(dbc,"SELECT * FROM steamidmanager WHERE steamid = '%s'",authid)     if (result == RESULT_FAILED){ //Problem with mysql         log_amx("[steamidmanager] MySQL Query failed")         return PLUGIN_CONTINUE     }     else if (result == RESULT_NONE)     { //not in db, add them         server_print("Not in our database yet, %s", authid)         result = dbi_query(dbc,"INSERT INTO steamidmanager (steamid, player) values ('%s','%s')", authid, name)         return PLUGIN_CONTINUE     }     else     {         server_print("%s is in our database under %s", authid, name)         result = dbi_query(dbc,"UPDATE steamidmanager SET player=%s WHERE steamid='%s'", name, authid)     }     dbi_free_result(result)     return PLUGIN_CONTINUE }

Xanimos 04-07-2006 16:12

Quote:

Originally Posted by Migs Davis
...
In English, for that conditional, i intended it to be If Record Doesn't Exist Then:... so is switching the operand there appropriate?

Code:
if (checkExist == RESULT_NONE)


All times are GMT -4. The time now is 16:48.

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