Raised This Month: $28 Target: $400
 7% 

[REQ]Аdmіn Prefix + Rаnk Ѕуѕtеm @ StatsX Database?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RaZ_HU
Senior Member
Join Date: May 2015
Location: Hungary
Old 05-13-2015 , 09:18   [REQ]Аdmіn Prefix + Rаnk Ѕуѕtеm @ StatsX Database?
Reply With Quote #1

Hi, I'm new to AMX modding and I don't know about coding either too much.
I have found this plugin's source named "Аdmіn Prefix + Rаnk Ѕуѕtеm" here: https://forums.alliedmods.net/showpo...21&postcount=3

The plugin is working flawlessly, but my problem is about it uses fvault db system.
Can someone take a look at it and give me some advices how can I make this plugin to work with the built-in StatsX plugin's database?

I mean to only read and show data from it, not write. The write would stay at the StatsX plugin with the other commands.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <colorchat>
#include <fvault>
 
#define PLUGIN "Аdmіn Prefix + Rаnk Ѕуѕtеm}"
#define VЕRЅІОN "1.0"
#define AUTHOR "РіkасhоY - Lеgеndаrу Еаglе"
#define MaxLevels 28
#define IsPlayer(%1) (1 <= %1 <=  g_iMaxPlayers)
 
#define ADMIN1 "Аdmіnіѕtrаtоr"
#define ADMIN1_ACCESS ADMIN_LEVEL_A    
 
#define ADMIN2 "Wоlvеrіnе"
#define ADMIN2_ACCESS ADMIN_LEVEL_B
 
#define ADMIN3 "Іnvіѕіblе mаn"
#define ADMIN3_ACCESS ADMIN_LEVEL_C
 
#define ADMIN4 "Іrоn Маn"
#define ADMIN4_ACCESS ADMIN_LEVEL_D
 
#define ADMIN5 "НULК"
#define ADMIN5_ACCESS ADMIN_LEVEL_E
 
#define ADMIN6 "VАМРІRЕ"
#define ADMIN6_ACCESS ADMIN_LEVEL_F
 
#define ADMIN7 "Саt Wоmаn"
#define ADMIN7_ACCESS ADMIN_LEVEL_G
 
#define ADMIN8 "Тhе Flаѕh"
#define ADMIN8_ACCESS ADMIN_LEVEL_H
new gMaxPlayersgMsgSayTextsync0bjLevel[33], eXP[33];
new 
ranks_hudknife_xphe_xphs_xpkill_xpkill_msg;
new const 
g_vault_name[] = "levelsz";
 
new const 
Levels[MaxLevels 1] ={
    
100,
    
300,
    
500,
    
800,
    
1000,
    
1300,
    
1600,
    
2000,
    
2500,
    
3500,
    
4500,
    
5600,
    
7500,
    
8000,
    
8100,
    
8300,
    
8500,
    
9000,
    
10000,
    
12000,
    
13000,
    
15000,
    
16000,
    
19000,
    
20000,
    
22000,
    
24000,
    
26000,
    
30000
}
 
new const 
Prefix[MaxLevels 1][] ={
    
"Luke Cage",
    
"Ghost Rider",
    
"Blade",
    
"Spider-Man",
    
"Daredevil",
    
"Captain Ameria",
    
"Ultron",
    
"Loki",
    
"Red Skull",
    
"Thanos",
    
"Ronan",
    
"Magneto",
    
"Dr.Doom",
    
"Green Goblin",
    
"Human Torch",
    
"Thing",
    
"Batman",
    
"Jokera",
    
"Robin",
    
"Angel",
    
"Colossus",
    
"Cyclops",
    
"Iceman",
    
"Gambit",
    
"Silver Surfer",
    
"Doctor Strange",
    
"Black Panter",
    
"Nick Fury",
    
"Professor X"
}
 
