I'm messing around with the SourceBot plugin, doing the usual thing I tend to do, updating it to new syntax and seeing I can make anything interesting by modifying it.
I got to the HandleSay function, where the plugin does its chat scanning to see if someone is talking to it, then looks for key words and decides how to respond accordingly. As you'll see below, it's a lot (a metric fuck-ton) of StrContains set up in various ways.
For what it is, it's fine. It does its job good enough for my purposes. I'm really just wanting to expand it to give the thing more of a predefined dictionary so to speak, without adding too much code. I did try out this little idea:
So yeah, is there any better way of doing this? If there isn't really a better way to do this, well then I guess as my old man used to say; "You gotta piss with the cock you got."
Last edited by 404UserNotFound; 01-21-2017 at 14:18.
I'm really just wanting to expand it without adding too much code.
The problem is that everything is hard coded into the HandleSay... If I were you I'd have it parse a kv file which would contain all of these. I've done the same exact thing here using the contains trigger.
Also you probably shouldn't use macro functions anyway. Even though what Bailopan said is old, you might want to consider avoiding them.
what the fuck dude just write a regex or something
Have you not looked at regex code before? It's an unreadable clusterfuck nightmare mess. No thanks. I'd rather not drive myself insane trying to figure it out.
Have you not looked at regex code before? It's an unreadable clusterfuck nightmare mess. No thanks. I'd rather not drive myself insane trying to figure it out.
Not all that bad/hard actually. Here is an example that checks a hex code for validity:
PHP Code:
#include <regex>
Regex g_hRegexHex;
public void OnPluginStart() { g_hRegexHex = new Regex("([A-Fa-f0-9]{6})"); //just google regex generator and input what you want and let it kick out the regex for you - there are quite a few, with some better than others }
Additionally, you can also google "regex check for word", or "regex alphanumeric", etc, and it generally would show within a couple of results. Hope that helps.
Not all that bad/hard actually. Here is an example that checks a hex code for validity:
PHP Code:
#include <regex>
Regex g_hRegexHex;
public void OnPluginStart() { g_hRegexHex = new Regex("([A-Fa-f0-9]{6})"); //just google regex generator and input what you want and let it kick out the regex for you - there are quite a few, with some better than others }
Additionally, you can also google "regex check for word", or "regex alphanumeric", etc, and it generally would show within a couple of results. Hope that helps.
Try not to use the preprocessor for stuff like that. It serves Little purpose other than to reduce readability of code.
Imo variable defines is the only sane use aside from includes..
limited use of the if else are useful for debug output with some prints too..
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.