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

Solved [CS:GO] Not working as intended.


Post New Thread Reply   
 
Thread Tools Display Modes
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 18:04   Re: [CS:GO] Not working as intended.
Reply With Quote #11

How about if a create a timer, that will fire CPrintToChat(author, "If you type that again you'll be banned"); after 1 second.
__________________
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 18:05   Re: [CS:GO] Not working as intended.
Reply With Quote #12

Quote:
Originally Posted by PinHeaDi View Post
How about if a create a timer, that will fire CPrintToChat(author, "If you type that again you'll be banned"); after 1 second.
yes that's exactly what I meant when I wrote:

Quote:
Originally Posted by 1337norway
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
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 18:10   Re: [CS:GO] Not working as intended.
Reply With Quote #13

How can I store the message outside of CP_OnChatMessage, so that I can print it in the timer? Example:

CreateTimer(1.0, warntheplayer, GetClientUserId(client));

PHP Code:
public Action warntheplayer(Handle timerint userid)
{
   
int client GetClientOfUserId(userid);
   if(
client == 0) return;

   
CPrintToChat(author"You were warned for this message: %s"message);

__________________

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

you want to use a datapack for this:
https://sm.alliedmods.net/new-api/datapack/DataPack

You create a datapack and push each argument type you want into it. Then you pass the created datapack into the function where you are currently using the client's userid. Then you read the pack within callback of the timer and close the handle to it. You'd want to push the userid of the client as the first arg and then the string message following to read from.
__________________
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 , 18:24   Re: [CS:GO] Not working as intended.
Reply With Quote #15

Something like that?

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]){
            
DataPack store = new DataPack();
            
store.WriteString(message);

            
IsUserWarned[author] = true;
            
CreateTimer(1.0warntheplayerGetClientUserId(client));
        }else{
            
SourceBans_BanPlayer(0author1"Somereason");
            
LogToFile(logfile"[%s/%s] %N: (%s) "steamidipauthormessage);
        }
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;



public 
Action warntheplayer(Handle timerint userid)
{
   
int client GetClientOfUserId(userid);
   if(
client == 0) return;

   
char message[256];
   
store.ReadString(message256);

   
CPrintToChat(client"{green}%s" ,message)

   
DestroyDataPack(store);

Nope, not at all.
__________________

Last edited by PinHeaDi; 02-22-2018 at 18:27.
PinHeaDi is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-22-2018 , 18:40   Re: [CS:GO] Not working as intended.
Reply With Quote #16

Well... Figured out the error, I guess, I shold've used CreateDataTimer, but I can't figure up how to store "userid" in the datapack.
__________________
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-22-2018 , 19:05   Re: [CS:GO] Not working as intended.
Reply With Quote #17

Something similar to this

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]){
            new 
Handle:dpinfo CreateDataPack();
            
WritePackCell(dpinfoGetClientUserId(author));
            
WritePackString(dpinfomessage);

            
IsUserWarned[author] = true;
            
CreateTimer(1.0warntheplayerdpinfo);
        }else{
            
SourceBans_BanPlayer(0author1"Somereason");
            
LogToFile(logfile"[%s/%s] %N: (%s) "steamidipauthormessage);
        }
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;



public 
Action warntheplayer(Handle timerHandle:data)
{
    if(
data == INVALID_HANDLE)
        return 
Plugin_Stop;

    
ResetPack(data);
    
int client GetClientOfUserId(ReadPackCell(data));
    if(
client == 0)
    {
        
CloseHandle(data);
        return 
Plugin_Stop;
    }
    
char message[256];
    
ReadPackString(datamessagesizeof(message));

    
CPrintToChat(client"{green}%s" ,message)

    
CloseHandle(data);
    return 
Plugin_Stop;

__________________
I highly recommend joining the SourceMod Discord Server for real time support.

Last edited by backwards; 02-23-2018 at 08:41.
backwards is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 02-23-2018 , 07:22   Re: [CS:GO] Not working as intended.
Reply With Quote #18

PHP Code:
L 02/23/2018 14:21:38: [SMException reportedClient index 5462 is invalid
L 02
/23/2018 14:21:38: [SMBlamingChatProcessor/chat-processor.smx
L 02
/23/2018 14:21:38: [SMCall stack trace:
L 02/23/2018 14:21:38: [SM]   [0IsClientInGame
L 02
/23/2018 14:21:38: [SM]   [1Line 383E:\Google Drive\Projects\Sourcemod\Public\Chat-Processor\scripting\chat-processor.sp::Frame_OnChatMessage_SayText2
L 02
/23/2018 14:21:39: [SMException reportedDataPack operation is out of bounds.
L 02/23/2018 14:21:39: [SMBlamingbadtag.smx
L 02
/23/2018 14:21:39: [SMCall stack trace:
L 02/23/2018 14:21:39: [SM]   [0ReadPackCell
L 02
/23/2018 14:21:39: [SM]   [1Line 179D:\Sourcemod Plugins\badtag.sp::warntheplayer 
__________________
PinHeaDi is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 02-23-2018 , 08:45   Re: [CS:GO] Not working as intended.
Reply With Quote #19

maybe try without the resetpack function call
__________________
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-23-2018 , 12:10   Re: [CS:GO] Not working as intended.
Reply With Quote #20

https://forums.alliedmods.net/showpo...80&postcount=3

This was the solution. Thank you @1337norway, also to @Chaosxk.
__________________
PinHeaDi 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 10:39.


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