AlliedModders

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

saabirsa 03-07-2006 16:11

SQL Plugin
 
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 03-08-2006 09:11

Bump :)

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

Thanks
Saabir Salim

Des12 03-08-2006 18:20

dbi_connect

saabirsa 03-08-2006 19:40

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

Xanimos 03-08-2006 19:42

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

Those are the functions for using a SQL server.

GHW_Chronic 03-08-2006 19:45

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.

saabirsa 03-08-2006 20:29

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 :P)

Thanks
Saabir Salim

Des12 03-09-2006 16:54

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

Xanimos 03-09-2006 17:01

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.

Des12 03-09-2006 17:13

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


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

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