Raised This Month: $51 Target: $400
 12% 

sorting by HP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mazmaajinsh
Senior Member
Join Date: Apr 2005
Location: Latvia
Old 05-02-2011 , 17:29   sorting by HP
Reply With Quote #1

Hi guys.
I was wondering, could someone show me an example, how to make this plugin sort players showing in the HUD msg, by HP? I cant understand it at all..

Code:
#include <amxmodx>  
#include <cstrike> 
#include <colorchat>  

#pragma semicolon 1 

public plugin_init()   
{  
    register_plugin("Show info after death", "1.0", "JocA"); 
   
    register_clcmd( "say /showhp", "HPInfo" ); 
}  
public HPInfo( id )  
{  
    new players[32], brojigraca, name[32], player; 

    new ctinfo[500], tinfo[500], ctlen, tlen; 
       
    get_players( players, brojigraca, "ah" ); 
       
    for ( new i = 0; i < brojigraca; i++ )    
    {   
        player = players[i]; 
           
        get_user_name( player, name, 31 );  
         
        new user_health = get_user_health( player ); 
           
        switch ( cs_get_user_team( player ) )   
        {   
            case CS_TEAM_CT: ctlen += formatex( ctinfo[ctlen], charsmax(ctinfo) - ctlen, "%s - %d^n", name, user_health );   
  
            case CS_TEAM_T: tlen += formatex( tinfo[tlen], charsmax(tinfo) - tlen, "%s - %d^n", name, user_health );   
        }   
    }   
    set_hudmessage( 0, 50, 255, 0.06, 0.6, 0, 0.0, 3.1, 0.0, 0.0, -1 ); 
    show_hudmessage( id, ctinfo ); 
    set_hudmessage( 255, 40, 0, 0.7, 0.6, 0, 0.0, 3.1, 0.0, 0.0, -1 ); 
    show_hudmessage( id, tinfo ); 
     
    set_task( 3.0, "HPcInfo", id ); 
     
    return PLUGIN_CONTINUE; 
}
__________________
Ahujena
mazmaajinsh is offline
pRoxxxDD
Junior Member
Join Date: Feb 2011
Location: Ukraine
Old 05-03-2011 , 04:35   Re: sorting by HP
Reply With Quote #2

from min to max HP ?
__________________
pRoxxxDD is offline
lkh1018
Junior Member
Join Date: Aug 2007
Old 05-03-2011 , 05:30   Re: sorting by HP
Reply With Quote #3

