AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved chat message just for admins (https://forums.alliedmods.net/showthread.php?t=330056)

lexzor 01-18-2021 10:43

chat message just for admins
 
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)
        }
    }



CrazY. 01-18-2021 10:46

Re: chat message just for admins
 
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.

lexzor 01-18-2021 10:55

Re: chat message just for admins
 
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")
}} 


OciXCrom 01-18-2021 10:57

Re: chat message just for admins
 
No, you should use get_players() to get all connected players and loop the result.

lexzor 01-18-2021 11:03

Re: chat message just for admins
 
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

CrazY. 01-18-2021 11:14

Re: chat message just for admins
 
You don't need the else if in this case. Replace:
Code:

else if (!AntiChanger)
with :arrow:
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 :arrow:

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]

Natsheh 01-18-2021 11:18

Re: chat message just for admins
 
lets follow the rules no steam no support.


Quote:

Originally Posted by lexzor (Post 2733125)
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)
        }
    }




OciXCrom 01-18-2021 15:24

Re: chat message just for admins
 
Or simply use my CromChat library instead of ColorChat:

Code:
CC_SendAdminMessage("c", true, "%s Admin %s bla bla", tag, name)

fysiks 01-18-2021 15:30

Re: chat message just for admins
 
Quote:

Originally Posted by lexzor (Post 2733125)
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.


All times are GMT -4. The time now is 07:37.

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