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

Solved chat message just for admins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-18-2021 , 10:43   chat message just for admins
Reply With Quote #1

hello. I'm trying to show an message just for admins, how could i do this ?

PHP Code:
public adminmenu_handler(idkey){
    switch(
key){
        case 
0: {
            new 
name[MAX_PLAYERS 1]
            
get_user_name(idnamecharsmax(name))
            if(
AntiChanger){
                
AntiChanger false
                server_cmd
("amx_cvar anti_steamid_changer 1")
                if(
get_user_flags(id) & ADMIN_KICKColorChat(0GREEN"%s Admin^4 %s^1enabled Anti SteamID Changer!"tagname)
                } else if (!
AntiChanger){
                
AntiChanger true
                server_cmd
("amx_cvar anti_steamid_changer 0")
                if(
get_user_flags(id) & ADMIN_KICKColorChat(0GREEN"%s Admin^4 %s^1disabled Anti SteamID Changer!"tagname)
            }    
            
adminmenu(id)
        }
        
        case 
9:{
            
menuVIP(id)
        }
    }


Last edited by lexzor; 01-18-2021 at 11:46.
lexzor is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-18-2021 , 10:46   Re: chat message just for admins
Reply With Quote #2

Just loop through all players and pass the player index in the first parameter of the ColorChat function instead of 0.

By the way, this is a steam only forum.
__________________









Last edited by CrazY.; 01-18-2021 at 10:47.
CrazY. is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-18-2021 , 10:55   Re: chat message just for admins
Reply With Quote #3

so i should do smth like this

PHP Code:
public init()
g_maxplayers get_maxplayers

public try(){
for(
i=1i<=g_maxplayersi++){
 if(
is_user_admin(id)) ColorChat(idGREEN"message")
}} 

Last edited by lexzor; 01-18-2021 at 10:55.
lexzor is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-18-2021 , 10:57   Re: chat message just for admins
Reply With Quote #4

No, you should use get_players() to get all connected players and loop the result.
__________________

Last edited by OciXCrom; 01-18-2021 at 10:57.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
lexzor
Veteran Member
Join Date: Nov 2020
Old 01-18-2021 , 11:03   Re: chat message just for admins
Reply With Quote #5

is this correct?

PHP Code:
public adminmenu_handler(idkey){
    switch(
key){
        case 
0: {
            new 
players[32], inumiPlayer
            
new name[MAX_PLAYERS 1]
            
get_user_name(idnamecharsmax(name))
            if(
AntiChanger){
                
AntiChanger false
                server_cmd
("amx_cvar anti_steamid_changer 1")
                } else if (!
AntiChanger){
                
AntiChanger true
                server_cmd
("amx_cvar anti_steamid_changer 0")
            }
            
get_players(playersinum)
            for (new 
i=1i<=inumi++){
                
players[i] = iPlayer
                
if(get_user_flags(iPlayer) & ADMIN_FLAGColorChat(idGREEN"%s Admin^4 %s^1%s Anti SteamID Changer!"tagnameAntiChanger "enabled" "disabled")
            }
            
adminmenu(id)
        }
        
        case 
9:{
            
menuVIP(id)
        }
    }

and should i use switch to check that boolean? idk if it's a good idea to use switch in a switch

Last edited by lexzor; 01-18-2021 at 11:08.
lexzor is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-18-2021 , 11:14   Re: chat message just for admins
Reply With Quote #6

You don't need the else if in this case. Replace:
Code:
else if (!AntiChanger)
with
Code:
else

and
Code:
for (new i=1, i<=inum; i++)
{
	players[i] = iPlayer

	if(get_user_flags(iPlayer) & ADMIN_FLAG)
		ColorChat(id, GREEN, "%s Admin^4 %s^1%s Anti SteamID Changer!", tag, name, AntiChanger ? "enabled" : "disabled")
}
with

Code:
for (new i=0, i<inum; i++)
{
	iPlayer = players[i]
	if(get_user_flags(iPlayer) & ADMIN_FLAG)
		ColorChat(iPlayer, GREEN, "%s Admin^4 %s^1%s Anti SteamID Changer!", tag, name, AntiChanger ? "enabled" : "disabled")
}
Also, this
Code:
new name[MAX_PLAYERS + 1]
should be
Code:
new name[MAX_NAME_LENGTH]
or simply
Code:
new name[32]
__________________









Last edited by CrazY.; 01-18-2021 at 11:17.
CrazY. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-18-2021 , 11:18   Re: chat message just for admins
Reply With Quote #7

lets follow the rules no steam no support.


Quote:
Originally Posted by lexzor View Post
hello. I'm trying to show an message just for admins, how could i do this ?

PHP Code:
public adminmenu_handler(idkey){
    switch(
key){
        case 
0: {
            new 
name[MAX_PLAYERS 1]
            
get_user_name(idnamecharsmax(name))
            if(
AntiChanger){
                
AntiChanger false
                server_cmd
("amx_cvar anti_steamid_changer 1")
                if(
get_user_flags(id) & ADMIN_KICKColorChat(0GREEN"%s Admin^4 %s^1enabled Anti SteamID Changer!"tagname)
                } else if (!
AntiChanger){
                
AntiChanger true
                server_cmd
("amx_cvar anti_steamid_changer 0")
                if(
get_user_flags(id) & ADMIN_KICKColorChat(0GREEN"%s Admin^4 %s^1disabled Anti SteamID Changer!"tagname)
            }    
            
adminmenu(id)
        }
        
        case 
9:{
            
menuVIP(id)
        }
    }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-18-2021 at 11:18.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-18-2021 , 15:24   Re: chat message just for admins
Reply With Quote #8

Or simply use my CromChat library instead of ColorChat:

Code:
CC_SendAdminMessage("c", true, "%s Admin %s bla bla", tag, name)
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-18-2021 , 15:30   Re: chat message just for admins
Reply With Quote #9

Quote:
Originally Posted by lexzor View Post
hello. I'm trying to show an message just for admins, how could i do this ?
Function already exists in AMX Mod X: amx_chat.
__________________
fysiks 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 19:00.


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