PHP Code:
new const MAXPLAYERS get_maxplayers()
new 
iHealth[MAXPLAYERS+1], iPlayer[MAXPLAYERS]
new 
num 00
for(new 1<= MAXPLAYERSi++) {
 if(
is_user_alive(i)) {
  
iHealth[i] = get_user_health(i)
  
num++
 }
 else
  
iHealth[i] = 0
}
for(new 
0numi++) {
 for(new 
1<= MAXPLAYERSj++) {
  if(
iHealth[L] < iHealth[j]) {
   
j
  
}
 }
 
iPlayer[i] = L
 iHealth
[L] = 0

I would do something like this. Now, iPlayer[] is the list of player index sorted by health with descending order.
lkh1018 is offline
mazmaajinsh
Senior Member
Join Date: Apr 2005
Location: Latvia
Old 05-03-2011 , 05:35   Re: sorting by HP
Reply With Quote #4

Quote:
Originally Posted by pRoxxxDD View Post
from min to max HP ?
from max to min


Quote:
Originally Posted by lkh1018 View Post
PHP Code:
new const MAXPLAYERS get_maxplayers()
new 
iHealth[MAXPLAYERS+1], iPlayer[MAXPLAYERS]
new 
num 00
for(new 1<= MAXPLAYERSi++) {
 if(
is_user_alive(i)) {
  
iHealth[i] = get_user_health(i)
  
num++
 }
 else
  
iHealth[i] = 0
}
for(new 
0numi++) {
 for(new 
1<= MAXPLAYERSj++) {
  if(
iHealth[L] < iHealth[j]) {
   
j
  
}
 }
 
iPlayer[i] = L
 iHealth
[L] = 0

I would do something like this. Now, iPlayer[] is the list of player index sorted by health with descending order.
How would it look in this script?
__________________
Ahujena

Last edited by mazmaajinsh; 05-03-2011 at 05:41.
mazmaajinsh is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-03-2011 , 07:01   Re: sorting by HP
Reply With Quote #5

Something like this:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "sort by HP example"
#define VERSION "1.0"
#define AUTHOR "retarded elf"

enum
{
    
CS_TEAM_UNASSIGNED=0,
    
CS_TEAM_T,
    
CS_TEAM_CT,
    
CS_TEAM_SPECTATOR
}

const 
OFFSET_LINUX=5
const OFFSET_CSTEAMS=114

new g_maxplayers

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("sort""clcmd_sort")
    
    
g_maxplayers=get_maxplayers()
}

public 
clcmd_sort(id)
{
    static 
ictplayers[32], tplayers[32], playercountTplayercountCTtempctinfo[1024], tinfo[1024], name[32]
    
    if (
id&&!(get_user_flags(id0)&ADMIN_BAN))
        return 
PLUGIN_HANDLED
        
    playercountT
=0
    playercountCT
=0
    tinfo
=""
    
ctinfo=""
    
    
for (id=1;id<=g_maxplayers;id++)
    {
        if (!
is_user_connected(id)||!is_user_alive(id))
            continue
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)==CS_TEAM_T)
        {
            
tplayers[playercountT]=id
            playercountT
++
        }
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)==CS_TEAM_CT)
        {
            
ctplayers[playercountCT]=id
            playercountCT
++
        }
    }  
    
    for (
i=0;i<playercountT;i++)
        for (
id=i;id<playercountT;id++)
            if (
pev(idpev_health)>pev(ipev_health))
            {
                
temp=tplayers[id]
                
tplayers[id]=tplayers[i]
                
tplayers[i]=temp
            
}
    
    for (
i=0;i<playercountCT;i++)
        for (
id=i;id<playercountCT;id++)
            if (
pev(idpev_health)>pev(ipev_health))
            {
                
temp=ctplayers[id]
                
ctplayers[id]=ctplayers[i]
                
ctplayers[i]=temp
            
}

    for (
id=0;id<playercountCT;id++)
    {    
        
get_user_name(idnamecharsmax(name))
        
add(tinfocharsmax(tinfo), namecharsmax(name))
        
add(tinfocharsmax(tinfo), " ("2)
        
num_to_str(pev(idpev_health), namecharsmax(name))
        
add(tinfocharsmax(tinfo), namecharsmax(name))
        
add(tinfocharsmax(tinfo), " HP)^n"5)
    }
    
    for (
id=0;id<playercountT;id++)
    {
        
get_user_name(idnamecharsmax(name))
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
        
add(ctinfocharsmax(ctinfo), " ("2)
        
num_to_str(pev(idpev_health), namecharsmax(name))
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
        
add(ctinfocharsmax(ctinfo), " HP)^n"5)
    }
    
    
set_hudmessage(0502550.060.600.03.10.00.0, -1)
    
show_hudmessage(idctinfo)
    
set_hudmessage(2554000.70.600.03.10.00.0, -1)
    
show_hudmessage(idtinfo)
    
    return 
PLUGIN_HANDLED

NOT TESTED.
__________________

SonicSonedit is offline
mazmaajinsh
Senior Member
Join Date: Apr 2005
Location: Latvia
Old 05-03-2011 , 12:01   Re: sorting by HP
Reply With Quote #6

Thanks.

It has some issues though. ^^
1. it shows hostname in the playerlist also, like if hostname is Counter-Strike, it shows in both teams Counter-Strike (0hp)
2. Sometimes it doesnt show up at all when writing sort. Dunno why.
3. Not issue, but it could also number players like this- #1 Player (100hp) , #2 Player3 (98hp) , #3 Player2 (34hp)

