Raised This Month: $32 Target: $400
 8% 

Online Vips


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-11-2020 , 11:27   Online Vips
Reply With Quote #1

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);
        }
    }

__________________
Napoleon_be is online now
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-11-2020 , 14:42   Re: Online Vips
Reply With Quote #2

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.
__________________

Last edited by OciXCrom; 01-11-2020 at 14:44.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-12-2020 , 00:08   Re: Online Vips
Reply With Quote #3

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.
__________________
@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-12-2020 at 00:09.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-12-2020 , 07:49   Re: Online Vips
Reply With Quote #4

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) ) 
__________________

Last edited by Napoleon_be; 01-12-2020 at 07:52.
Napoleon_be is online now
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-12-2020 , 08:37   Re: Online Vips
Reply With Quote #5

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.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-12-2020 , 09:33   Re: Online Vips
Reply With Quote #6

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;

__________________

Last edited by Napoleon_be; 01-12-2020 at 09:39.
Napoleon_be is online now
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-12-2020 , 10:13   Re: Online Vips
Reply With Quote #7

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?
__________________

Last edited by OciXCrom; 01-12-2020 at 10:13.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-12-2020 , 10:34   Re: Online Vips
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
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.
__________________
Napoleon_be is online now
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-12-2020 , 18:08   Re: Online Vips
Reply With Quote #9

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.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply



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 07:27.


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