Raised This Month: $41 Target: $400
 10% 

how to deal with task spam?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Member
Join Date: Feb 2021
Location: Russia
Old 04-07-2021 , 18:46   how to deal with task spam?
Reply With Quote #1

Hello ppl! I have some trouble with set_task. I'm catching a specified messages and if caught, i starting a task that displaying hud messages to players. But when i'm catching an msg it starts to spam hud msgs. What i made(it's just a part of my useless code):
Thanks in advance
PHP Code:
#include <amxmodx>
#include <csx>
#include <dhudmessage>

#define MESS_LEN     64
#define NAME_LEN     32

#define DH_R_STD     251
#define DH_G_STD     126
#define DH_B_STD     20
#define DH_XPOS         -1.0
#define DH_YPOS         0.63
#define HUD_SHIFT     0.04
#define DH_FX         0
#define DH_FX_TIME     0.0
#define DH_HOLD_TIME 2.7
#define DH_FADEIN     0.5
#define DH_FADEOUT     0.8

enum {
    
NO_MSG 0,
    
BOMB_PLANTED,
    
BOMB_DEFUSED
}

enum {
    
NO_WINNER 0,
    
W_TEAM_CT,
    
W_TEAM_T
}

new 
submsg NO_MSG

#define TASK_ID_XO 457

public plugin_init() {
    
register_plugin("messages""latest""kww")
    
    
register_message(get_user_msgid("TextMsg"), "onMessageSent")
    
    
register_event("HLTV""onRoundStart""a""1=0""2=0")
}

public 
onRoundStart() {    
    
//reset variables    
    
submsg NO_MSG
}

public 
bomb_planted(planter) {
    
get_user_name(planterg_mvpcharsmax(g_mvp))
}

public 
bomb_defused(defuser) {
    
get_user_name(defuserg_mvpcharsmax(g_mvp))
}

public 
onMessageSent(iMessageiDestid) {
    
//get message sent
    
static szMessage[MESS_LEN]
    
get_msg_arg_string(2szMessagecharsmax(szMessage))
    
    if(
equali(szMessage"#Bomb_Defused")) {
        
winnerTeam W_TEAM_CT
        submsg 
BOMB_DEFUSED
    
}
    else if(
equali(szMessage"#Target_Bombed")) {
        
winnerTeam W_TEAM_CT
        submsg 
BOMB_PLANTED
    
}
    
    
//if bomb defused or exploded then run task
    
if(winnerTeam) {
        
set_task(0.1"message_send"id TASK_ID_XO)
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}

public 
message_send(taskid) {
    new 
id taskid TASK_ID_XO 
    
// i think if onMessageSent() is calling every time when every player catching a message 
    // then task will run as many times as they receive message, so if 7 palyers on server then 7 tasks
    // will start(?) and i tried to get players' ids from started tasks and show hudmessages to them but failed 
    // and idk why
    
    
client_print(0print_console"[*] executed "//for debug
        
    //format 1st string
    
static szText[MESS_LEN]
    
formatex(szTextcharsmax(szText), "placeholder")
    
    
//show it
    
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
    
show_dhudmessage(idszText)
    
    
//format substring
    
new szSubText[MESS_LEN 2]
    switch(
submsg) {
        case 
BOMB_PLANTED: {
            
formatex(szSubTextcharsmax(szSubText), "Bomb exploded")
        }
        case 
BOMB_DEFUSED: {
            
formatex(szSubTextcharsmax(szSubText), "Bomb defused")
        }
        default:
            return 
PLUGIN_HANDLED
    
}
    
    
//show it too
    
set_hudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOS HUD_SHIFTDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT, -1)
    
show_hudmessage(idszSubText)
    return 
PLUGIN_HANDLED

full code, test it if u want to see what is happening

Last edited by kww; 04-08-2021 at 11:30.
kww is offline
LondoN
Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 04-07-2021 , 18:51   Re: how to deal with task spam?
Reply With Quote #2

Try removing the 'id+taskid' and just use 0 = for all players
__________________
LondoN is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 04-07-2021 , 19:12   Re: how to deal with task spam?
Reply With Quote #3

Code:
if(winnerTeam) {         set_task(0.1, "message_send", id + TASK_ID_XO)
any message sent on the server will cause the task to be set if winnerTeam = true


just get rid of the onMessageSent() and the 0.1 second task altogether and use csx forwards to send the hud messages

Last edited by jimaway; 04-07-2021 at 19:24.
jimaway is offline
LondoN
Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 04-07-2021 , 19:48   Re: how to deal with task spam?
Reply With Quote #4

Quote:
Originally Posted by jimaway View Post
Code:
if(winnerTeam) {         set_task(0.1, "message_send", id + TASK_ID_XO)
any message sent on the server will cause the task to be set if winnerTeam = true


just get rid of the onMessageSent() and the 0.1 second task altogether and use csx forwards to send the hud messages
CSX is much better but if he want's to block default messages still need to hook his way.
__________________
LondoN is offline
kww
Member
Join Date: Feb 2021
Location: Russia
Old 04-08-2021 , 10:12   Re: how to deal with task spam?
Reply With Quote #5

Quote:
Originally Posted by LondoN View Post
Try removing the 'id+taskid' and just use 0 = for all players
not working. it have the same effect

Quote:
Originally Posted by jimaway View Post
any message sent on the server will cause the task to be set if winnerTeam = true
i think you're wrong. Task starting when winnerTeam is not false

Quote:
Originally Posted by jimaway View Post
just get rid of the onMessageSent() and the 0.1 second task altogether and use csx forwards to send the hud messages
tbh i'm catching not only that 2 messages
PHP Code:
//what is in full code:
enum {
    
NO_MSG 0// 0
    
CT_WIN// 1
    
T_WIN// 2
    
TARGET_SAVED// 3
    
BOMB_PLANTED// 4
    
BOMB_DEFUSED// 5
    
HOSTAGES_RESCUED// 6
    
HOSTAGES_NOT_RESCUED// 7
    
VIP_ESCAPED// 8
    
VIP_ASSASSINATED // 9

Quote:
Originally Posted by LondoN View Post
CSX is much better but if he want's to block default messages still need to hook his way.
You're right, i'm blocking standard messages and sending hud messages instead

Last edited by kww; 04-08-2021 at 11:25.
kww is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 04-08-2021 , 13:04   Re: how to deal with task spam?
Reply With Quote #6

Either check if the task already exists before setting a new one or clear the hud before show_hudmessage.

https://www.amxmodx.org/api/amxmodx/task_exists
https://www.amxmodx.org/api/amxmodx/CreateHudSyncObj
https://www.amxmodx.org/api/amxmodx/ClearSyncHud
__________________
Accepting private $$$ plugins requests.

@Steam: crazy770
@Discord: CrazY.#5317

Website | Channel

CrazY. is offline
Reply


Thread Tools
Display Modes

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:23.


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