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

Infractions - The Early Stages


Post New Thread Reply   
 
Thread Tools Display Modes
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-14-2017 , 13:30   Re: Infractions - The Early Stages
Reply With Quote #11

Quote:
Originally Posted by Headline View Post
reading information on OnMapStart and then write to it on OnMapEnd. Maybe something like this will start you off.
  • Create a KeyValues file structured like below
  • OnMapStart use FileToKeyValues to load KeyValues in
  • Cache KeyValues handle globally to allow us to lookup client info
  • OnClientPostAdminCheck search the tree for their steamid, if it exists set some boolean somewhere to true so we know they have some infraction count.

EDIT: Give me a few minutes I'll give you some code

Here's some inspiration
*snip*
Thank you for that, I'll be sure to use that as a good reference when writing my own file I/O

Quote:
Originally Posted by Peace-Maker View Post
You could have a look at this plugin which does most of what you want. I know you do this for learning purposes, but maybe you want to extend that plugin and add the other features you had in mind.
Wow, I'm honestly not sure how I didn't find that plugin. It does accomplish a lot of what I wanted out of Infractions, but like you said, this is a learning experience for me, and I get to customize it to my liking and add/remove features! I may look into what you suggested, but I'll see how everything goes, for now.

I haven't really had much time to compile and test the plugin, but I've got a dilemma that may or may not actually BE a dilemma. So, one of my cvars, sm_infractions_custom_command, can be used to set a custom external command (default is sm_slay). In OnPluginStart(), I have this written:
PHP Code:
AddCommandListener(CustomCallbackGetCustomCommandString(InfractionsCustomCommand)); 
GetCustomCommandString(ConVar custom) is a custom function I've written which returns the value of the cvar sm_infractions_custom_command so OnPluginStart() is less cluttered. What would happen with AddCommandListener() if the server had the cvar set to "", i.e. that the server does not wish to use a custom command?
I was thinking, maybe have a function somewhere that would call RemoveCommandListener() when the cvar is empty (""), and re-call AddCommandListener() when the cvar is set to a different value? Is that just making things overly complicated, or is it a failsafe?

Last edited by QuantumToast; 06-14-2017 at 13:32.
QuantumToast is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-14-2017 , 14:28   Re: Infractions - The Early Stages
Reply With Quote #12

Quote:
Originally Posted by QuantumToast View Post
Is that just making things overly complicated, or is it a failsafe?
Idk about it being a fail-safe, but yeah you should definitely handle that situation. I'd do it in exactly the way you described
headline is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-14-2017 , 16:32   Re: Infractions - The Early Stages
Reply With Quote #13

