AlliedModders

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

Anthraxnz 03-07-2006 00:31

Help Please
 
can someone tell me why this doesnt work properly?

when i test it with just one person( my self ) it works because im slot #1 but when someone else is in slot #1 it doesnt work.

its suposed to connect to a SQL DB then loop through all players STEAMIDs on the server and compare then with ones located in the admins table.

if it one matches it shud print Alias Name then STEAMID followed by Real Name

ie
Player??? STEAM123 Dave

Code:
public checkAdmin(id){     if (!(get_user_flags(id)&ADMIN_KICK)){         console_print(id,"You have no access to that command")         return PLUGIN_HANDLED }             new players[32],inum, auth[32],name[32],playerid[32], playername[32]         if(!get_playersnum()){         console_print(id,"No Players Found")         return PLUGIN_HANDLED     }     get_players(players,inum)     result = dbi_query(dbc,"SELECT * FROM admins")         console_print(id,"Admins On Server")         for (new i=0;i<=dbi_num_rows(result);i++) {                     dbi_nextrow(result)         dbi_result(result,"auth",auth,31)         get_user_authid(players[i],playerid,31)         get_user_name(players[i],playername,31)         if ( equal(auth,playerid)){             dbi_result(result,"name",name,31)             console_print(id,"%s %s = %s",playername,playerid,name)         }     }     dbi_free_result(result)     return PLUGIN_HANDLED }

think its to do with the loop

Charr 03-07-2006 14:05

Do the people that are trying to use it not have Kick access?
Is there an open connection to the SQL?

Anthraxnz 03-07-2006 15:50

requried level is kick and there is a connection to sql

Kraugh 03-07-2006 16:16

right now you are mixing a player check loop and an admin check loop. you need two different loops: one that loops through all of the players, and one inside that searches all steam ids in the database and attempts to match it with the current player.

i would recommend querying the server only once and saving the admin steam ids into a variable so you don't have to use mysql over and over. it would look something like this:

Code:
#define MAX_ADMINS 32 new adminlist[MAX_ADMINS][32]; public get_adminlist() {    new admincount = 0;    // query here    while(/* this would be your result loop */) {       format(adminlist[admincount++],31,"%s",/* authid retrieved from database */);    }    return admincount; } public check_admins() {    new admincount = get_adminlist();    new players[32], num, i, j;    get_players(players, num);    for(i=0;i<num;i++) {       new authid[32];       get_user_authid(players[i],authid,31);       for(j=0;j<admincount;j++) {          if(equali(authid,adminlist[j])) {             // console print here             continue;          }       }    } }

i don't know exactly how amxx's mysql works so you'll have to work to adapt it.

Anthraxnz 03-07-2006 18:49

ok thanks will give it a try

Anthraxnz 03-08-2006 19:25

cant seem to figure it out can someone help?
heres the complete code

Code:
#include <amxmodx> #include <amxmisc> #include <dbi> new Sql:dbc new Result:result #define MAX_ADMINS 32 new adminlist[MAX_ADMINS][32] public plugin_init() {     register_plugin("AdminCheck","1.0","Anthrax")     register_concmd("amx_admins","checkAdmin",ADMIN_KICK," - Checks For Admins Real Name")     set_task(Float:10.0,"sql_init") } public sql_init(id){     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)         log_amx("[AMXX] SQL Connection Failed") } //----------------------------------------------------------------------------------------- public get_adminlist(){     new admincount = 0;     new sqlAuth[32]     new i = 1     result = dbi_query(dbc,"SELECT auth FROM admins")     while( i <= dbi_num_rows(result)) {         format(adminlist[admincount++],31,"%s",sqlAuth);         i++     }     return admincount; } //----------------------------------------------------------------------------------------- public checkAdmin(id){     if (!(get_user_flags(id)&ADMIN_KICK)){         console_print(id,"You have no access to that command")         return PLUGIN_HANDLED     }     if (!get_playersnum()){         console_print(id,"No Players Found")         return PLUGIN_HANDLED     }     new admincount = get_adminlist()     new players[32], num, i, j     new name[32]     get_players(players, num)         for(i=0;i<num;i++) {         new authid[32]         get_user_authid(players[i],authid,31)                       for(j=0;j<admincount;j++) {             if(equali(authid,adminlist[j])) {                 dbi_result(result,"name",name,32)                 console_print(id,"%s",name)                 continue;             }         }     }         dbi_free_result(result)     return PLUGIN_HANDLED }

GHW_Chronic 03-08-2006 19:34

Code:
dbc = dbi_connect(host,username,password,dbname,error,32)
to
Code:
dbc = dbi_connect(host,username,password,dbname,error,31)

just something that I noticed off the back. Another thing I noticed is the thread title is "Help Please". Next time please name is something related to what you need help with. In example: "SQL Query Help"


All times are GMT -4. The time now is 20:17.

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