View Single Post
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-02-2021 , 13:58   Re: Health per Level
Reply With Quote #2

How can it be HP steal if the player is dead?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <crxranks>
#include <fun>
#include <hamsandwich>

#define PLUGIN_VERSION "1.0"

new Trie:g_tHealth
new Trie:g_tHealthHS

public plugin_init()
{
    
register_plugin("CRXRanks: Health on Kill"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXRanksHPOnKill"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
    
register_event("DeathMsg""OnPlayerKilled""a")
}

public 
plugin_cfg()
{
    
g_tHealth TrieCreate()
    
g_tHealthHS TrieCreate()
    
ReadFile()
}

public 
plugin_end()
{
    
TrieDestroy(g_tHealth)
    
TrieDestroy(g_tHealthHS)
}
    
ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/RankSystemHealthOnKill.ini"szConfigsName)
    
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[64], szValue[16], szValue2[8], szMap[32], szKey[32], bool:bRead trueiSize
        get_mapname
(szMapcharsmax(szMap))
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            switch(
szData[0])
            {
                case 
EOS'#'';': continue
                case 
'-':
                {
                    
iSize strlen(szData)
                    
                    if(
szData[iSize 1] == '-')
                    {
                        
szData[0] = ' '
                        
szData[iSize 1] = ' '
                        
trim(szData)
                        
                        if(
contain(szData"*") != -1)
                        {
                            
strtok(szDataszKeycharsmax(szKey), szValuecharsmax(szValue), '*')
                            
copy(szValuestrlen(szKey), szMap)
                            
bRead equal(szValueszKey) ? true false
                        
}
                        else
                        {
                            static const 
szAll[] = "#all"
                            
bRead equal(szDataszAll) || equali(szDataszMap)
                        }
                    }
                    else continue
                }
                default:
                {
                    if(!
bRead)
                        continue
                        
                    
strtok(szDataszKeycharsmax(szKey), szValuecharsmax(szValue), '=')
                    
trim(szKey); trim(szValue)
                            
                    if(!
szValue[0])
                        continue

                    
parse(szValueszValuecharsmax(szValue), szValue2charsmax(szValue2))                        
                    
TrieSetCell(g_tHealthszKeystr_to_num(szValue))
                    
TrieSetCell(g_tHealthHSszKeystr_to_num(szValue2))
                }
            }
        }
        
        
fclose(iFilePointer)
    }
}

public 
OnPlayerKilled()
{
    new 
iAttacker read_data(1), iVictim read_data(2)

    if(
is_user_connected(iAttacker) && iAttacker != iVictim)
    {
        new 
szLevel[8], iLevel crxranks_get_user_level(iAttacker)
        
num_to_str(iLevelszLevelcharsmax(szLevel))

        new 
iHealth
        TrieGetCell
(read_data(3) ? g_tHealthHS g_tHealthszLeveliHealth)
        
set_user_health(iAttackerget_user_health(iAttacker) + iHealth)
    }

Example RankSystemHealthOnKill.ini:

PHP Code:
#======================================================#
# CRXRanks: Health On Kill Configuration file          #
#======================================================#
# This plugin requires OciXCrom's Rank System to work  #
#======================================================#

# Add each health amount on a new line following the format:
# <level number> = <health on normal kill> <health on headshot>

0 0
1 2
2 3
5 10 
__________________

Last edited by OciXCrom; 03-02-2021 at 13:59.
OciXCrom is offline
Send a message via Skype™ to OciXCrom