but already big thanks!!
__________________
Ahujena
mazmaajinsh is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-03-2011 , 14:07   Re: sorting by HP
Reply With Quote #7

Heres another way which I wrote for frags but can easily be adjusted for hp. You will also need to add HUD code. If you can't figure it out let me know.
http://forums.alliedmods.net/showpos...94&postcount=4
__________________
Bugsy is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-03-2011 , 14:29   Re: sorting by HP
Reply With Quote #8

mazmaajinsh
Fixed:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "sort by HP example"
#define VERSION "1.0"
#define AUTHOR "retarded elf"

enum
{
    
CS_TEAM_UNASSIGNED=0,
    
CS_TEAM_T,
    
CS_TEAM_CT,
    
CS_TEAM_SPECTATOR
}

const 
OFFSET_LINUX=5
const OFFSET_CSTEAMS=114

new g_maxplayers

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("sort""clcmd_sort")
    
    
g_maxplayers=get_maxplayers()
}

public 
clcmd_sort(id)
{
    static 
ictplayers[32], tplayers[32], playercountTplayercountCTtempctinfo[1024], tinfo[1024], name[32]
    
    if (
id&&!(get_user_flags(id0)&ADMIN_BAN))
        return 
PLUGIN_HANDLED
        
    playercountT
=0
    playercountCT
=0
    tinfo
=""
    
ctinfo=""
    
    
for (id=1;id<=g_maxplayers;id++)
    {
        if (!
is_user_connected(id)||!is_user_alive(id))
            continue
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)==CS_TEAM_T)
        {
            
tplayers[playercountT]=id
            playercountT
++
        }
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)==CS_TEAM_CT)
        {
            
ctplayers[playercountCT]=id
            playercountCT
++
        }
    }  
    
    for (
i=0;i<playercountT;i++)
        for (
id=i;id<playercountT;id++)
            if (
pev(tplayers[id], pev_health)>pev(tplayers[i], pev_health))
            {
                
temp=tplayers[id]
                
tplayers[id]=tplayers[i]
                
tplayers[i]=temp
            
}
    
    for (
i=0;i<playercountCT;i++)
        for (
id=i;id<playercountCT;id++)
            if (
pev(ctplayers[id], pev_health)>pev(ctplayers[i], pev_health))
            {
                
temp=ctplayers[id]
                
ctplayers[id]=ctplayers[i]
                
ctplayers[i]=temp
            
}

    for (
id=0;id<playercountCT;id++)
    {    
        
format(namecharsmax(name), "#%d: "id)
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
        
get_user_name(ctplayers[id], namecharsmax(name))
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
        
format(namecharsmax(name), " (%d HP)^n"pev(ctplayers[id], pev_health))
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
    }
    
    for (
id=0;id<playercountT;id++)
    {
        
format(namecharsmax(name), "#%d: "id)
        
add(tinfocharsmax(tinfo), namecharsmax(name))
        
get_user_name(tplayers[id], namecharsmax(name))
        
add(tinfocharsmax(tinfo), namecharsmax(name))
        
format(namecharsmax(name), " (%d HP)^n"pev(tplayers[id], pev_health))
        
add(tinfocharsmax(tinfo), namecharsmax(name))
    }
    
    
set_hudmessage(0502550.060.600.03.10.00.0, -1)
    
show_hudmessage(idctinfo)
    
set_hudmessage(2554000.70.600.03.10.00.0, -1)
    
show_hudmessage(idtinfo)
    
    return 
PLUGIN_HANDLED

__________________


Last edited by SonicSonedit; 05-03-2011 at 14:33.
SonicSonedit is offline
mazmaajinsh
Senior Member
Join Date: Apr 2005
Location: Latvia
Old 05-03-2011 , 18:46   Re: sorting by HP
Reply With Quote #9

