AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   stock print (https://forums.alliedmods.net/showthread.php?t=320765)

Sanjay Singh 01-08-2020 07:58

stock print
 
I am trying to print a specific message to all admins only.
so is this possible to use like without using full colorchat stock becuz 1.9.0 already includes colorchat
client_print_color

PHP Code:

print_admin(00"Hi %s You're Admin"name)

stock print_admin(id, const msg[])
{
    new 
iPlayers[32], iPnumiPlayer
    get_players
(iPlayersiPnum)

    for(new 
0iPnumi++)
    {
        
iPlayer iPlayers[i]
        
        if(
get_user_flags(iPlayer) & ADMIN_CHAT)
            
client_print_color(iPlayer0msg)
    } 



OciXCrom 01-08-2020 10:00

Re: stock print
 
1. You defined the function with 2 arguments, but you're using 4.

2. Why do you need an "id" parameter in the function if it's going to send the message to a group of players?

3. You're missing "vformat".

4. You probably don't need the "stock" tag.

Sanjay Singh 01-08-2020 10:36

Re: stock print
 
Quote:

Originally Posted by OciXCrom (Post 2679404)
1. You defined the function with 2 arguments, but you're using 4.

2. Why do you need an "id" parameter in the function if it's going to send the message to a group of players?

3. You're missing "vformat".

4. You probably don't need the "stock" tag.

like this?
PHP Code:

print_admin(const id, const input[], any:...)
{
    new 
count 1players[32];
    static 
msg[191];
    
vformat(msg190input3);
    
    if(
id)
        
players[0] = id;
    else
        
get_players(playerscount"ch");
    
    for (new 
0counti++)
    {
        
players[i]
        if(
is_user_admin(x))
        
client_print_color(x0msg)
    }



Shadows Adi 01-09-2020 08:32

Re: stock print
 
You can try this:
PHP Code:

    stock print_admin(const id, const input[], any:...)
    {
        new 
count 1players[32]
        static 
msg[191]
        
vformat(msg190input3)
        
        
replace_all(msg190"!g""^4"// Green Color
        
replace_all(msg190"!y""^1"// Default Color
        
replace_all(msg190"!team""^3"// Team Color
        
replace_all(msg190"!team2""^0"// Team2 Color
        
        
if (idplayers[0] = id; else get_players(playerscount"ch")
        {
            for (new 
0counti++)
            {
                if (
is_user_connected(players[i]))
                {
                    
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
                    
write_byte(players[i]);
                    
write_string(msg);
                    
message_end();
                }
            }
        }
    } 


OciXCrom 01-09-2020 13:35

Re: stock print
 
@Shadows Adi - read the first post again.

PHP Code:

// You don't need an "id" parameter - you're sending the message to a GROUP of players.
print_admin(const id, const input[], any:...)
{
    
// Why is count = 1?
    
new count 1players[32];
    static 
msg[191];

    
// Use charsmax(msg) instead of 190.
    
vformat(msg190input3);
    
    
// Again not needed - only get_players() should stay.
    
if(id)
        
players[0] = id;
    else
        
get_players(playerscount"ch");
    
    for (new 
0counti++)
    {
        
players[i]

        
// Indentation or { brackets } after the check would be nice.
        
if(is_user_admin(x))
        
        
// Don't use "magic numbers". The second argument should be "print_team_default", not 0.
        
client_print_color(x0msg)
    }


Try to think what you're doing. If you went line by line through the code, you probably could have figured it out.
You simply need to send a message to all admins, so there's no "id" involved at all - the player sending the message (if existant) is not relevant.

Natsheh 01-09-2020 13:51

Re: stock print
 
Well he actually needs the parameter id? Don't he?
Let's call it instead sender.
PHP Code:

print_to_admins(const id, const input[], any:...)
{
    
// Why is count = 1?
    
new countplayers[32], szName[32];
    static 
msg[192];

    
// Use charsmax(msg) instead of 190.
    
vformat(msg191input3);
    
    
// Again not needed - only get_players() should stay.
    
get_players(playerscount"ch");
    
get_user_name(idszName31);
    
    for (new 
0counti++)
    {
        
players[i]

        
// Indentation or { brackets } after the check would be nice.
        
if(is_user_admin(x))
        
        
// Don't use "magic numbers". The second argument should be "print_team_default", not 0.
        
client_print_color(x0"(ADMINS) %s: %s"szNamemsg)
    }


Assuming thats why he needs the parameter id.

Also follow the guidance to get fully code optimization.

OciXCrom 01-09-2020 14:06

Re: stock print
 
He never mentioned that he wants to use the sender's name anywhere, so I'm working with the information he provided.

Sanjay Singh 01-09-2020 16:04

Re: stock print
 
I dont want to show sender, it should work like normal msg to all who have accsss flags.

Natsheh 01-10-2020 04:38

Re: stock print
 
Well your example here is wrong

"Hi %s You're Admin"

It clarify that you only need 1 receiver

Sanjay Singh 01-10-2020 06:37

Re: stock print
 
Quote:

Originally Posted by Natsheh (Post 2679617)
Well your example here is wrong

"Hi %s You're Admin"

It clarify that you only need 1 receiver

Actually I want it to be work like both types if possible.

like if am using like this
PHP Code:

print_color(0"ADMIN type /help for commands")
this will print to all admins 

But what if i want to add their names to in that
PHP Code:

print_color(0"ADMIN %s type /help for commands"adminname

I don't want to show the sender but I want the receiver name in the chat.


All times are GMT -4. The time now is 02:42.

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