Raised This Month: $51 Target: $400
 12% 

Solved Any way of formatting this better?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-21-2017 , 13:57   Any way of formatting this better?
Reply With Quote #1

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:

PHP Code:
#define HANDLESAY(%1) "StrContains(strMessage, \"%1\", false) != -1"

if(HANDLESAY("nasties") || HANDLESAY("naughty word")) 
Beware ye who enter


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.
404UserNotFound is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-21-2017 , 14:10   Re: Any way of formatting this better?
Reply With Quote #2

Quote:
Originally Posted by abrandnewday View Post
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.
headline is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-21-2017 , 14:18   Re: Any way of formatting this better?
Reply With Quote #3

Ah, so that thing is the "macro function". Got it. Won't use 'em then.

I'll check out your plugin too. I definitely need to push myself to learn keyvalues and properly doing config files.
404UserNotFound is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 01-21-2017 , 18:00   Re: Any way of formatting this better?
Reply With Quote #4

what the fuck dude just write a regex or something
Miu is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-21-2017 , 18:12   Re: Any way of formatting this better?
Reply With Quote #5

Quote:
Originally Posted by Miu View Post
what the fuck dude just write a regex or something
a naughty word regex
might as well just adapt Tay.ai into SourceBot.
It would fit in well with the csgo community atleast.

Last edited by Mitchell; 01-21-2017 at 18:15.
Mitchell is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-21-2017 , 18:43   Re: Any way of formatting this better?
Reply With Quote #6

Quote:
Originally Posted by Miu View Post
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.
404UserNotFound is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 01-23-2017 , 22:35   Re: Any way of formatting this better?
Reply With Quote #7

Quote:
Originally Posted by abrandnewday View Post
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
}

bool IsValidHex(const char[] sHex)
{
    if(
g_hRegexHex.Match(sHex))
    {
        return 
true;
    }
    return 
false;

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.
__________________

Last edited by ThatOneGuy; 01-23-2017 at 22:38.
ThatOneGuy is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-23-2017 , 23:44   Re: Any way of formatting this better?
Reply With Quote #8

Quote:
Originally Posted by ThatOneGuy View Post
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
}

bool IsValidHex(const char[] sHex)
{
    if(
g_hRegexHex.Match(sHex))
    {
        return 
true;
    }
    return 
false;

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.
I'll check 'em out!
404UserNotFound is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-24-2017 , 05:14   Re: Any way of formatting this better?
Reply With Quote #9

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.
friagram is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-24-2017 , 12:24   Re: Any way of formatting this better?
Reply With Quote #10

i hope people don't think I made the spoiler'd snippet

i didn't

creator of sourcebot did

s'why it's so messy
404UserNotFound 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 05:21.


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