View Single Post
tarsisd2
Veteran Member
Join Date: Feb 2016
Location: brazil
Old 01-03-2019 , 15:18   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #164

Quote:
Originally Posted by OciXCrom View Post
Try this:

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

#define PLUGIN_VERSION "1.0"

new Trie:g_tWeightg_iWeight[33]

public 
plugin_init()
{
    
register_plugin("CRXRanks: Weighted XP"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXRanksWXP"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
register_event("DeathMsg""OnPlayerKilled""a")
    
g_tWeight TrieCreate()
    
ReadFile()
}

public 
plugin_end()
    
TrieDestroy(g_tWeight)
    
ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/RankSystemWeight.ini"szConfigsName)
    
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[64], szValue[32], 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
                        
                    
TrieSetCell(g_tWeightszKeystr_to_num(szValue))
                }
            }
        }
        
        
fclose(iFilePointer)
    }
}

public 
client_putinserver(id)
    
crxranks_user_level_updated(idcrxranks_get_user_level(id), true)

public 
crxranks_user_level_updated(idiLevelbool:bLevelUp)
{
    
g_iWeight[id] = 0

    
for(new szI[8], iLevel0i--)
    {
        
num_to_str(iszIcharsmax(szI))
        
        if(
TrieGetCell(g_tWeightszIg_iWeight[id]))
            break
    }
}

public 
OnPlayerKilled()
{
    new 
iAttacker read_data(1), iVictim read_data(2)
    
    if(!
is_user_connected(iAttacker) || iAttacker == iVictim || !g_iWeight[iVictim])
        return

    
crxranks_give_user_xp(iAttackerg_iWeight[iVictim], _CRXRANKS_XPS_REWARD)
    
crxranks_give_user_xp(iVictimg_iWeight[iVictim] * -1_CRXRANKS_XPS_REWARD)
}

public 
crxranks_user_receive_xp(idiXPCRXRanks_XPSources:iSource)
    return (
g_iWeight[id] && iSource == CRXRANKS_XPS_REWARD) ? (iXP g_iWeight[id]) : CRXRANKS_CONTINUE 
Create a file in your "configs" folder named "RankSystemWeight.ini" and add in it the following:

PHP Code:
# <level> = <xp weight>
2
3
18 
4
26 
5
35 

For example, "18 = 4" means that players that reached level 18 will have a XP weight of 4.

When a player kills another player, he will receive the XP weight of the killed player, and the killed player will lose XP according to his own XP weight.

For example, player A has a XP weight of 4 and player B has 6.
If player A kills player B, player A will receive 6 XP and player B will lose 6 XP.

When a player receives any kind of XP that is set in the [XP Rewards] section in "RankSystem.ini", he will also receive the amount of XP weight he has.

For example, "headshot" is set to 2 in the configuration file and player B kills player A - player B will get the XP weight of player A which is 4 + the "headshot" event of 2 (+ any other events set in the .ini file) which will result in him gaining 6 XP. Player A will lose only 4 XP as this is his XP weight.

Let me know if things are working as they should, since I haven't tested the plugin. Also let me know if you want me to change something.
Using a formula to determine the XP weight can make the plugin work without an .ini file and make it much smaller, so let me know if you figure out some kind of formula. For example, XP weight = player level * 20 / 100.

About the assistance plugin you're using - post it here. Only 1 line needs to be added in order for it to give XP on assist.
this is working great, great work, just the chat msgs are not matching, if you could when you have a free time, edit it for me so it shows exactly how many points the player won and how many he lost

because now player is getting like 5 points and showing 2, and losing points and not showing

thanks a million
tarsisd2 is offline