Veteran Member
Join Date: Feb 2016
Location: brazil
|
01-03-2019
, 15:18
Re: OciXCrom's Rank System [XP|Levels|Ranks]
|
#164
|
Quote:
Originally Posted by OciXCrom
Try this:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <crxranks>
#include <fun>
#include <hamsandwich>
#define PLUGIN_VERSION "1.0"
new Trie:g_tWeight, g_iWeight[33]
public plugin_init()
{
register_plugin("CRXRanks: Weighted XP", PLUGIN_VERSION, "OciXCrom")
register_cvar("CRXRanksWXP", PLUGIN_VERSION, FCVAR_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(szConfigsName, charsmax(szConfigsName))
formatex(szFilename, charsmax(szFilename), "%s/RankSystemWeight.ini", szConfigsName)
new iFilePointer = fopen(szFilename, "rt")
if(iFilePointer)
{
new szData[64], szValue[32], szMap[32], szKey[32], bool:bRead = true, iSize
get_mapname(szMap, charsmax(szMap))
while(!feof(iFilePointer))
{
fgets(iFilePointer, szData, charsmax(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(szData, szKey, charsmax(szKey), szValue, charsmax(szValue), '*')
copy(szValue, strlen(szKey), szMap)
bRead = equal(szValue, szKey) ? true : false
}
else
{
static const szAll[] = "#all"
bRead = equal(szData, szAll) || equali(szData, szMap)
}
}
else continue
}
default:
{
if(!bRead)
continue
strtok(szData, szKey, charsmax(szKey), szValue, charsmax(szValue), '=')
trim(szKey); trim(szValue)
if(!szValue[0])
continue
TrieSetCell(g_tWeight, szKey, str_to_num(szValue))
}
}
}
fclose(iFilePointer)
}
}
public client_putinserver(id)
crxranks_user_level_updated(id, crxranks_get_user_level(id), true)
public crxranks_user_level_updated(id, iLevel, bool:bLevelUp)
{
g_iWeight[id] = 0
for(new szI[8], i = iLevel; i > 0; i--)
{
num_to_str(i, szI, charsmax(szI))
if(TrieGetCell(g_tWeight, szI, g_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(iAttacker, g_iWeight[iVictim], _, CRXRANKS_XPS_REWARD)
crxranks_give_user_xp(iVictim, g_iWeight[iVictim] * -1, _, CRXRANKS_XPS_REWARD)
}
public crxranks_user_receive_xp(id, iXP, CRXRanks_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>
1 = 2
9 = 3
18 = 4
26 = 5
35 = 6
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
|
|