Raised This Month: $32 Target: $400
 8% 

OciXCrom's Rank System [XP|Levels|Ranks]


Post New Thread Reply   
 
Thread Tools Display Modes
Dexon
Member
Join Date: Aug 2019
Old 08-24-2019 , 17:47   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #311

Ammo = Ammo Packs
AP = Armor
Dexon is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-25-2019 , 07:18   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #312

1. Armor:

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

#define PLUGIN_VERSION "1.0"

new Trie:g_tArmor

public plugin_init()
{
    
register_plugin("CRXRanks: Armor Per Level"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXRanksAPL"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
}

public 
plugin_cfg()
{
    
g_tArmor TrieCreate()
    
ReadFile()
}

public 
plugin_end()
{
    
TrieDestroy(g_tArmor)
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/RankSystemArmor.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_tArmorszKeystr_to_num(szValue))
                }
            }
        }

        
fclose(iFilePointer)
    }
}

public 
OnPlayerSpawn(id)
{
    if(!
is_user_alive(id))
        return

    new 
szLevel[10]
    
num_to_str(crxranks_get_user_level(id), szLevelcharsmax(szLevel))

    if(
TrieKeyExists(g_tArmorszLevel))
    {
        new 
iArmor
        TrieGetCell
(g_tArmorszLeveliArmor)
        
cs_set_user_armor(idiArmorCS_ARMOR_VESTHELM)
    }

Create a file in your "configs" folder named "RankSystemArmor.ini" and inside it add:

PHP Code:
# <level> = <armor amount>
0
0
0
0
0
0
0
0
0
10 
10 
Continue it for other levels.

2. AmmoPacks:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <crxranks>
#include <zombieplague>

#define PLUGIN_VERSION "1.0"

new Trie:g_tAP

public plugin_init()
{
    
register_plugin("CRXRanks: ZP Per Level"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXRanksAPPL"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
}

public 
plugin_cfg()
{
    
g_tAP TrieCreate()
    
ReadFile()
}

public 
plugin_end()
{
    
TrieDestroy(g_tAP)
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/RankSystemAmmoPacks.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_tAPszKeystr_to_num(szValue))
                }
            }
        }

        
fclose(iFilePointer)
    }
}

public 
crxranks_user_level_updated(idiLevelbool:bLevelUp)
{
    if(!
bLevelUp)
        return

    new 
szLevel[10]
    
num_to_str(iLevelszLevelcharsmax(szLevel))

    if(
TrieKeyExists(g_tAPszLevel))
    {
        new 
iAP
        TrieGetCell
(g_tAPszLeveliAP)
        
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + iAP)
        
CC_SendMessage(id"&x04* &x01You received &x04%i AmmoPacks &x01for reaching level &x03%i&x01."iAPiLevel)
    }

Create a file in your "configs" folder named "RankSystemAmmoPacks.ini" and inside it add:

PHP Code:
# <level> = <AmmoPacks amount>
100
100
100
100
100
100
100
100
100
10 
250 
Continue it for other levels.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Dexon
Member
Join Date: Aug 2019
Old 08-25-2019 , 10:38   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #313

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// rsammo.sma
// C:\Users\h3d3r\Desktop\1.6\Compiler\addons\am xmodx\scripting\rsammo.sma(1) : error 010: invalid function or declaration
//
// 1 Error.
// Could not locate output file C:\Users\h3d3r\Desktop\1.6\Compiler\addons\am xmodx\scripting\compiled\rsammo.amx (compile failed).
//
// Compilation Time: 0,12 sec
// ----------------------------------------

Press enter to exit ...


-----------------------------------------------------

The AmmoPacks was wrong, but the Armor system compiled fine.

Last edited by Dexon; 08-25-2019 at 10:46.
Dexon is offline
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 08-25-2019 , 10:43   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #314

