AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with in-game admin (https://forums.alliedmods.net/showthread.php?t=11030)

joecaprini 03-07-2005 21:28

Help with in-game admin
 
Does anyone know what is wrong with this code?

Code:
/* Admin Access by JoeCaprini Add access by amx_addadmin <steamid> <levels> To do: + Add remove function */ #include <amxmodx> new gFileLocation = "addons/amxmodx/configs/users.ini" new gTextName public plugin_init() {     register_plugin("Admin Access","1.1","JoeCaprini")     register_clcmd("amx_addadmin","addadmin",ADMIN_BAN,"- Adds an admin") } public addadmin(id) {     new adminid[32]     new accesslvls[32]     if(read_argc() == 0)     {         client_print(id,print_console,"Usage: amx_addadmin <steamid> <access levels>")         return PLUGIN_HANDLED     }     if(read_argc() < 2)     {         client_print(id,print_console,"[AMX] Must have an ID and the ACCESS LEVELS!")         return PLUGIN_HANDLED     }     read_argv(1,adminid,31)     read_argv(2,accesslvls,31)     if(containi(gFileLocation,adminid)     {         client_print(id,print_console,"[AMX] User is already an admin")         return PLUGIN_HANDLED     }     format(gTextName,"^"%s^" ^"^" ^"%s^"",adminid,accesslvls)     write_file(gFileLocation,gTextName,-1)     return PLUGIN_CONTINUE } public removeadmin(id) {     new adminremove[32]     new getline     new adminlook[32]     read_argv(1,adminremove,31)     if(read_argc() == 0)     {         client_print(id,print_console,"[AMX] Must specify a user")         return PLUGIN_HANDLED     }     format(gTextName,";")     read_file(gFileLocation,getline,adminlook,31)     if(adminlook == adminremove)     {         write_file(gFileLocation,gTextName,getline)         return PLUGIN_CONTINUE     }     return PLUGIN_CONTINUE }

I know there is already a plugin like this but I'm trying to learn how to do it.

XunTric 03-08-2005 13:12

Your using clcmd... Now everyone on your server can add and remove admins :P

joecaprini 03-08-2005 15:11

Code:
register_clcmd("amx_addadmin","addadmin",ADMIN_BAN,"- Adds an admin")

Only people with ban access can :lol:

XunTric 03-08-2005 15:14

Ops sorry... my eyes... :P

And show us the errors when you compile, or explain whats wrong with it...?

EDIT:
You forgot } at the end of the plugin...

joecaprini 03-08-2005 15:56

Code:

//// addadmin.sma
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(38) : error 035: argument type mismatch (argument 1)
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(43) : error 035: argument type mismatch (argument 1)
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(44) : error 035: argument type mismatch (argument 1)
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(59) : error 035: argument type mismatch (argument 1)
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(60) : error 035: argument type mismatch (argument 1)
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(61) : error 033: array must be indexed (variable "adminlo
ok")
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(63) : error 035: argument type mismatch (argument 1)
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(67) : warning 203: symbol is never used: "getline"
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(67) : warning 203: symbol is never used: "gFileLocation"
// C:\Valve\Steam\SteamApps\juggernaut817\dedicated server\czero\addons\amxmodx\
scripting\addadmin.sma(67) : warning 203: symbol is never used: "gTextName"
//
// 7 Errors.
// Could not locate output file compiled\addadmin.amx (compile failed).
//
// Compilation Time: 0.3 sec
// ----------------------------------------

Press enter to exit ...

Yea I have the } at the end I just accidentally fogot it in the post.

xeroblood 03-08-2005 16:50

Yes Actually, anyone could run that command, because you forgot to restrict it with:
Code:
if( !cmd_access( id, lvl, cid, 2 ) )     return PLUGIN_HANDLED

And you forgot to register a client command to remove admins (you have the function for it)..

And the following just wont work, you need to read the file contents line by line, and compare each line.. not the file name..
Code:
if(containi(gFileLocation,adminid)

You have alot of errors, both syntax and logic, and you need to think it through alot more... mainly your file access commands and logic.. look at some examples from other plugins which do this...

I could fix you plugin for you, but that basically means rewriting the entire thing myself, and that would spoil the fun for you.. Keep trying tho, and study!!


Edit: here, I removed the syntax errors, but the logic is still wrong, and I can GUARANTEE this wont work still even tho it compiles fine.. it is logically incorrect...
Code:
#include <amxmodx> #include <amxmisc> new gFileLocation[] = "addons/amxmodx/configs/users.ini" new gTextName[32] public plugin_init() {     register_plugin("Admin Access","1.1","JoeCaprini")     register_clcmd("amx_addadmin","addadmin",ADMIN_BAN," <steamid> <access levels>") } public addadmin(id,lvl,cid) {     if( !cmd_access( id, lvl, cid, 2 ) )         return PLUGIN_HANDLED     new adminid[32]     new accesslvls[32]     read_argv(1,adminid,31)     read_argv(2,accesslvls,31)     if( containi(gFileLocation,adminid) > -1 )     {         client_print(id,print_console,"[AMX] User is already an admin")         return PLUGIN_HANDLED     }     format(gTextName,31,"^"%s^" ^"^" ^"%s^"",adminid,accesslvls)     write_file(gFileLocation,gTextName,-1)     return PLUGIN_CONTINUE } public removeadmin(id) {     new adminremove[32]     new len, getline = 0     new adminlook[32]     read_argv(1,adminremove,31)     if(read_argc() == 0)     {         client_print(id,print_console,"[AMX] Must specify a user")         return PLUGIN_HANDLED     }     format(gTextName,31,";")     read_file(gFileLocation,getline,adminlook,31,len)     if(equali(adminlook,adminremove))     {         write_file(gFileLocation,gTextName,getline)         return PLUGIN_CONTINUE     }     return PLUGIN_CONTINUE }

MrSlatu 11-20-2005 13:00

if you ever finish
 
If you ever get that removeadmin code to work post it!!! I know lots of people who would love you for that code including myself, since it is a pain for me to edit my users.ini with the way I have my server set up.


All times are GMT -4. The time now is 14:13.

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