AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Capturing user's clcmds (https://forums.alliedmods.net/showthread.php?t=120551)

Dizzy 03-06-2010 01:13

Capturing user's clcmds
 
Was wondering how to go about doing this. What I have is a plugin that when a user says keywords, such as: nfs, stfu, or lag it ultimately plays a cooresponding sound (nfs.wav, stfu.wav, or lag.wav)..

As it is now, I have (eleven of each type):
11=> _clcmd("say COMMAND")
11=> _clcmd("say_team COMMAND")
11=> _concmd("COMMAND")

The script itself gets very messy and redundant and I'm a bit weak on using and capturing strings and needed a little help :)..

Ultimately I wanted one public play(id) function rather than a function for each sound (so it's easier for users and I to add new sounds with releases)

Here's the script so you can get an idea.

Code:
#include <amxmodx> #include <amxmisc> #define PLUGINNAME  "Type Sounds" #define VERSION     "1.4" #define AUTHOR      "Dizzy" #define CVAR_PLUGIN "amx_typesounds" #define CVAR_USES   "amx_typesounds_uses" #define CVAR_ADMIN  "amx_typesounds_ao" new uses[33] = "CVAR_USES"; public plugin_init() {     register_plugin("PLUGINNAME","VERSION","AUTHOR");         register_cvar("CVAR_PLUGIN","1");     register_cvar("CVAR_USES","5");     register_cvar("CVAR_ADMIN","0");     register_clcmd("say holyshit","holyshit");     register_clcmd("say lag","lag");     register_clcmd("say please","please");     register_clcmd("say nfs","nfs");     register_clcmd("say stfu","stfu");     register_clcmd("say english","english");     register_clcmd("say hugebitch","hugebitch");     register_clcmd("say haha","haha");     register_clcmd("say who","who");     register_clcmd("say hacks","hacks");     register_clcmd("say fag","fag");     register_clcmd("say_team holyshit","holyshit");     register_clcmd("say_team lag","lag");     register_clcmd("say_team please","please");     register_clcmd("say_team nfs","nfs");     register_clcmd("say_team stfu","stfu");     register_clcmd("say_team english","english");     register_clcmd("say_team hugebitch","hugebitch");     register_clcmd("say_team haha","haha");     register_clcmd("say_team who","who");     register_clcmd("say_team hacks","hacks");     register_clcmd("say_team fag","fag");     register_concmd("holyshit","holyshit");     register_concmd("lag","lag");     register_concmd("please","please");     register_concmd("nfs","nfs");     register_concmd("stfu","stfu");     register_concmd("english","english");     register_concmd("hugebitch","hugebitch");     register_concmd("haha","haha");     register_concmd("who","who");     register_concmd("hacks","hacks");     register_concmd("fag","fag");     register_event("ResetHUD","roundchange","b"); } public plugin_precache() {     precache_sound("misc/holyshit.wav");     precache_sound("misc/lag.wav");     precache_sound("misc/please.wav");     precache_sound("misc/nfs.wav");     precache_sound("misc/stfu.wav");     precache_sound("misc/english.wav");     precache_sound("misc/hugebitch.wav");     precache_sound("misc/haha.wav");     precache_sound("misc/who.wav");     precache_sound("misc/hacks.wav");     precache_sound("misc/fag.wav"); } public holyshit(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/holyshit");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public lag(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/lag");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public please(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/please");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public nfs(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/nfs");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public stfu(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/stfu");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public english(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/english");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public hugebitch(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/hugebitch");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public haha(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/haha");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public who(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/who");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public hacks(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/hacks");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public fag(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)     {         client_print (id, print_chat, "[Type Sounds]: The plugin is off!");         return PLUGIN_HANDLED;     }         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))         {             client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");             return PLUGIN_HANDLED;         }         return PLUGIN_CONTINUE;     }     if (uses[id] != 0)     {         client_cmd(0, "spk misc/fag");         uses[id]--;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");     return PLUGIN_HANDLED; } public roundchange(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)         return PLUGIN_HANDLED;     if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))             return PLUGIN_HANDLED;         uses[id] = CVAR_USES;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     uses[id] = CVAR_USES;     client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);     return PLUGIN_HANDLED; }

Yeah, I know, if I had it use one function it would be x11 smaller :P

Thanks in advance guys, you're always great help!

wrecked_ 03-06-2010 12:09

Re: Capturing user's clcmds
 
Put your words in the WORDS const and execute whatever in the code of the for loop.

Code:
new const WORDS[][] = {     "hacks",     "pro",     "lol" } public plugin_init() {     register_plugin( "Word Block Ex", "1", "Wrecked" )         register_clcmd( "say", "CMD_Say" )     register_clcmd( "say_team", "CMD_Say" ) } public CMD_Say( id ) {     new said[128]         read_argv( 1, said, 127 )         for( new i = 0; i < sizeof WORDS; i++ )     {         if( containi( said, WORDS[i] ) )         {             // ...         }     } }

Dizzy 03-06-2010 13:37

Re: Capturing user's clcmds
 
Hey wrecked, thanks for the response! I've just gotten two errors (which are really the same problem) while compiling and for some reason I can't figure it out.

Code:
#define CVAR_PLUGIN "amx_typesounds" #define CVAR_USES   "amx_typesounds_uses" #define CVAR_ADMIN  "amx_typesounds_ao" new uses[33] = "CVAR_USES"; ...     register_cvar("CVAR_PLUGIN","1");     register_cvar("CVAR_USES","5");     register_cvar("CVAR_ADMIN","0"); ...         uses[id] = CVAR_USES;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     uses[id] = CVAR_USES;

The lines that contain: uses[id] = CVAR_USES; throws an error saying: error 006: must be assigned to an array hmmm...

wrecked_ 03-06-2010 13:41

Re: Capturing user's clcmds
 
Well, first off, take the quotes off of the cvars "CVAR_PLUGIN", "CVAR_USES", and "CVAR_ADMIN".

Second, what are you trying to do? At the moment, your code hardly makes any sense.

Dizzy 03-06-2010 13:44

Re: Capturing user's clcmds
 
Yea, I just noticed that and made that switch to

Code:
    register_cvar(CVAR_PLUGIN, "1");     register_cvar(CVAR_USES, "5");     register_cvar(CVAR_ADMIN, "0");

What I'm ultimately trying to do is get what the users says in game and if it matches one of the WORDS play the cooresponding sound..

Ex: The users says: hacks

Recognize that they said one of the words and play misc/hacks.wav

Here's my full updated code

Code:
/////////////////////////////////////////////// //AMX[X]MOD:                                 // //          Type Sounds v1.4                 // //            By: Dizzy                      // //                                           // //SHORT DESCRIPTION:                         // //    Client command-based plugin that       // //returns sounds to key words (listed below) // //                                           // //                                           // //CVARS:                                     // //    amx_typesounds 0/1 (off/on)            // //    amx_typesounds_ao 0/1 (off/on)         // //              -Admins only                 // //    amx_typesounds_uses                    // //              -Uses per round              // //                                           // //CLCMDS:                                    // //    holyshit                               // //    lag                                    // //    please                                 // //    nfs                                    // //    stfu                                   // //    english                                // //    hugebitch                              // //    haha                                   // //    who                                    // //    hacks                                  // //    fag                                    // //                                           // /////////////////////////////////////////////// #include <amxmodx> #include <amxmisc> #define PLUGINNAME  "Type Sounds" #define VERSION     "1.4" #define AUTHOR      "Dizzy" #define CVAR_PLUGIN "amx_typesounds" #define CVAR_USES   "amx_typesounds_uses" #define CVAR_ADMIN  "amx_typesounds_ao" new uses[33] = "CVAR_USES"; new const WORDS[][] = {     "holyshit",     "lag",     "please",     "nfs",     "stfu",     "english",     "hugebitch",     "haha",     "who",     "hacks",     "fag" } public plugin_init() {     register_plugin(PLUGINNAME, VERSION, AUTHOR);         register_cvar(CVAR_PLUGIN, "1");     register_cvar(CVAR_USES, "5");     register_cvar(CVAR_ADMIN, "0");     register_clcmd("say","play");     register_clcmd("say_team","play");     register_event("ResetHUD","roundchange","b"); } public plugin_precache() {     precache_sound("misc/holyshit.wav");     precache_sound("misc/lag.wav");     precache_sound("misc/please.wav");     precache_sound("misc/nfs.wav");     precache_sound("misc/stfu.wav");     precache_sound("misc/english.wav");     precache_sound("misc/hugebitch.wav");     precache_sound("misc/haha.wav");     precache_sound("misc/who.wav");     precache_sound("misc/hacks.wav");     precache_sound("misc/fag.wav"); } public play(id) {     new said[128]     read_argv(1, said, 127)     for (new i = 0; i < sizeof WORDS; i++)     {         if (containi(said, WORDS[i]))         {             if (get_cvar_num(CVAR_PLUGIN) == 0)             {                 client_print (id, print_chat, "[Type Sounds]: The plugin is off!");                 return PLUGIN_HANDLED;             }                 if (get_cvar_num(CVAR_ADMIN) == 1)             {                 if (!is_user_admin(id))                 {                     client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");                     return PLUGIN_HANDLED;                 }                 return PLUGIN_CONTINUE;             }             if (uses[id] != 0)             {                 client_cmd(0, "spk misc/%s", WORDS[i]);                 uses[id]--;                 client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);                 return PLUGIN_HANDLED;             }             client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");             return PLUGIN_HANDLED;         }     }     return PLUGIN_HANDLED; } public roundchange(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)         return PLUGIN_HANDLED;     if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))             return PLUGIN_HANDLED;         uses[id] = CVAR_USES;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED;     }     uses[id] = CVAR_USES;     client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);     return PLUGIN_HANDLED; }

It errors at both lines all the way at the bottom that say:
Code:
uses[id] = CVAR_USES;

Bugsy 03-06-2010 13:46

Re: Capturing user's clcmds
 
uses[] is single dimension array. You are trying to assign a string value (an array of cells) to a single cell which will not work.

Assume id = 5 and 55, 43, 34, 90, 55 are all letters (in ascii value) stored in CVAR_USES. Below is what you're trying to do with that assignment.
uses[ 5 ] = { 55 , 43 , 34 , 90 , 55 };

I suggest explaining what you are doing instead of posting 100% useless code and asking why it doesn't work. We can then show you the correct\efficient way of doing it.

wrecked_ 03-06-2010 13:47

Re: Capturing user's clcmds
 
What is "uses[]" supposed to do / represent?

Also, use PCvars, they're much faster.

Dizzy 03-06-2010 13:48

Re: Capturing user's clcmds
 
My first post was the entire code before I tried using wrecked's string constants. I wasn't just posting snippets

@ Wrecked, uses is a value that an admin can edit while in game (via Cvar) to change the amount of times that a user can use the plugin before round reset

Dizzy 03-06-2010 13:52

Re: Capturing user's clcmds
 
The idea I was trying to accomplish was to reset the uses[id] back to CVAR_USES (which is constant and changeable)

wrecked_ 03-06-2010 13:54

Re: Capturing user's clcmds
 
This is my interpretation of what you're trying to do.
Code:
new uses[33] public play(id) {     new said[128]     read_argv(1, said, 127)         for (new i = 0; i < sizeof WORDS; i++)     {         if (containi(said, WORDS[i]))         {             uses[id]++                         if( uses[id] >= get_cvar_num( CVAR_USES ) )             {                 return PLUGIN_HANDLED;             }             if (get_cvar_num(CVAR_PLUGIN) == 0)             {                 client_print (id, print_chat, "[Type Sounds]: The plugin is off!");                                 return PLUGIN_HANDLED;             }                         if (get_cvar_num(CVAR_ADMIN) == 1)             {                 if (!is_user_admin(id))                 {                     client_print (id, print_chat, "[Type Sounds]: Sorry, you are not an Administrator!");                     return PLUGIN_HANDLED;                 }                                 return PLUGIN_CONTINUE;             }                         if (uses[id] != 0)             {                 client_cmd(0, "spk misc/%s", WORDS[i]);                 uses[id]--;                 client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);                                 return PLUGIN_HANDLED;             }             client_print (id, print_chat, "[Type Sounds]: Sorry, 0 sound left, wait until next round!");                         return PLUGIN_HANDLED;         }     }     return PLUGIN_HANDLED; } public roundchange(id) {     if (get_cvar_num(CVAR_PLUGIN) == 0)         return PLUGIN_HANDLED;         if (get_cvar_num(CVAR_ADMIN) == 1)     {         if (!is_user_admin(id))             return PLUGIN_HANDLED;                 uses[id] = CVAR_USES;         client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);                 return PLUGIN_HANDLED;     }     uses[id] = CVAR_USES;     client_print (id, print_chat, "[Type Sounds]: %d sound(s) left!", uses[id]);         return PLUGIN_HANDLED; }


All times are GMT -4. The time now is 08:46.

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