Quote:
Originally Posted by Dexon View Post
//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// rsammo.sma
// C:\Users\h3d3r\Desktop\1.6\Compiler\addons\am xmodx\scripting\rsammo.sma(1) : error 010: invalid function or declaration
//
// 1 Error.
// Could not locate output file C:\Users\h3d3r\Desktop\1.6\Compiler\addons\am xmodx\scripting\compiled\rsammo.amx (compile failed).
//
// Compilation Time: 0,12 sec
// ----------------------------------------

Press enter to exit ...


----------------------------------------------------

The AmmoPacks
you added something wrong , in line (1) , try removing it

-
-
-
Quote:
Originally Posted by OciXCrom View Post
PHP Code:
public plugin_end()
{
    
TrieDestroy(g_tAP)

https://forums.alliedmods.net/showpo...50&postcount=2

Last edited by LearninG; 08-25-2019 at 11:38.
LearninG is offline
Dexon
Member
Join Date: Aug 2019
Old 08-25-2019 , 11:22   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #315

Forget it, was trying with bad files, cause I added similar name.

Thanks, OciXCrom for the help.
Dexon is offline
Dexon
Member
Join Date: Aug 2019
Old 08-25-2019 , 12:00   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #316

Quote:
Originally Posted by OciXCrom View Post
1. Armor:

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

#define PLUGIN_VERSION "1.0"

new Trie:g_tArmor

public plugin_init()
{
    
register_plugin("CRXRanks: Armor Per Level"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXRanksAPL"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
}

public 
plugin_cfg()
{
    
g_tArmor TrieCreate()
    
ReadFile()
}

public 
plugin_end()
{
    
TrieDestroy(g_tArmor)
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/RankSystemArmor.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_tArmorszKeystr_to_num(szValue))
                }
            }
        }

        
fclose(iFilePointer)
    }
}

public 
OnPlayerSpawn(id)
{
    if(!
is_user_alive(id))
        return

    new 
szLevel[10]
    
num_to_str(crxranks_get_user_level(id), szLevelcharsmax(szLevel))

    if(
TrieKeyExists(g_tArmorszLevel))
    {
        new 
iArmor
        TrieGetCell
(g_tArmorszLeveliArmor)
        
cs_set_user_armor(idiArmorCS_ARMOR_VESTHELM)
    }

Create a file in your "configs" folder named "RankSystemArmor.ini" and inside it add:

PHP Code:
# <level> = <armor amount>
0
0
0
0
0
0
0
0
0
10 
10 
Continue it for other levels.

2. AmmoPacks:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cromchat>
#include <crxranks>
#include <zombieplague>

#define PLUGIN_VERSION "1.0"

new Trie:g_tAP

public plugin_init()
{
    
register_plugin("CRXRanks: ZP Per Level"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXRanksAPPL"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
}

public 
plugin_cfg()
{
    
g_tAP TrieCreate()
    
ReadFile()
}

public 
plugin_end()
{
    
TrieDestroy(g_tAP)
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/RankSystemAmmoPacks.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_tAPszKeystr_to_num(szValue))
                }
            }
        }

        
fclose(iFilePointer)
    }
}

public 
crxranks_user_level_updated(idiLevelbool:bLevelUp)
{
    if(!
bLevelUp)
        return

    new 
szLevel[10]
    
num_to_str(iLevelszLevelcharsmax(szLevel))

    if(
TrieKeyExists(g_tAPszLevel))
    {
        new 
iAP
        TrieGetCell
(g_tAPszLeveliAP)
        
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + iAP)
        
CC_SendMessage(id"&x04* &x01You received &x04%i AmmoPacks &x01for reaching level &x03%i&x01."iAPiLevel)
    }

Create a file in your "configs" folder named "RankSystemAmmoPacks.ini" and inside it add:

PHP Code:
# <level> = <AmmoPacks amount>
100
100
100
100
100
100
100
100
100
10 
250 
Continue it for other levels.


I am using VIP system on my Zombie Plague server, and so it removes the basic armor what VIPs get at the round start. Could you make it to add + armor to basic armor?
Dexon is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-25-2019 , 15:44   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #317

Quote:
Originally Posted by LearninG View Post
https://www.amxmodx.org/api/celltrie/TrieCreate