In the code below,
PHP Code:
InfractionsCooldown CreateConVar("sm_infractions_cooldown""7""Number of days between infraction cooldowns, set to 0 to never cooldown"true0.0); 
I am getting a tag mismatch warning when compiling. Is it because if I'm going to specify a minimum, I have to include the flags, because that argument comes first? Or, how would I correct this to specify a minimum of 0 and nothing else?
The API has the syntax for CreateConVar as:
PHP Code:
ConVar CreateConVar(const char[] name, const char[] defaultValue, const char[] descriptionint flagsbool hasMinfloat minbool hasMaxfloat max
Edit: Disregard, I figured out the problem, and at least that part's working, for now.

Last edited by QuantumToast; 06-14-2017 at 17:11.
QuantumToast is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-14-2017 , 17:13   Re: Infractions - The Early Stages
Reply With Quote #14

Quote:
Originally Posted by QuantumToast View Post
In the code below, I am getting a tag mismatch warning when compiling.
PHP Code:
InfractionsCooldown CreateConVar("sm_infractions_cooldown""7""Number of days between infraction cooldowns, set to 0 to never cooldown"_true0.0); 
Use _ to indicate you want the default value. This assumes there is one (and there is for CreateConVar, you can look at the actual native definition in the include file to see it).

Regarding SQL and a DB, for something like this you absolutely do want to use a DB. Since you aren't looking to share data over a network, you should use the built-in sqlite support in SM. Piggybacking off clientprefs might be possible, but probably more annoying than it's worth.

For banning, SM provides OnBanClient and OnBanIdentity forwards. For kicking, there's no forward but looking for the server command kickid rather than the SM command might work out better. (There's also banid and banip if for some reason the forwards for banning aren't sufficient.)

Last edited by Fyren; 06-14-2017 at 17:14.
Fyren is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-14-2017 , 17:42   Re: Infractions - The Early Stages
Reply With Quote #15

Quote:
Originally Posted by Fyren View Post
Regarding SQL and a DB, for something like this you absolutely do want to use a DB. Since you aren't looking to share data over a network, you should use the built-in sqlite support in SM. Piggybacking off clientprefs might be possible, but probably more annoying than it's worth.
Again, I do understand the advantages of SQL over a regular keyvalues file, but I'd literally have to ask someone to hand-hold me through it, since I have absolutely ZERO experience with anything related to SQL, aside from manually editing .db files.
Quote:
Originally Posted by Fyren View Post
For banning, SM provides OnBanClient and OnBanIdentity forwards. For kicking, there's no forward but looking for the server command kickid rather than the SM command might work out better. (There's also banid and banip if for some reason the forwards for banning aren't sufficient.)
Regarding your reference to kickid, would that only work if an admin ran kickid as opposed to sm_kick? That would be easier said than done, but most of the admins are familiar with sm_kick. People are stubborn, blah. I'd happily hook kickid instead, but....
QuantumToast is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-14-2017 , 18:32   Re: Infractions - The Early Stages
Reply With Quote #16

Honestly I think doing SQL is easier than reading/saving to a file, since a lot of the work is done for you
hmmmmm is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-14-2017 , 18:59   Re: Infractions - The Early Stages
Reply With Quote #17

Would either of you be so kind as to point me to a good tutorial for using SQL with Sourcemod? I tried using it before, for the Store plugin, and I was truly unsuccessful. If it changes anything, I'm running my server on its own remote gameserver, so I shouldn't be hosting the database from my local machine.
QuantumToast is offline
QuantumToast
Member
Join Date: May 2017
Location: US
Old 06-14-2017 , 19:59   Re: Infractions - The Early Stages
Reply With Quote #18

Well, here's some progress on the core functions before I start messing with keyvalue files and/or SQL databases. This is just a snippet of the whole source, but the program did successfully compile!
PHP Code:
*snip*
    
// Stuff
    
if(InfractionsCustomCommand != null)
    {
        
HookConVarChange(InfractionsCustomCommandOnCustomCommandChange);
    }
}

public 
void OnCustomCommandChange(ConVar convar, const char[] oldValue, const char[] newValue)
{
    if(
strcmp(newValue"") == 0// if the cvar string is empty "", meaning there is no custom command
    
{
        
RemoveCommandListener(CustomCallbackoldValue);
    }
    else
    {
        
RemoveCommandListener(CustomCallbackoldValue);
        
AddCommandListener(CustomCallbacknewValue);
    }
}

public 
bool IsCvarStringEmpty(ConVar convar)
{
    
char buffer[128];
    
convar.GetString(buffer,128);
    if(
strcmp(buffer"") == 0) return true;
    else return 
false;

Just checking if anyone's noticing any glaring issues...I know that just because a program compiles, doesn't mean it works correctly

Last edited by QuantumToast; 06-14-2017 at 20:04. Reason: Deprecated code, I don't have to use a buffer, since I have newValue
QuantumToast is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-14-2017 , 21:17   Re: Infractions - The Early Stages
Reply With Quote #19

Here's an example plugin that I got from here: https://forums.alliedmods.net/showthread.php?t=175245 and updated to new syntax.
Attached Files
File Type: sp Get Plugin or Get Source (SQL_Example.sp - 88 views - 3.0 KB)
hmmmmm is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-14-2017 , 23:23   Re: Infractions - The Early Stages
Reply With Quote #20

SM itself only runs kickid to actually kick anyone. It also only actually runs banid and banip to ban anyone. All roads lead to Rome, unless it's a road not built by SM.

If the purpose is to learn, then SQL seems to fit the bill if you don't know anything. There's SM docs about the SQL API, but they're not a tutorial on SQL itself. There are a million tutorials about SQL itself you can find online. It might be useful to download an sqlite shell from http://sqlite.org (docs) to play around with running queries by just typing them instead of having to run a SM script or an actual SQL server.
Fyren 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 15:27.


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