Raised This Month: $ Target: $400
 0% 

SQL Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
saabirsa
Junior Member
Join Date: Feb 2005
Location: U.K.
Old 03-07-2006 , 16:11   SQL Plugin
Reply With Quote #1

Hello all,

I am new at AMX Mod X coding, and I would like to know how I would go about doing this;

If say, a player came on, with a specific tag in front of their name (EG [Someone] Player), then a plugin would detect this and check in SQL if their SteamID can be found in a table. If it can find it, then it lets them in, and if not it kicks them. But if a player came on without the specified tag, nothing would happen, and all would continue.

I have an OK knowledge of MySQL, but absolutely none with Small, and I would like to start learning.

Thanks Again
Saabir Salim
(PS Sorry if this is in the wrong forum )
saabirsa is offline
saabirsa
Junior Member
Join Date: Feb 2005
Location: U.K.
Old 03-08-2006 , 09:11  
Reply With Quote #2

Bump

Just asking for a nudge in the right direction, how to actually make it connect to SQL first of all.

Thanks
Saabir Salim
__________________
My Sites l Forum | Cold Chaos Clan | M+
saabirsa is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-08-2006 , 18:20  
Reply With Quote #3

dbi_connect
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
saabirsa
Junior Member
Join Date: Feb 2005
Location: U.K.
Old 03-08-2006 , 19:40  
Reply With Quote #4

OK, thanks, this is what I got so far,

Code:
#include <amxmodx> #include <dbi>   new Sql:dbc // Standerd Defines public plugin_init() { register_plugin("Check for STEAMID","0.0.1","Saabir Salim") register_cvar("amx_ccc_host","xxxxx") register_cvar("amx_ccc_user","xxxxx") register_cvar("amx_ccc_pass","xxxxx") register_cvar("amx_ccc_db","xxxxx") set_task(1.0,"start_sql") } // Comunicate with MySQL, and set CVARs public start_sql() { new host[32], username[32], password[32], dbname[32], error[32] get_cvar_string("amx_ccc_host",host,32) get_cvar_string("amx_ccc_user",username,32) get_cvar_string("amx_ccc_pass",password,32) get_cvar_string("amx_ccc_db",dbname,32) dbc = dbi_connect(host,username,password,dbname,error,32) // If Fail... if (dbc == SQL_FAILED) { server_print("[CcC] Could Not Connect To Forum SQL Database^n") } // Or else it worked else { server_print("[CcC] Connected To Forum SQL^n") } // Quiery SQL for STEAMID, if STEAMID not found then kick public show_cccmembers() { SELECT `user_steamid` FROM `phpbbgames_users` WHERE `user_steamid` LIKE 'STEAM_0:1:6826255' // My STEAMID For now if (dbc == SQL_FAILED) { server_print("[CcC] Could Not Quiery Database^n") } else { server_print("[CcC] Quiery OK!^n") } }

For some reason, It isn't compling, any ideas what went wrong?
Also, am I going the right way?

Thanks
Saabir Salim
__________________
My Sites l Forum | Cold Chaos Clan | M+
saabirsa is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-08-2006 , 19:42  
Reply With Quote #5

dbi_query()
dbi_numrows()
dbi_result() - dbi_field()
dbi_close()
dbi_error()

Those are the functions for using a SQL server.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 03-08-2006 , 19:45  
Reply With Quote #6

Code:
SELECT `user_steamid` FROM `phpbbgames_users` WHERE `user_steamid` LIKE 'STEAM_0:1:6826255'
should be in the mysql_query function, not all by itself. And all the other lines like it.
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
saabirsa
Junior Member
Join Date: Feb 2005
Location: U.K.
Old 03-08-2006 , 20:29  
Reply With Quote #7

Hmm, can you guys by any chance post a cleaned up version, i'd be most grateful

(Still learning Small lol, this is the 1st project that Ive worked on with Small )

Thanks
Saabir Salim
__________________
My Sites l Forum | Cold Chaos Clan | M+
saabirsa is offline
Des12
Senior Member
Join Date: Jan 2005
Old 03-09-2006 , 16:54  
Reply With Quote #8

Code:
#include <amxmodx> #include <dbi>   new Sql:dbc new Result:result // Standerd Defines public plugin_init() { register_plugin("Check for STEAMID","0.0.1","Saabir Salim") register_cvar("amx_ccc_host","xxxxx") register_cvar("amx_ccc_user","xxxxx") register_cvar("amx_ccc_pass","xxxxx") register_cvar("amx_ccc_db","xxxxx") set_task(1.0,"start_sql") } // Comunicate with MySQL, and set CVARs public start_sql() { new host[32], username[32], password[32], dbname[32], error[32] get_cvar_string("amx_ccc_host",host,32) get_cvar_string("amx_ccc_user",username,32) get_cvar_string("amx_ccc_pass",password,32) get_cvar_string("amx_ccc_db",dbname,32) dbc = dbi_connect(host,username,password,dbname,error,32) // If Fail... if (dbc == SQL_FAILED) { server_print("[CcC] Could Not Connect To Forum SQL Database^n") } // Or else it worked else { server_print("[CcC] Connected To Forum SQL^n") } } // Quiery SQL for STEAMID, if STEAMID not found then kick public show_cccmembers() {     new query[256];     new authid[32] = "STEAM_0:1:6826255";     format(query,255,"SELECT user_steamid FROM phpbbgames_users WHERE user_steamid='%s'",authid); result = dbi_query(dbc, query); }

I used a slightly different method of obtaining the data
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 03-09-2006 , 17:01  
Reply With Quote #9

Use dbi_query(sql , "%s" , query) if you are going to do that...Someone didn't read BAILOPAN's post about proper use of formatting.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Des12
Senior Member
Join Date: Jan 2005
Old 03-09-2006 , 17:13  
Reply With Quote #10

Thats how I was brought up to code SQL in AMXX, so how would you use your way?
__________________
-Dest Romano

www.JustRP.com
A TSRP Server

Quote:
Originally Posted by Brad
Don't you go be bringing reality into this.
Des12 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:28.


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