LSM 發表於 8-2-2009 20:12:53

[教學]教你整經驗值升Level AMXX

本帖最後由 LSM 於 9-2-2009 11:03 編輯



#include <amxmodx>
#include <amxmisc>
#include <nvault>   //save exp時用的


new PlayerXP,PlayerLevel   //新增變數playerEXP(經驗值) playerLevel(等級)

new XP_Kill,XP_Hs,SaveXP // 一個固定的經驗值
new g_vault//用來save的數字

new const LEVELS = {    //const 即 constant(常數) 此處為每級EXP 等級數目不可大於[]內數字
0,
100,//你需要100exp
200,//200 exp
400,//400exp
800,
1600,
99999//可防止某BUG
}


public plugin_init()   //大致上BBQ都教了
{
    register_plugin("EXPLEVELmod", "1.0", "LSM")
    register_event("DeathMsg", "eDeath", "a")   //殺人時發生 "eDeath" 時件
    SaveXP = register_cvar("SaveXP","1")
    XP_Kill=register_cvar("XP_per_kill", "20")   //指令 令殺人幾多exp
    XP_Hs=register_cvar("XP_hs_bonus","20")
    g_vault = nvault_open("expmod")            //開一個save 檔
    register_clcmd("say /class", "ChangeClass")
    register_clcmd("say_team /class", "ChangeClass")
    register_clcmd("say /xp", "ShowHud")
    register_clcmd("say_team /xp", "ShowHud")
}

public eDeath( ) //function name
{
    new killer = read_data( 1 )
    new iVictim = read_data( 2 )
    new headshot = read_data( 3 )
    PlayerXP += get_pcvar_num(XP_Kill) //殺手增加XP_Kill 咁多exp
    if(headshot)
    PlayerXP += get_pcvar_num(XP_Hs) //爆頭的附加exp
   while(PlayerXP >= LEVELS]) //當exp大於
    {
      client_print(killer, print_chat, " Congratulations! You are a level %i %s!", PlayerLevel,CLASSES])
      PlayerLevel += 1 //此變數加一
    }
    ShowHud(killer)
}

public ShowHud(id) //HUD顯示器
{
    set_hudmessage(255, 0, 0, 0.75, 0.01, 0, 6.0, 15.0)
    show_hudmessage(id, "Level: %i^nXP: %i^nClass: %s",PlayerLevel,PlayerXP)
}



public client_connect(id)//當某人入場
{
    if(get_pcvar_num(SaveXP) == 1)
    {
      // load save
      LoadData(id)
    }
}

public client_disconnect(id) //類似上面 當有人離場
{
   if(get_pcvar_num(SaveXP) == 1)
   {
          SaveData(id)
   }
}
public SaveData(id)
{

    new AuthID get_user_authid(id,AuthID,34)
    new vaultkey,vaultdata
    format(vaultkey,63,"%s-Mod",AuthID)
    format(vaultdata,255,"%i#%i#",PlayerXP,PlayerLevel)
    nvault_set(g_vault,vaultkey,vaultdata)
    return PLUGIN_CONTINUE
}


public LoadData(id)
{
    new AuthID get_user_authid(id,AuthID,34)
    new vaultkey,vaultdata
    // search
    format(vaultkey,63,"%s-Mod",AuthID)
    format(vaultdata,255,"%i#%i#",PlayerXP,PlayerLevel)
    // load the data
    nvault_get(g_vault,vaultkey,vaultdata,255)
    replace_all(vaultdata, 255, "#", " ")
    new playerxp, playerlevel
    parse(vaultdata, playerxp, 31, playerlevel, 31)
    PlayerXP = str_to_num(playerxp)
    PlayerLevel = str_to_num(playerlevel)
    return PLUGIN_CONTINUE
}


每個level 的能力




public levelfunc(id)//請設定一個引發的事件
{
   if playerLevel >= X    //某一lv
   {
             XXXXXXXXXX(id)          // 效果 (請自設)
   }
   每一lv 整一次
}

唔好kick我 發表於 8-2-2009 20:28:39

LSM 發表於 12-2-2009 20:56:24

2# 唔好kick我

升lv 的差不多都是這個寫法..

唔好kick我 發表於 12-2-2009 21:04:03

yathsing 發表於 12-2-2009 22:25:28

new AuthID get_user_authid(id,AuthID,34)

基本上 non-steam用唔到...

蘭仔 發表於 13-2-2009 07:24:16

5# yathsing

用get_user_ip._.?

pro_on_05 發表於 13-2-2009 15:58:43

緊系用get_user_name 啦._.

ip可能流動.

不能最好都系get_user_authid...

社會敗類 發表於 13-2-2009 18:38:41

唔該晒 但唔係好明~=.=

SoRrY]]* 發表於 13-2-2009 22:28:15

Willy.B 發表於 13-2-2009 23:03:55

頁: [1] 2
查看完整版本: [教學]教你整經驗值升Level AMXX