AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Send message only admins (https://forums.alliedmods.net/showthread.php?t=318516)

skatz_ws 09-04-2019 16:54

Send message only admins
 
Im trying to send this message only to player whit the flag ADMIN_BAN

PHP Code:

new players[32], num
get_players
(playersnum"a");
for(new 
<= numi++)
{
    
tempid players[i]
    
    if (
get_user_flags(tempid) & ADMIN_BAN)
    {
        if(
is_user_alive(tempid))
            
ColorChat(tempidGREY"Test")
        else
            
ColorChat(tempidGREY"Test2")
    }


What happens is that is sending 2 messages to all players. Can someone fix?

OciXCrom 09-04-2019 17:11

Re: Send message only admins
 
In the loop body, the condition needs to be "i < num", not "i <= num".

There's no point of the "is_user_alive" check because you're using the "a" flag in "get_players" which returns only alive players. "Test2" will never be sent.

Apart from that, I don't see a reason why all players are seeing 2 messages. I feel like you didn't provide the right code.

iceeedr 09-04-2019 17:21

Re: Send message only admins
 
Quote:

Originally Posted by OciXCrom (Post 2665898)
I feel like you didn't provide the right code.

You see he creating the variable tempid?

OciXCrom 09-04-2019 20:59

Re: Send message only admins
 
Quote:

Originally Posted by iceeedr (Post 2665899)
You see he creating the variable tempid?

If the code works, I assume the variable is already created elsewhere. It doesn't matter where because inside the loop it will always hold a player's index. Assuming that the variable is actually an integer.

iceeedr 09-05-2019 00:00

Re: Send message only admins
 
Quote:

Originally Posted by OciXCrom (Post 2665926)
If the code works, I assume the variable is already created elsewhere. It doesn't matter where because inside the loop it will always hold a player's index. Assuming that the variable is actually an integer.

I think you did not understand the sarcasm well, finally, OP show us the whole function to be able to assist you in the best way.


All times are GMT -4. The time now is 17:16.

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