AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sorting by HP (https://forums.alliedmods.net/showthread.php?t=156223)

mazmaajinsh 05-02-2011 17:29

sorting by HP
 
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;
}


pRoxxxDD 05-03-2011 04:35

Re: sorting by HP
 
from min to max HP ?

lkh1018 05-03-2011 05:30

Re: sorting by HP
 
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.

mazmaajinsh 05-03-2011 05:35

Re: sorting by HP
 
Quote:

Originally Posted by pRoxxxDD (Post 1462390)
from min to max HP ?

from max to min


Quote:

Originally Posted by lkh1018 (Post 1462401)
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?

SonicSonedit 05-03-2011 07:01

Re: sorting by HP
 
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.

mazmaajinsh 05-03-2011 12:01

Re: sorting by HP
 
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!! :)

Bugsy 05-03-2011 14:07

Re: sorting by HP
 
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

SonicSonedit 05-03-2011 14:29

Re: sorting by HP
 
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



mazmaajinsh 05-03-2011 18:46

Re: sorting by HP
 
Quote:

Originally Posted by SonicSonedit (Post 1462658)
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

mazmaajinsh 05-03-2011 19:26

Re: sorting by HP
 
Quote:

Originally Posted by Bugsy (Post 1462650)
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?


All times are GMT -4. The time now is 04:26.

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