AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how to deal with task spam? (https://forums.alliedmods.net/showthread.php?t=331796)

kww 04-07-2021 18:46

how to deal with task spam?
 
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

LondoN 04-07-2021 18:51

Re: how to deal with task spam?
 
Try removing the 'id+taskid' and just use 0 = for all players

jimaway 04-07-2021 19:12

Re: how to deal with task spam?
 
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

LondoN 04-07-2021 19:48

Re: how to deal with task spam?
 
Quote:

Originally Posted by jimaway (Post 2743370)
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.

kww 04-08-2021 10:12

Re: how to deal with task spam?
 
Quote:

Originally Posted by LondoN (Post 2743368)
Try removing the 'id+taskid' and just use 0 = for all players

not working. it have the same effect

Quote:

Originally Posted by jimaway (Post 2743370)
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 (Post 2743370)
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 (Post 2743374)
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

CrazY. 04-08-2021 13:04

Re: how to deal with task spam?
 
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


All times are GMT -4. The time now is 20:13.

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