Quote:
Originally Posted by SonicSonedit View Post
mazmaajinsh
Fixed:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "sort by HP example"
#define VERSION "1.0"
#define AUTHOR "retarded elf"

enum
{
    
CS_TEAM_UNASSIGNED=0,
    
CS_TEAM_T,
    
CS_TEAM_CT,
    
CS_TEAM_SPECTATOR
}

const 
OFFSET_LINUX=5
const OFFSET_CSTEAMS=114

new g_maxplayers

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("sort""clcmd_sort")
    
    
g_maxplayers=get_maxplayers()
}

public 
clcmd_sort(id)
{
    static 
ictplayers[32], tplayers[32], playercountTplayercountCTtempctinfo[1024], tinfo[1024], name[32]
    
    if (
id&&!(get_user_flags(id0)&ADMIN_BAN))
        return 
PLUGIN_HANDLED
        
    playercountT
=0
    playercountCT
=0
    tinfo
=""
    
ctinfo=""
    
    
for (id=1;id<=g_maxplayers;id++)
    {
        if (!
is_user_connected(id)||!is_user_alive(id))
            continue
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)==CS_TEAM_T)
        {
            
tplayers[playercountT]=id
            playercountT
++
        }
            
        if (
get_pdata_int(idOFFSET_CSTEAMSOFFSET_LINUX)==CS_TEAM_CT)
        {
            
ctplayers[playercountCT]=id
            playercountCT
++
        }
    }  
    
    for (
i=0;i<playercountT;i++)
        for (
id=i;id<playercountT;id++)
            if (
pev(tplayers[id], pev_health)>pev(tplayers[i], pev_health))
            {
                
temp=tplayers[id]
                
tplayers[id]=tplayers[i]
                
tplayers[i]=temp
            
}
    
    for (
i=0;i<playercountCT;i++)
        for (
id=i;id<playercountCT;id++)
            if (
pev(ctplayers[id], pev_health)>pev(ctplayers[i], pev_health))
            {
                
temp=ctplayers[id]
                
ctplayers[id]=ctplayers[i]
                
ctplayers[i]=temp
            
}

    for (
id=0;id<playercountCT;id++)
    {    
        
format(namecharsmax(name), "#%d: "id)
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
        
get_user_name(ctplayers[id], namecharsmax(name))
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
        
format(namecharsmax(name), " (%d HP)^n"pev(ctplayers[id], pev_health))
        
add(ctinfocharsmax(ctinfo), namecharsmax(name))
    }
    
    for (
id=0;id<playercountT;id++)
    {
        
format(namecharsmax(name), "#%d: "id)
        
add(tinfocharsmax(tinfo), namecharsmax(name))
        
get_user_name(tplayers[id], namecharsmax(name))
        
add(tinfocharsmax(tinfo), namecharsmax(name))
        
format(namecharsmax(name), " (%d HP)^n"pev(tplayers[id], pev_health))
        
add(tinfocharsmax(tinfo), namecharsmax(name))
    }
    
    
set_hudmessage(0502550.060.600.03.10.00.0, -1)
    
show_hudmessage(idctinfo)
    
set_hudmessage(2554000.70.600.03.10.00.0, -1)
    
show_hudmessage(idtinfo)
    
    return 
PLUGIN_HANDLED

well now the plugin loads, but HUD doesnt show up at all when writing using sort command
__________________
Ahujena
mazmaajinsh is offline
mazmaajinsh
Senior Member
Join Date: Apr 2005
Location: Latvia
Old 05-03-2011 , 19:26   Re: sorting by HP
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Heres another way which I wrote for frags but can easily be adjusted for hp. You will also need to add HUD code. If you can't figure it out let me know.
http://forums.alliedmods.net/showpos...94&postcount=4
I tried to add the HUD code, it compiled right, but somehow it didnt show HUD msg in game. could you show me how to do that?
__________________
Ahujena
mazmaajinsh is offline
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 14:04.


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