Raised This Month: $ Target: $400
 0% 

Compare Array Question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Anthraxnz
Senior Member
Join Date: May 2005
Location: New Zealand
Old 03-14-2006 , 01:18   Compare Array Question
Reply With Quote #1

hi

i have 2 arrays one called admins[32] and one called adminSQL[100]

i need to compare these arrays and cant get my head around how

admins[32] stores the steam id of any admins on the server
adminSQL[100] stores all the admin steamids from "auth" field

how would i compare these 2 arrays since SQL could have anywhere from 1 admin to 100 admins and the server could have 32 admins on it.

heres what i got so far
Code:
    new adminSteamIDs[32]     new authID[32]     new players[32], inum     new i = 0         get_players(players,inum)         //Find All Admins On Server and Store SteamID in array     while( i < inum ){         if( get_user_flags(players[i])){             get_user_authid(players[i],authID,31)             copy(adminSteamIDs[i],31,authID)         }         i++     }     //Retrieve All Admins From SQL Database and Store In Array     new steamSQL[100]     new adminName[100]     new j = 0         result = dbi_query(dbc,"SELECT auth,name FROM admins")         while( j < dbi_num_rows(result)){         dbi_nextrow(result)         dbi_result(result,"auth",steamSQL[j])     }         //Compare Admins Array With SQL Array And Print If They Match

someone help please
__________________
Dont know how to add admins?

use my program
http://www.amxmodx.org/forums/viewto...=129092#129092

it does the work for you ... sort of
Anthraxnz is offline
Anthraxnz
Senior Member
Join Date: May 2005
Location: New Zealand
Old 03-14-2006 , 04:55  
Reply With Quote #2

heres what iv got so far. dont know if it works but im guessing it wont.
any suggestions on how to make it work?

Code:
    new j = 0     new authSQL[32]     new nameSQL[32]         result = dbi_query(dbc,"SELECT name,auth FROM admins")         while( j < inum ){                 new k = 0         while( k < dbi_num_rows(result)){             dbi_nextrow(result)             dbi_result(result,"auth",authSQL,31)                         if( equali(authSQL[k],adminSteamIDs[j])){                 dbi_result(result,"name",nameSQL,31)                 console_print(id,"%s = %s",adminSteamIDs[j],nameSQL)             }             k++         }         j++     }
__________________
Dont know how to add admins?

use my program
http://www.amxmodx.org/forums/viewto...=129092#129092

it does the work for you ... sort of
Anthraxnz is offline
Anthraxnz
Senior Member
Join Date: May 2005
Location: New Zealand
Old 03-14-2006 , 05:37  
Reply With Quote #3

works if theres only one person on the server.

if theres more then it just prints a whole bunch of ='s with some random letters
__________________
Dont know how to add admins?

use my program
http://www.amxmodx.org/forums/viewto...=129092#129092

it does the work for you ... sort of
Anthraxnz is offline
capndurk
Senior Member
Join Date: Feb 2006
Old 03-14-2006 , 08:53  
Reply With Quote #4

Show the output and the database files, so maybe we can get a better look at the problem you're having.

Also, to make things easier to read, I'd use a for loop within a for loop, instead of two whiles:

