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

Solved troubles with TextMsg


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-16-2021 , 13:00   troubles with TextMsg
Reply With Quote #1

Hello. I'm trying to show defuser's/planter's name on dhud but defuser's name is not showing. what i'm doing wrong?

PHP Code:
//including all i need
#include <amxmodx>
#include <csx> //to get who's planted/defused the bomb
#include <dhudmessage> //to show message on screen

//created some vars
new g_teamname_ctg_teamname_t // for custom teamnames
new g_planter_name[32], g_defuser_name[32]

//registered cvars
public plugin_init() {
    
register_message(get_user_msgid("TextMsg"), "onMessageSent")
    
    
register_logevent("onFreezeEnd"2"1=Round_Start")
    
    
g_teamname_ct register_cvar("mp_teamname_ct""Counter-Terrorists"FCVAR_SERVER)
    
g_teamname_t register_cvar("mp_teamname_t""Terrorists"FCVAR_SERVER)
}
//clear playernames on freezetime end
public onFreezeEnd() {
    
g_defuser_name ""
    
g_planter_name ""
}

//get player name depending on the event
public bomb_defused(defuser) {
    
get_user_name(defuserg_defuser_namecharsmax(g_defuser_name))
}

public 
bomb_planted(planter) {
    
get_user_name(planterg_planter_namecharsmax(g_planter_name))
}

