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

Solved [CS:GO] Not working as intended.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 14:45   [CS:GO] Not working as intended.
Reply With Quote #1

PHP Code:
public Action CP_OnChatMessage(intauthorArrayList recipientschar[] flagstringchar[] namechar[] messageboolprocesscolorsboolremovecolors)
{
    
char ip[32], steamid[32];
    
GetClientIP(authoripsizeof(ip)); 
    
GetClientAuthId(authorAuthId_Steam2steamidsizeof(steamid));

    if(
StrContains(message"test") != -1)
    {
        if(!
IsUserWarned[author]){
            
CPrintToChat(author"Test warn message");
            
IsUserWarned[author] = true;
        }else{
            
SourceBans_BanPlayer(0author1"Somereason");
            
LogToFile(logfile"[%s/%s] %N: (%s) "steamidipauthormessage);
        }
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;

What I'm trying to do I guess you can figure up by the code, but it doesn't work. It will print the message and not do what it's supposed, if I simply add "SourceBans_BanPlayer(0, author, 1, "Somereason");" and than I return Plugin_Stop; it's working, but i'm trying to achive something else.
__________________

Last edited by PinHeaDi; 02-23-2018 at 12:10.
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 16:23   Re: [CS:GO] Not working as intended.
Reply With Quote #2

you have to be a little more clear in your statements for help. You're saying it will print the warning message but not ban the player the second time they type it? but you're then stating that now you are adding the ban function and it's working with plugin_stop return but also that you want to achieve something different? you're not wanting to ban the player? What are you trying to achieve that's different? Are you resetting the IsUserWarned variable after banning the player so the next user with that index isn't already set to true?
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 16:42   Re: [CS:GO] Not working as intended.
Reply With Quote #3

This is what I'm trying to achieve:

If they first say "test"(which will be changed later) the plugins won't print that message and will tell them "If you type that again you'll be banned"(example). When you type "test" again, again it won't print the message and will ban you.

This is working:

PHP Code:
public Action CP_OnChatMessage(intauthorArrayList recipientschar[] flagstringchar[] namechar[] messageboolprocesscolorsboolremovecolors)
{
    
char ip[32], steamid[32];
    
GetClientIP(authoripsizeof(ip)); 
    
GetClientAuthId(authorAuthId_Steam2steamidsizeof(steamid));

    if(
StrContains(message"test") != -1)
    {
        
SourceBans_BanPlayer(0author1"Somereason");
        
LogToFile(logfile"[%s/%s] %N: (%s) "steamidipauthormessage);
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;

And this isn't (It prints "test" and does not ban or warn):

PHP Code:
public Action CP_OnChatMessage(intauthorArrayList recipientschar[] flagstringchar[] namechar[] messageboolprocesscolorsboolremovecolors)
{
    
char ip[32], steamid[32];
    
GetClientIP(authoripsizeof(ip)); 
    
GetClientAuthId(authorAuthId_Steam2steamidsizeof(steamid));

    if(
StrContains(message"test") != -1)
    {
        if(!
IsUserWarned[author]){
            
CPrintToChat(author"If you type that again you'll be banned");
            
IsUserWarned[author] = true;
        }else{
            
SourceBans_BanPlayer(0author1"Somereason");
            
LogToFile(logfile"[%s/%s] %N: (%s) "steamidipauthormessage);
        }
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;

The variable is resetting here, so they can receive one warning and than a ban and that's the best place to reset it for me:
PHP Code:
public void OnClientPutInServer(int client)
{
    
IsUserWarned[client] = false;

__________________

Last edited by PinHeaDi; 02-22-2018 at 16:47.
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 16:49   Re: [CS:GO] Not working as intended.
Reply With Quote #4

Okay so in the working sample is it just jumping directly to banning the player and not warning them? Is it just constantly giving the warning and not applying the ban? Is it banning and warning them but also continuing to print the message you're trying to block? The code logic looks alright, if neither of the if or else statements are getting to a point of execution then there's most likely an error that occurred before within the same scope and it's preventing the rest of the function from being executed
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 16:58   Re: [CS:GO] Not working as intended.
Reply With Quote #5

In the working sample it firing a ban directly without warning, doesn't warn them and doesn't print the message for which they're banned. Simple and plane.

But I want to add that warning, before the actual ban. So every time when a player join he gets !IsUserWarned[client](false) by default. So when he types the forbidden word in the chat, the plugins will stop that word from printing it in chat, it will trigger true on IsUserWarned[client], will get a warning about that and therefore will get banned the second time he types that.

There's the whole code:

PHP Code:
#include <sourcemod>
#include <chat-processor>
#include <sourcebans>
#include <multicolors>

bool IsUserWarned[MAXPLAYERS 1];

static const 
char logfile[] = "addons/sourcemod/logs/badword_bans.log";

public 
void OnClientPutInServer(int client)
{
    
IsUserWarned[client] = false;
}

public 
Action CP_OnChatMessage(intauthorArrayList recipientschar[] flagstringchar[] namechar[] messageboolprocesscolorsboolremovecolors)
{
    
char ip[32], steamid[32];
    
GetClientIP(authoripsizeof(ip)); 
    
GetClientAuthId(authorAuthId_Steam2steamidsizeof(steamid));

    if(
StrContains(message"test") != -1)
    {
        if(!
IsUserWarned[author]){
            
CPrintToChat(author"If you type that again you'll be banned");
            
IsUserWarned[author] = true;
        }else{
            
SourceBans_BanPlayer(0author1"Somereason");
            
LogToFile(logfile"[%s/%s] %N: (%s) "steamidipauthormessage);
        }
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;

__________________

Last edited by PinHeaDi; 02-22-2018 at 16:59.
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 17:02   Re: [CS:GO] Not working as intended.
Reply With Quote #6

If you load this sample while already connected to the server, the value of the bool may be set to true. You aren't defining in the creation to set all values to false. If you reconnect after the plugins loaded then it should work as intended. You can set the default value of the boolean array with:
PHP Code:
bool IsUserWarned[MAXPLAYERS+1] = {false, ...}; 
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 17:18   Re: [CS:GO] Not working as intended.
Reply With Quote #7

Well, for the first time, there's an error:

PHP Code:
L 02/23/2018 00:17:05: [SMException reportedCould not send a usermessage
L 02
/23/2018 00:17:05: [SMBlamingbadtag.smx
L 02
/23/2018 00:17:05: [SMCall stack trace:
L 02/23/2018 00:17:05: [SM]   [0PrintToChat
L 02
/23/2018 00:17:05: [SM]   [1Line 88D:\Sourcemod Plugins\include\multicolors/colors.inc::C_PrintToChat
L 02
/23/2018 00:17:05: [SM]   [2Line 76D:\Sourcemod Plugins\include\multicolors.inc::CPrintToChat
L 02
/23/2018 00:17:05: [SM]   [3Line 24D:\Sourcemod Plugins\badtag.sp::CP_OnChatMessage
L 02
/23/2018 00:17:05: [SM]   [5Call_Finish
L 02
/23/2018 00:17:05: [SM]   [6Line 274E:\Google Drive\Projects\Sourcemod\Public\Chat-Processor\scripting\chat-processor.sp::OnSayText2 
__________________
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 17:22   Re: [CS:GO] Not working as intended.
Reply With Quote #8

Oh that's a separate issue as well. You're using a print message inside another print message function. The way the source engine works with usermessages like SayText2 is by creating a buffer and writing to it with begin message and when it's finished and ready to be written to the client they use an EndMessage function. Pretty much a single threaded approach that wont allow separate user messages to be open at a time. You can't start a new message before the previous one has ended. Since this is a hook on the usermessage it falls in between that space and requires you to wait until after the message is finished. So just create a timer for a delay of 0.1 seconds with your message and which client to send the message to.

To be more clear those functions are called to safeguard the engine from corrupting the bit stream buffer. Writing bytes to this stream before the previous message has finished will definitely corrupt the stream and in turn make a few messages go out of sync with undefined behavior.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.

Last edited by backwards; 02-22-2018 at 17:26. Reason: more info
backwards is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 17:56   Re: [CS:GO] Not working as intended.
Reply With Quote #9

What the normal "say" that the engine uses, I can use instead of CP.
__________________
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 17:58   Re: [CS:GO] Not working as intended.
Reply With Quote #10

you will run into the same exact issue by using another chat message callback, however with other ones you may not be able to prevent the message from being processed unless it too is hooked in the middle of the user message stream being written. All you have to do is delay the chat message you want to send to the client
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards 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 17:38.


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