Code:
Return

New Map handle, which must be freed via TrieDestroy()
Quote:
Originally Posted by Dexon View Post
I am using VIP system on my Zombie Plague server, and so it removes the basic armor what VIPs get at the round start. Could you make it to add + armor to basic armor?
Replace:

PHP Code:
cs_set_user_armor(idiArmorCS_ARMOR_VESTHELM
With:

PHP Code:
cs_set_user_armor(idcs_get_user_armor(id) + iArmorCS_ARMOR_VESTHELM
__________________

Last edited by OciXCrom; 08-25-2019 at 15:45.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Dexon
Member
Join Date: Aug 2019
Old 08-26-2019 , 06:14   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #318

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// rsarmor.sma
// C:\Users\h3d3r\Desktop\1.6\Compiler\addons\am xmodx\scripting\rsarmor.sma(106) : error 088: number of arguments does not match definition
//
// 1 Error.
// Could not locate output file C:\Users\h3d3r\Desktop\1.6\Compiler\addons\am xmodx\scripting\compiled\rsarmor.amx (compile failed).
//
// Compilation Time: 0,09 sec
// ----------------------------------------

Press enter to exit ...


if(TrieKeyExists(g_tArmor, szLevel))
{
new iArmor
TrieGetCell(g_tArmor, szLevel, iArmor)
cs_set_user_armor(id, cs_get_user_armor(id) + iArmor, CS_ARMOR_VESTHELM)
}

What should I add?
Dexon is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-26-2019 , 06:24   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #319

1.
PHP Code:
g_aLevels ArrayCreate(16
g_aLevels seems to be an array for integers. Then cellsize should be 1, not 16.

2. As I said before, your code can leak connections if a query fails. If you prematurely return from a function before a handle is freed you should also add SQL_FreeHandle before returning.

For example, at line 239: assume the if check passes because the query failed. You will print the error message and jump after SQL_FreeHandle(iSqlConnection) with a goto. This will cause a leak.

The proper code should be:

PHP Code:
if(!SQL_Execute(iQueries))
{
    
SQL_QueryError(iQueriesg_szSqlErrorcharsmax(g_szSqlError))
    
log_amx(g_szSqlError)
    
switch_to_nvault()
        
SQL_FreeHandle(iSqlConnection)
    goto @
AFTER_MYSQL

This should be done everywhere, not only in this specific case.

3.

a)In client_infochanged you should refactor to have the SAVE_TYPE check be first or right after is_user_connected check. There is no point in retrieving new/old name or doing anything for that matter if the saving method is not "name".

b)Why do you wait 0.1 seconds in the mysql case instead of immediately calling save_or_load for loading.

c)Also, do you think you could add a setting to control what happens on a name change? It can be right now, where you simply load whatever was saved on the new name or you could actually transfer the data from the old name to the new name and remove the old one from the vault/database.
I think this could be useful if a player gets sick of his old name, wants to play under a new one, but doesn't want to start from 0.

4.It's probably time to remove Cmd_UpdateMySQL.

5.In sort_players_by_xp, you can just return g_ePlayerData[id2][XP] - g_ePlayerData[id1][XP]. This is common practice for short sorting functions.

6.I know I pointed this out before, but I'll say again, just in case: inside save_or_load, in SL_SAVE_DATA you should free iSqlConnection or use SQL_FreeHandle inside SQL_QuoteString.

In SL_LOAD_DATA case: I don't really like you make a connection, close it and then reopen immediately inside prepare_player. Keep the connection open and do both task with one connection, the information is already there.

Enough for now.
__________________
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-26-2019 , 07:42   Re: OciXCrom's Rank System [XP|Levels|Ranks]
Reply With Quote #320

@Dexon - it seems like you're running an older AMXX version. Replace "cs_get_user_armor" with "get_user_armor".

@HamletEagle - I'll do the changes + the ones from your PM later today or tomorrow.
__________________

Last edited by OciXCrom; 08-26-2019 at 07:43.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply


Thread Tools
Display Modes

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 10:46.


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