//catch bombed or defused
public onMessageSent(iMessageiDestid) {
    static 
szMessage[64]
    
get_msg_arg_string(2szMessagecharsmax(szMessage))
    
    static 
teamname[32]
    new 
szText[64*2]

    if(
equali(szMessage"#Bomb_Defused")) {
        
get_pcvar_string(g_teamname_ctteamnamecharsmax(teamname))
        
formatex(szTextcharsmax(szText), "%s Wins The Round^nMVP: %s for defusing the bomb"teamnameg_defuser_name)
        
         
//these values are predefined so dhud messages showng
        
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
        
show_dhudmessage(idszText)
        return 
PLUGIN_HANDLED
    
}
    else if(
equali(szMessage"#Target_Bombed")) {
        
get_pcvar_string(g_teamname_tteamnamecharsmax(teamname))
        
formatex(szTextcharsmax(szText), "%s Wins The Round^nMVP: %s for planting the bomb"teamnameg_planter_name)
        
        
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
        
show_dhudmessage(idszText)
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE


Last edited by kww; 03-19-2021 at 06:43. Reason: added includes used
kww is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 03-16-2021 , 14:23   Re: troubles with TextMsg
Reply With Quote #2

How are bomb_defused() and bomb_planted() called in your code?

Last edited by redivcram; 03-16-2021 at 14:23.
redivcram is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-16-2021 , 14:26   Re: troubles with TextMsg
Reply With Quote #3

Quote:
Originally Posted by redivcram View Post
How are bomb_defused() and bomb_planted() called in your code?
I've included <csx> and used mentioned forwards. Or what do u mean?

Last edited by kww; 03-16-2021 at 14:34.
kww is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-16-2021 , 17:07   Re: troubles with TextMsg
Reply With Quote #4

send the dhud messages straight from the csx forwards and get rid of the textmsg forward.
jimaway is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-16-2021 , 17:11   Re: troubles with TextMsg
Reply With Quote #5

You can solve this in two ways:
1. Setting a task when your message is triggered, because bomb_defused() forward is called after #Bomb_Defused cstrike message. Example:
PHP Code:
#include <amxmodx>
#include <csx> //to get who's planted/defused the bomb
#include <dhudmessage> //to show message on screen

//created some vars
new g_teamname_ctg_teamname_t // for custom teamnames
new g_planter_name[32], g_defuser_name[32]

//registered cvars
public plugin_init() {
    
register_message(get_user_msgid("TextMsg"), "onMessageSent")
    
    
register_logevent("onFreezeEnd"2"1=Round_Start")
    
    
g_teamname_ct register_cvar("mp_teamname_ct""Counter-Terrorists"FCVAR_SERVER)
    
g_teamname_t register_cvar("mp_teamname_t""Terrorists"FCVAR_SERVER)
}
//clear playernames on freezetime end
public onFreezeEnd() {
    
g_defuser_name ""
    
g_planter_name ""
}

//get player name depending on the event
public bomb_defused(defuser) {
    
get_user_name(defuserg_defuser_namecharsmax(g_defuser_name))
}

public 
bomb_planted(planter) {
    
get_user_name(planterg_planter_namecharsmax(g_planter_name))
}

//catch bombed or defused
public onMessageSent(iMessageiDestid) {
    static 
szMessage[64]
    
get_msg_arg_string(2szMessagecharsmax(szMessage))
    
    static 
teamname[32]
    new 
szText[64*2]

    if(
equali(szMessage"#Bomb_Defused")) {
        
set_task(0.2"task_show_defuser")
        return 
PLUGIN_HANDLED
    
}
    else if(
equali(szMessage"#Target_Bombed")) {
        
get_pcvar_string(g_teamname_tteamnamecharsmax(teamname))
        
formatex(szTextcharsmax(szText), "%s Wins The Round^nMVP: %s for planting the bomb"teamnameg_planter_name)
        
        
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
        
show_dhudmessage(0szText)
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}

public 
task_show_defuser()
{
    static 
teamname[32]
    new 
szText[128]
    
get_pcvar_string(g_teamname_ctteamnamecharsmax(teamname))
    
formatex(szTextcharsmax(szText), "%s Wins The Round^nMVP: %s for defusing the bomb"teamnameg_defuser_name)
    
     
//these values are predefined so dhud messages showng
    
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
    
show_dhudmessage(0szText)

2. You can do it in called forward for every event. Example:
PHP Code:
#include <amxmodx>
#include <csx> //to get who's planted/defused the bomb
#include <dhudmessage> //to show message on screen

enum _:Event
{
    
BombPlanted 0,
    
BombDefused
}

//created some vars
new g_teamname_ctg_teamname_t // for custom teamnames
new g_planter_name[32], g_defuser_name[32]

//registered cvars
public plugin_init() {
    
register_logevent("onFreezeEnd"2"1=Round_Start")
    
    
g_teamname_ct register_cvar("mp_teamname_ct""Counter-Terrorists"FCVAR_SERVER)
    
g_teamname_t register_cvar("mp_teamname_t""Terrorists"FCVAR_SERVER)
}
//clear playernames on freezetime end
public onFreezeEnd() {
    
g_defuser_name ""
    
g_planter_name ""
}

//get player name depending on the event
public bomb_defused(defuser) {
    
get_user_name(defuserg_defuser_namecharsmax(g_defuser_name))
    
ShowEvent(BombDefused)
}

public 
bomb_planted(planter) {
    
get_user_name(planterg_planter_namecharsmax(g_planter_name))
    
ShowEvent(BombPlanted)
}

public 
ShowEvent(Event:iType)
{
    static 
teamname[32]
    new 
szText[128]

    switch(
iType)
    {
        case 
BombPlanted:
        {
            
get_pcvar_string(g_teamname_tteamnamecharsmax(teamname))
            
formatex(szTextcharsmax(szText), "%s Wins The Round^nMVP: %s for planting the bomb"teamnameg_planter_name)
        
            
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
            
show_dhudmessage(0szText)
        }
        case 
BombDefused:
        {
            
get_pcvar_string(g_teamname_ctteamnamecharsmax(teamname))
            
formatex(szTextcharsmax(szText), "%s Wins The Round^nMVP: %s for defusing the bomb"teamnameg_defuser_name)
        
             
//these values are predefined so dhud messages showng
            
set_dhudmessage(DH_R_STDDH_G_STDDH_B_STDDH_XPOSDH_YPOSDH_FXDH_FX_TIMEDH_HOLD_TIMEDH_FADEINDH_FADEOUT)
            
show_dhudmessage(0szText)
        }
    }

Not tested the codes provided above.

Also, you could take a look on this MVP Plugin which provides more functionalities: https://forums.alliedmods.net/showthread.php?t=327690
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 03-18-2021 at 10:29. Reason: Edited first code
Shadows Adi is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-17-2021 , 09:23   Re: troubles with TextMsg
Reply With Quote #6

Quote:
Originally Posted by Shadows Adi View Post
... because bomb_defused() forward is called after #Bomb_Defused cstrike message
hmm... interesting. I didn't know about it. I'll try 1st way because it would suit me better, i think
EDIT: task give me many errors

Last edited by kww; 03-17-2021 at 09:56.
kww is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-17-2021 , 11:10   Re: troubles with TextMsg
Reply With Quote #7

Quote:
Originally Posted by kww View Post
hmm... interesting. I didn't know about it. I'll try 1st way because it would suit me better, i think
EDIT: task give me many errors
Edited the first code given, try it now. I didn't tested codes, could you post the errors?
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Old 03-17-2021, 17:25
kww
This message has been deleted by kww.
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-18-2021 , 06:37   Re: troubles with TextMsg
Reply With Quote #8

Quote:
Originally Posted by Shadows Adi View Post
Edited the first code given, try it now. I didn't tested codes, could you post the errors?
Ok, i compiled the code and it works but dhud not appears on bomb defuse.
kww is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-18-2021 , 06:59   Re: troubles with TextMsg
Reply With Quote #9

Quote:
Originally Posted by kww View Post
Ok, i compiled the code and it works but dhud not appears on bomb defuse.
Did you tried both codes?
Also, debug the code:
PHP Code:
public bomb_defused(defuser) {
    
get_user_name(defuserg_defuser_namecharsmax(g_defuser_name))
    
client_print(0print_chat"forward bomb_defused() called")

__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-18-2021 , 07:29   Re: troubles with TextMsg
Reply With Quote #10

Quote:
Originally Posted by Shadows Adi View Post
Did you tried both codes?
no. should i?
Quote:
Originally Posted by Shadows Adi View Post
Also, debug the code:
PHP Code:
public bomb_defused(defuser) {
    
get_user_name(defuserg_defuser_namecharsmax(g_defuser_name))
    
client_print(0print_chat"forward bomb_defused() called")

I made it right after starting this topic and it calling successfully every time it needed

Ok, I'll send dhud message right in bomb_defused() forward (but I didn't want to do it)

Last edited by kww; 03-18-2021 at 07:36.
kww 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 18:13.


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