public 
plugin_init()
{
    
register_plugin("Ranks & XP mod""1.0""alt.nick")
   
    
register_event("DeathMsg","client_death","a")
    
register_clcmd("say""hook_say")
    
register_clcmd("say_team""hook_say")
   
    
register_clcmd("say /rank""cmdRank")
    
register_clcmd("say_team /rank""cmdRank")
 
   
    
ranks_hud register_cvar("ranks_hud""1")     // Дали да се появява хъд при влизане в сървъра. В?лючено 1/0 Из?лючено
    
knife_xp register_cvar("knife_xp""5")     // Кол?о ХР да дава за убийство с нож.
    
he_xp register_cvar("he_xp""8")        // Кол?о ХР да дава за убийство с Granata (HE).
    
hs_xp register_cvar("hs_xp""15")        // Кол?о ХР да дава за убийство с Headshot.
    
kill_xp register_cvar("kill_xp""10")        // Кол?о ХР да дава за нормално убийство.    
    
kill_msg register_cvar("kill_msg""1")    // Дали да по?азва ?ой сте убили и ?ол?о ХР сте получили. В?лючено 1/0 Из?лючено
   
    
register_concmd ("amx_give_xp""CmdAddXP"ADMIN_LEVEL_A"<nick | ct | t | @all> <xp>")
   
    
gMaxPlayers get_maxplayers()
    
gMsgSayText get_user_msgid("SayText")
 
    
sync0bj     CreateHudSyncObj()
   
    
fvault_load(g_vault_name)
}
public 
ShowHud(id)
{
    
set_hudmessage(142239390.010.2006.01.00.00.0, -1)
    
ShowSyncHudMsg(idsync0bj,"Rank: %s ^nXP: %i ^n"Prefix[Level[id]], eXP[id])
}
 
public 
client_putinserver(id)
{
    if(
get_pcvar_num(ranks_hud) == 1)
        
set_task(1.0"ShowHud"id__"b")
       
    if(
Level[id] < MaxLevels-1)
        while(
eXP[id] >= Levels[Level[id]])
            
Level[id] += 1
}
 
public 
client_death(killervictimweaponhitgroupTK)
{        
    if(
killer == victim)
        return 
PLUGIN_HANDLED
       
    
new headshot = (hitgroup == HIT_HEAD) ? 0
   
    
switch(weapon)
    {
        case 
CSW_HEGRENADE:
        {
            
eXP[killer] += get_pcvar_num(he_xp)
            
CheckLevel(killer)
            
SaveData(killer)
            if(
get_pcvar_num(kill_msg) == 1)
                
client_print_color(killerprint_chat"^4[Ranks]^1 poluchihte^4 %d XP^1 poradi ubiistwoto s^4 HE^1."get_pcvar_num(he_xp))
               
            return 
PLUGIN_CONTINUE
        
}
        case 
CSW_KNIFE:
        {
            
eXP[killer] += get_pcvar_num(knife_xp)
            
CheckLevel(killer)
            
SaveData(killer)
            if(
get_pcvar_num(kill_msg) == 1)
                
client_print_color(killerprint_chat"^4[Ranks]^1 poluchihte^4 %d XP^1 poradi ubiistwoto s^4 noj^1."get_pcvar_num(knife_xp))
           
            return 
PLUGIN_CONTINUE
        
}
    }
   
    if(
headshot)
    {
        
eXP[killer] += get_pcvar_num(hs_xp)
        
CheckLevel(killer)
        
SaveData(killer)
        if(
get_pcvar_num(kill_msg) == 1)
            
client_print_color(killerprint_chat"^4[Ranks]^1 poluchihte^4 %d XP^1 poradi ubiistwoto s^4 HS^1.",get_pcvar_num(hs_xp))
       
        return 
PLUGIN_CONTINUE
    
}
   
    else
    {
        
eXP[killer] += get_pcvar_num(kill_xp)
        
CheckLevel(killer)
        
SaveData(killer)
        if(
get_pcvar_num(kill_msg) == 1)
            
client_print_color(killerprint_chat"^4[Ranks]^1 poluchihte^4 %d XP^1."get_pcvar_num(kill_xp))
   
        return 
PLUGIN_CONTINUE
    
}
   
    
CheckLevel(killer)
    
SaveData(killer)
    return 
PLUGIN_CONTINUE
}
 
