AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Online Vips (https://forums.alliedmods.net/showthread.php?t=320826)

Napoleon_be 01-11-2020 11:27

Online Vips
 
I'm trying to display the current online vips on the server but i'm having some trouble.

This is how my current code looks like, and it's showing the message on a new line every single time.
How do i fix this?

PHP Code:

public VipsOnline(id
{
    new 
szPlayers[32], iNumszName[33];
    
get_players(szPlayersiNum);
    
    for(new 
iiNumi++)
    {
        if(
get_user_flags(szPlayers[i]) & VIP_LEVEL)
        {
            
get_user_name(szPlayers[i], szNamecharsmax(szName));
            
ColorChat(idGREEN"Online Vips: %s |"szName);
        }
    }



OciXCrom 01-11-2020 14:42

Re: Online Vips
 
You're displaying the message for each loop cycle. Only get the names in the loop and store them in a variable using "formatex" and/or "format", then display the formatted message (the variable) outside the loop.

Natsheh 01-12-2020 00:08

Re: Online Vips
 
PHP Code:

public check_vips(id)
{
    new 
sBuffer[128], sVipname[32], sSlots[34], useridvsi
    
    formatex
(sBuffercharsmax(sBuffer), "!t[-!gV!tI!gP's!t-] !gOnline: ")
    
    new 
z;
    if((
get_vips_online()) > 0)
    {
        new 
players[32], pnum
        get_players
(playerspnum"ch")
        
        for(
0pnumi++)
        {
            
userid players[i]
            
            if(!(
get_user_vip(userid) & read_flags(szFLAG)))
                continue;
            
            
vs ++;
            
get_user_name(useridsVipnamecharsmax(sVipname))
            
formatex(sSlotscharsmax(sSlots), "!t%s!g%s"sVipname== vs ".":", ")
            
add(sBuffercharsmax(sBuffer), sSlots)
        }
    }
    else
    {
        
add(sBuffercharsmax(sBuffer), "!tThere is no vip's !gOnline!")
    }
    
    
chat_message(idsBuffer)
}

stock get_vips_online()
{
    new 
players[32], pnumvsiuserid
    get_players
(playerspnum"ch")
    
    for(
0pnumi++)
    {
        
userid players[i]
        
        if(!(
get_user_vip(userid) & read_flags(szFLAG)))
            continue;
        
        
vs ++;
    }
    
    return 
vs


Heres an example.

Napoleon_be 01-12-2020 07:49

Re: Online Vips
 
I'm currently using this code which i kinda stole from another plugin. The problem is that it doesn't show the vips correctly. For players without the VIP flag, it will always show "No vips online", while people who have the VIP flag will always get a message that outputs all the player names in the server. Any idea how i can fix this?

PHP Code:

public VipsOnline(id) {
    new 
bool:IsFirst trueszMessage[256], iLenTempID;
    
    for(
TempID 0TempID <= get_maxplayers(); TempID++)
    {
        if( !
is_user_connected(TempID) || !(get_user_flags(id) & VIP_LEVEL) )
        {
            continue;
        }
        
        if( !
IsFirst )
        {
            
szMessage[iLen++] = ' ';
            
szMessage[iLen++] = '|';
            
szMessage[iLen++] = ' ';
        }
        
        
szMessage[iLen++] = '^x04';
        
szMessage[iLen] = EOS;
        
        
iLen += get_user_name(TempIDszMessage[iLen], charsmax(szMessage) - iLen);
        
        
szMessage[iLen++] = '^x01';
        
szMessage[iLen] = EOS;
        
        
IsFirst false;
    }
    
    if( 
IsFirst )
    {

        
ColorChat(idGREEN"There are no vips online.");
        return 
PLUGIN_HANDLED;
    }
    else
    {
        
ColorChat(idTEAM_COLOR"Online Vips: %s"szMessage);
        return 
PLUGIN_HANDLED;        
    }
    
    return 
PLUGIN_CONTINUE


EDIT: I might've found the reason for this isue, i was using "id" instead of "TempID" on this line
PHP Code:

if( !is_user_connected(TempID) || !(get_user_flags(id) & VIP_LEVEL) ) 


OciXCrom 01-12-2020 08:37

Re: Online Vips
 
It's because you're checking the flags of "id" (the person who used the command") instead of "TempID" (the loop-element).

Please use "get_players" instead of looping all indexes from 1 to 32.

Napoleon_be 01-12-2020 09:33

Re: Online Vips
 
something like this?

PHP Code:

public VipsOnline(id) {
    new 
bool:IsFirst true;
    new 
szMessage[256], iLenszPlayers[32], iNum;
    
    
get_players(szPlayersiNum);
    
    for(new 
iiNumi++)
    {
        if(!
is_user_connected(szPlayers[i]) || !(get_user_flags(szPlayers[i]) & VIP_LEVEL))
        {
            continue;
        }
        
        if(!
IsFirst)
        {
            
szMessage[iLen++] = ' ';
            
szMessage[iLen++] = '|';
            
szMessage[iLen++] = ' ';
        }
        
        
szMessage[iLen++] = '^x04';
        
szMessage[iLen] = EOS;
        
        
iLen += get_user_name(szPlayers[i], szMessage[iLen], charsmax(szMessage) - iLen);
        
        
szMessage[iLen++] = '^x01';
        
szMessage[iLen] = EOS;
        
        
IsFirst false;
    }
    
    if(
IsFirst)
    {

        
ColorChat(idGREEN"There are no vips online.");
        return 
PLUGIN_HANDLED;
    }
    else
    {
        
ColorChat(idTEAM_COLOR"Online Vips: %s"szMessage);
        return 
PLUGIN_HANDLED;        
    }
    
    return 
PLUGIN_CONTINUE;



OciXCrom 01-12-2020 10:13

Re: Online Vips
 
You don't need "is_user_connected". Use the flags provided by "get_players" - https://www.amxmodx.org/api/amxmodx/get_players

Even though this will probably work, what happens if you have more VIP users than the message can display?

Napoleon_be 01-12-2020 10:34

Re: Online Vips
 
Quote:

Originally Posted by OciXCrom (Post 2679904)
You don't need "is_user_connected". Use the flags provided by "get_players" - https://www.amxmodx.org/api/amxmodx/get_players

Even though this will probably work, what happens if you have more VIP users than the message can display?

Yea my bad, will edit this.

And that's a good question, i don't know to be honest lol.

OciXCrom 01-12-2020 18:08

Re: Online Vips
 
You can add a limit, e.g. 4 players max on a line. If the loop reaches 4, print the message and clear the formatex, then set the counter to 0 again.


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

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