Code:
for(new i = 0; i < whatever; i++) {      for(new j = 0; j < whatever; j++)      {           if(they equal) // blah blah blah      } }
capndurk is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-14-2006 , 10:00  
Reply With Quote #5

You only want the matching records from SQL, correct?

I haven't tested the code below but what it's intended to do is create a where clause containing each of the STEAM_ID's you're looking to match. It then only pulls the records from the table that do match. Therefore, the number of matches will be equal to the new of records returned from the query.

Code:
    new authID[32]     new players[32], inum, playerID         get_players(players,inum)         //Find All Admins On Server and Store SteamID in where string     for (new i = 0; i < inum; i++){         playerID = players[i]         if( get_user_flags(playerID)){             get_user_authid(playerID,authID,31)             format(whereClause, 1023, "%s OR auth = '%s'", whereClause, authID)         }     }     copy(whereClause, 1023, whereClause[4])     //Retrieve All Admins From SQL Database and Store In Array     new adminName[100]     new j = 0         result = dbi_query(dbc,"SELECT auth,name FROM admins WHERE %s", whereClause)         while( j < dbi_num_rows(result)){         dbi_nextrow(result)         dbi_result(result,"auth",steamSQL[j])     }
Brad is offline
Anthraxnz
Senior Member
Join Date: May 2005
Location: New Zealand
Old 03-14-2006 , 16:07  
Reply With Quote #6

cool, thanks will give it a try when i get back
__________________
Dont know how to add admins?

use my program
http://www.amxmodx.org/forums/viewto...=129092#129092

it does the work for you ... sort of
Anthraxnz is offline
Anthraxnz
Senior Member
Join Date: May 2005
Location: New Zealand
Old 03-15-2006 , 04:30  
Reply With Quote #7

been workin on this and it still doesnt work.

if im admin in slot #1 it works but if im in #2 then i just does nothing.
cant figure out why heres what i got so far that seems to work when im in #1

Code:
//Admin Checking Function--------------------------------------------------------------- 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 players[32], inum     get_players(players,inum)     //Retrieve All Admins From SQL Database and Store In Array         new authSQL[32]     new nameSQL[32]         new nameHLDS[32]     new authHLDS[32]         result = dbi_query(dbc,"SELECT name,auth FROM admins")         for( new j = 0; j < inum; j++ ){         get_user_authid(players[j],authHLDS,31)         get_user_name(players[j],nameHLDS,31)                 for( new k = 0; k <= dbi_num_rows(result); k++ ){             dbi_nextrow(result)             dbi_result(result,"auth",authSQL,31)                         if( equali(authSQL,authHLDS)){                 dbi_result(result,"name",nameSQL,31)                 console_print(id,"%s = %s",nameHLDS,nameSQL)             }         }     }         dbi_free_result(result)     return PLUGIN_HANDLED   }
__________________
Dont know how to add admins?

use my program
http://www.amxmodx.org/forums/viewto...=129092#129092

it does the work for you ... sort of
Anthraxnz is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-15-2006 , 08:41  
Reply With Quote #8

Are you trying to be inefficient with your code? Also, you're more likely to get help if you post the entire plugin so that others can make/test changes.
Brad is offline
Anthraxnz
Senior Member
Join Date: May 2005
Location: New Zealand
Old 03-15-2006 , 16:23  
Reply With Quote #9

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <dbi> new Sql:dbc new Result:result public plugin_init() {     register_plugin("SQL Admin Checker","1.0","Anthrax")     register_concmd("amx_admins","checkAdmin",ADMIN_KICK," - Checks For Admins Real Name")     set_task(Float:10.0,"sql_init") } //Start SQL Connection Function--------------------------------------------------------- public sql_init(id){     new host[64], username[32], password[32], dbname[32], error[32]     get_cvar_string("amx_sql_host",host,63)     get_cvar_string("amx_sql_user",username,31)     get_cvar_string("amx_sql_pass",password,31)     get_cvar_string("amx_sql_db",dbname,31)     dbc = dbi_connect(host,username,password,dbname,error,31)     if (dbc == SQL_FAILED)         log_amx("[AMXX] SQL Connection Failed") } //Admin Checking Function--------------------------------------------------------------- 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 players[32], inum     get_players(players,inum)     //Retrieve All Admins From SQL Database and Store In Array         new authSQL[32]     new nameSQL[32]         new nameHLDS[32]     new authHLDS[32]         result = dbi_query(dbc,"SELECT name,auth FROM admins")         for( new j = 0; j < inum; j++ ){         get_user_authid(players[j],authHLDS,31)         get_user_name(players[j],nameHLDS,31)                 for( new k = 0; k <= dbi_num_rows(result); k++ ){             dbi_nextrow(result)             dbi_result(result,"auth",authSQL,31)                         if( equali(authSQL,authHLDS)){                 dbi_result(result,"name",nameSQL,31)                 console_print(id,"%s = %s",nameHLDS,nameSQL)             }         }     }         dbi_free_result(result)     return PLUGIN_HANDLED   }

as for effiency i cant think of any other way of doing it.
__________________
Dont know how to add admins?

use my program
http://www.amxmodx.org/forums/viewto...=129092#129092

it does the work for you ... sort of
Anthraxnz is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-15-2006 , 19:17  
Reply With Quote #10

Quote:
Originally Posted by Anthraxnz
as for effiency i cant think of any other way of doing it.
Quote:
Originally Posted by Brad
I haven't tested the code below but what it's intended to do is create a where clause containing each of the STEAM_ID's you're looking to match. It then only pulls the records from the table that do match. Therefore, the number of matches will be equal to the new of records returned from the query.
Using the code I provided, or at least a reasonable facisimile is more efficient than the double loop. As a general rule, you always want to limit the amount of data you're bringing over the wire. In other words, don't bring over more than you need.
Brad is offline
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 20:15.


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