public 
CheckLevel(id)
{
    if(
Level[id] < MaxLevels-1)
        while(
eXP[id] >= Levels[Level[id]])
            
Level[id] += 1
}
 
public 
client_connect(id)
{
    
LoadData(id)
}
 
 
public 
client_disconnect(id)
{
    
SaveData(id)
    
eXP[id] = 0
    Level
[id] = 0
    remove_task
(id)
}
       
 
       
public 
cmdRank(id)
{
    if(
is_user_connected(id))
        
client_print_color(idprint_chat"^4[Ranks]^1 Rank:^4 %s^1 | XP:^4 %d^1 | Level:^4 %d^1."Prefix[Level[id]], eXP[id], Level[id])
}
       
public 
CmdAddXP (iPlayerlevelcid)
{
    if(!
cmd_access(iPlayerlevelcid3)) return PLUGIN_HANDLED;
       
    new 
arg [32]
    
read_argv (1arg31)
 
    new 
AddXP [32]
    
read_argv (2AddXPcharsmax (AddXP))
 
    new 
XPtoGive str_to_num (AddXP)
       
    new 
AdminName [32]
    new 
TargetName [32]
    
get_user_name (iPlayerAdminNamecharsmax (AdminName))
       
    if(
arg[0]=='@')
    {
        if(
equali(arg[1],"All") || equali(arg[1],"ALL"))
        {
            new 
players[32], totalplayersAll
            get_players
(playerstotalplayers)
             
            for (new 
0totalplayersi++)
            {
                
All players[i]
                       
                
eXP[All] += XPtoGive
            
}
           
            
CheckLevel(All)
            
client_print_color(0print_chat"^4[Ranks]^1 ^3%s^1 dade^3 %i^1 XP na vsichki ^3igrachi^1!"AdminNameXPtoGive)
        }
        else if(
equali(arg[1],"T") || equali(arg[1],"t"))
        {
            new 
players[32], totalplayersT
            get_players
(playerstotalplayers)
             
            for (new 
0totalplayersi++)
            {
                if (
get_user_team(players[i]) == 1)
                {
                    
players[i]
                           
                    
eXP[T] += XPtoGive
                
}
            }
           
            
CheckLevel(T)
            
client_print_color(0print_chat"^4[Ranks]^1 ^3%s^1 dade^3 %i^1 XP na vsichki ^3 Teroristi^1."AdminNameXPtoGive)
        }
        else if(
equali(arg[1],"CT") || equali(arg[1],"ct"))
        {
            new 
players[32], totalplayersCT
            get_players
(playerstotalplayers)
             
            for(new 
0totalplayersi++)
            {
                if(
get_user_team(players[i]) == 2)
                {
                    
CT players[i]
                           
                    
eXP[CT] += XPtoGive
                
}
            }
           
            
CheckLevel(CT)
            
client_print_color(0print_chat"^4[Ranks]^1 ^3%s^1 dade^3 %i^1 XP na wsichki ^3 Kontra-Teroristi^1!"AdminNameXPtoGive)
        }
    }
    else
    {
        new 
iTarget cmd_target(iPlayerarg3)
        
get_user_name (iTargetTargetNamecharsmax (TargetName))
       
        if(
iTarget)
        {
            
eXP[iTarget] += XPtoGive
           
            CheckLevel
(iTarget)
            
client_print_color(0print_chat"^4[Ranks]^1 ^3%s^1 dade^3 %i^1 XP na^3 %s^1."AdminNameXPtoGiveTargetName)
        }
    }
    return 
PLUGIN_HANDLED
}
 
bool:IsValidMessageszMessage[ ], iLen )
{
    
read_argsszMessageiLen )
    
remove_quotesszMessage )
   
    new 
iPoscChar
    
while( <= ( cChar szMessageiPos++ ] ) <= 255 )
    {
        if( 
cChar != ' ' && cChar != '%' )
        {
            return 
true
        
}
    }
   
    return 
false
}
 
public 
hook_say(id)
{
    if(!
is_user_connected(id))
        return 
PLUGIN_HANDLED_MAIN
   
    
new szArgs[192]
   
    if( !
IsValidMessage(szArgscharsmax(szArgs)))
        return 
PLUGIN_HANDLED_MAIN
 
    
if(equal(szArgs,"")) return PLUGIN_HANDLED_MAIN
 
   
    
new szName[32]
    
get_user_name(idszNamesizeof szName-1)
 
    new 
alive is_user_alive(id)
 
    if(
contain(szArgs,"@") >= 0)
    return  
PLUGIN_HANDLED_MAIN
 
    
if(get_user_flags(id) & ADMIN1_ACCESS)
    
format(szArgs191,"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN1Prefix[Level[id]], szNameszArgs)
   
    else if(
get_user_flags(id) & ADMIN2_ACCESS)
    
format(szArgs191"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN2Prefix[Level[id]], szNameszArgs)
   
    else if(
get_user_flags(id) & ADMIN3_ACCESS)
    
format(szArgs191"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN3Prefix[Level[id]], szNameszArgs)
   
    else if(
get_user_flags(id) & ADMIN4_ACCESS)
    
format(szArgs191"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN4Prefix[Level[id]], szNameszArgs)
 
    else if(
get_user_flags(id) & ADMIN5_ACCESS)
    
format(szArgs191"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN5Prefix[Level[id]], szNameszArgs)
   
    else if(
get_user_flags(id) & ADMIN6_ACCESS)
    
format(szArgs191"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN6Prefix[Level[id]], szNameszArgs)
 
    else if(
get_user_flags(id) & ADMIN7_ACCESS)
    
format(szArgs191"^x03[%s] [%s] ^x04%s^x04 :^x03  %s"ADMIN7Prefix[Level[id]], szNameszArgs)
   
    else
    
format(szArgs191"^x03%s] ^x03%s^x01 :  %s",  Prefix[Level[id]], szNameszArgs)
 
    for(new 
1<= gMaxPlayersi++)
    {
        if(!
is_user_connected(i))
            continue
   
        if(
alive && is_user_alive(i))
        {
            
message_begin(MSG_ONEgMsgSayText, {000}, i)
            
write_byte(id)
            
write_string(szArgs)
            
message_end()
        }
        else if(!
alive && !is_user_alive(i))
        {
            new 
format[192]
            
formatex(format,191,"^x01*DEAD %s",szArgs)
            
message_begin(MSG_ONEgMsgSayText, {000}, i)
            
write_byte(id)
            
write_string(format)
            
message_end()
        }
    }
       
    return 
PLUGIN_HANDLED_MAIN
}
 
public 
SaveData(id)
{
    new 
name[32];
    
get_user_name(id,name,31);
    new 
vaultkey[64],vaultdata[256];
   
    
format(vaultkey,63,"%s"name);
    
format(vaultdata,255,"%i#%i#",eXP[id],Level[id]);
    
fvault_set_data(g_vault_name,vaultkey,vaultdata);
   
    return 
PLUGIN_CONTINUE;
}
public 
LoadData(id)
{
    new 
name[32];
    
get_user_name(id,name,31);
    new 
vaultkey[64],vaultdata[256];
   
    
format(vaultkey,63,"%s",name);
    
format(vaultdata,255,"%i#%i#",eXP[id],Level[id]);
    
fvault_get_data(g_vault_name,vaultkey,vaultdata,charsmax(vaultdata));
   
    
replace_all(vaultdata255"#"" ");
    new 
playerxp[32], playerlevel[32];
    
parse(vaultdataplayerxp31playerlevel31);
   
    
eXP[id] = str_to_num(playerxp);
    
Level[id] = str_to_num(playerlevel);
   
    return 
PLUGIN_CONTINUE;

Thanks for your time if you answer me.

Last edited by RaZ_HU; 05-13-2015 at 09:25. Reason: Language mistakes.
RaZ_HU is offline
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 02:46.


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