Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- #include <cstrike>
- #include <sqlx>
- #include <CSO_System>
- #include <nvault>
- #include <zombie_theheroex>
- #define PLUGIN "[CSO] System: Level"
- #define VERSION "1.0"
- #define AUTHOR "Dias Pendragon"
- // Use Medal System Also ?
- //#define USE_MEDALSYSTEM
- #define HUD_X 0.02
- #define HUD_Y 0.30
- // SAVE TYPE
- #define SAVE_TYPE 1 // 1 - Nvault | 2 - MySQL (Check Database Info)
- // MySQL Config
- #define SQL_HOST "127.0.0.1"
- #define SQL_DB "databasename"
- #define SQL_USERNAME "user"
- #define SQL_PASSWORD "pass"
- new Handle:g_SQL_Id, g_SQL_Error[128], g_SQL_Query[512]
- // Profile Config
- #define SOUND_LVUP "cso_system/lvup.wav"
- #define SOUND_PROMOTED "cso_system/promoted.wav"
- new g_PlayerLevel[33], g_PlayerExp[33]
- // Level Configs
- #define MAX_LEVEL 30
- new const LevelTitle[MAX_LEVEL+1][] =
- {
- "[NONE]", // 0 - There is no level 0 :)
- "Recruit", // 1
- "Private", "Private First Class", "Corporal",
- "Sergeant", // 5
- "Staff Sergeant (1st)", "Staff Sergeant (Final)", "Sergeant First Class (1st)", "Sergeant First Class (2nd)",
- "Sergeant First Class (Final)", // 10
- "Master Sergeant (1st)", "Master Sergeant (2nd)", "Master Sergeant (Final)", "Sergeant Major (1st)",
- "Sergeant Major (2nd)", // 15
- "Sergeant Major (3rd)", "Sergeant Major (Final)", "Second Lieutenant (1st)", "Second Lieutenant (2nd)",
- "Second Lieutenant (3rd)", // 20
- "Second Lieutenant (4th)", "Second Lieutenant (Final)", "First Lieutenant (1st)", "First Lieutenant (2nd)",
- "First Lieutenant (3rd)", // 25
- "First Lieutenant (4th)", "First Lieutenant (Final)", "Captain (1st)", "Captain (2nd)", "Captain (3rd)" // 30
- }
- new const LevelExp[MAX_LEVEL+1] =
- {
- 0, // Level 0 lol
- 0, // 5000 Money
- 30, // 7000
- 50, // 8000
- 70, // 9000
- 100, // 10000
- 300, //12000
- 400, // 15000
- 500, // 20000
- 600, // 25000
- 700, // 30000
- 800, // 35000
- 900, //40000
- 1100, // 45000
- 1300, // 50000
- 2000, // 55000
- 2200, // 60000
- 2400, // 70000
- 2600, // 80000
- 2800, // 90000
- 3000, // 100000
- 3400, // 110000
- 3800, // 120000
- 4200, // 130000
- 4500, // 140000
- 5000, // 150000
- 5400, // 160000
- 5800, // 170000
- 6200, // 180000
- 6600, // 190000
- 7000 // 190000
- }
- // Task
- #define TASK_LVUP_SOUND1 49651
- #define TASK_LVUP_SOUND2 49652
- // Message
- enum _:MAX_TYPES
- {
- TYPE_NONE,
- TYPE_RELATION,
- TYPE_PLAYER,
- TYPE_HEALTH
- }
- enum
- {
- LOOK_FRIEND = 1,
- LOOK_ENEMY,
- LOOK_HOSTAGE,
- }
- new StatusValue[MAX_TYPES]
- // Language (Becareful when changing those ones)
- #define NOTICE_LEVELUP "!g**** Congratulation! **** [%s] has been promoted to Lv.%i [%s]!n"
- #define STATUS_FRIEND "%s - %iHP (Lv.%i - Exp: %i percent)"
- #define STATUS_FRIEND_MEDAL "[%s] %s - %iHP (Lv.%i - Exp: %i percent)"
- #define STATUS_ENEMY "%s (Lv.%i - Exp: %i percent)"
- #define STATUS_ENEMY_MEDAL "[%s] %s (Lv.%i - Exp: %i percent)"
- new g_MaxPlayers, g_MsgSayText, g_MsgStatusText
- new g_Forward_LevelUp, g_fwResult, g_VaultID
- new g_Hud
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
- register_logevent("Event_RoundEnd", 2, "1=Round_End")
- g_Hud = zbheroex_get_synchud_id(SYNCHUD_ZBHM_SKILL1)
- // Initialize MySql System
- new Type; Type = SAVE_TYPE
- if(Type == 1) g_VaultID = nvault_open("CSO_Level")
- else if(Type == 2) MySQL_Init()
- // Event
- register_event("StatusValue", "Event_StatusValue", "b")
- /// Forwards
- g_Forward_LevelUp = CreateMultiForward("CSO_System_LevelUp", ET_IGNORE, FP_CELL, FP_CELL)
- // Get Data
- g_MaxPlayers = get_maxplayers()
- g_MsgSayText = get_user_msgid("SayText")
- g_MsgStatusText = get_user_msgid("StatusText")
- // Command
- register_clcmd("say /player", "CMD_PlayerInfo")
- }
- public plugin_end() nvault_close(g_VaultID)
- public plugin_precache()
- {
- precache_sound(SOUND_LVUP)
- precache_sound(SOUND_PROMOTED)
- }
- public plugin_natives()
- {
- register_native("CSO_System_Level_GainExp", "Native_GainExp", 1)
- register_native("CSO_System_Level_SetLv", "Native_SetLv", 1)
- register_native("CSO_System_Level_GetLv", "Native_GetLv", 1)
- register_native("CSO_System_Level_SetExp", "Native_SetExp", 1)
- register_native("CSO_System_Level_GetExp", "Native_GetExp", 1)
- }
- public client_putinserver(id)
- {
- Clear_PlayerLevel(id)
- Load_PlayerLevel(id)
- }
- public client_disconnect(id)
- {
- Save_PlayerLevel(id)
- }
- public client_connect(id)
- {
- Load_PlayerLevel(id)
- }
- public Event_NewRound()
- {
- for(new i = 0; i < g_MaxPlayers; i++)
- {
- if(!is_user_connected(i))
- continue
- Save_PlayerLevel(i)
- }
- }
- public Event_RoundEnd(id)
- {
- new Type; Type = SAVE_TYPE
- if(Type == 1) g_VaultID = nvault_open("CSO_Level")
- Save_PlayerLevel(id)
- }
- // ============================================================
- // --------------------- Natives Functions --------------------
- public Native_GainExp(id, Exp, CheckLvUp)
- {
- if(!is_user_connected(id))
- return
- Level_GainExp(id, Exp, CheckLvUp)
- }
- public Native_SetLv(id, Level)
- {
- if(!is_user_connected(id))
- return
- if(Level > MAX_LEVEL)
- return
- g_PlayerLevel[id] = Level
- }
- public Native_GetLv(id)
- {
- if(!is_user_connected(id))
- return 0
- return g_PlayerLevel[id]
- }
- public Native_SetExp(id, Exp)
- {
- if(!is_user_connected(id))
- return
- g_PlayerExp[id] = Exp
- }
- public Native_GetExp(id)
- {
- if(!is_user_connected(id))
- return 0
- return g_PlayerExp[id]
- }
- // ============================================================
- // ------------------ Main Level Functions --------------------
- public Level_GainExp(id, Exp, CheckLvUp)
- {
- g_PlayerExp[id] += Exp
- if(CheckLvUp) Level_CheckUp(id)
- Save_PlayerLevel(id)
- }
- public Level_CheckUp(id)
- {
- if(g_PlayerLevel[id] >= MAX_LEVEL)
- return
- static HadLevelUp; HadLevelUp = 0
- while(g_PlayerExp[id] >= LevelExp[g_PlayerLevel[id]+1])
- {
- g_PlayerLevel[id]++
- HadLevelUp = 1
- }
- if(HadLevelUp)
- { // Player Level Up!
- PlaySound(id, SOUND_LVUP)
- static Name[32]
- get_user_name(id, Name, sizeof(Name))
- set_task(1.0, "Sound_LevelUp_Repeat", id+TASK_LVUP_SOUND1)
- set_task(2.25, "Sound_LevelUp_Promoted", id+TASK_LVUP_SOUND2)
- client_printc(0, NOTICE_LEVELUP, Name, g_PlayerLevel[id], LevelTitle[g_PlayerLevel[id]])
- // Run Forward
- ExecuteForward(g_Forward_LevelUp, g_fwResult, id, g_PlayerLevel[id])
- }
- }
- public Sound_LevelUp_Repeat(id)
- {
- id -= TASK_LVUP_SOUND1
- if(!is_user_connected(id))
- return
- PlaySound(id, SOUND_LVUP)
- set_task(1.0, "Sound_LevelUp_Repeat", id+TASK_LVUP_SOUND1)
- }
- public Sound_LevelUp_Promoted(id)
- {
- id -= TASK_LVUP_SOUND2
- remove_task(id+TASK_LVUP_SOUND1)
- remove_task(id+TASK_LVUP_SOUND2)
- if(!is_user_connected(id))
- return
- PlaySound(id, SOUND_PROMOTED)
- }
- public zbheroex_skill_show(id, Zombie)
- {
- if(!Zombie)
- {
- if(g_PlayerLevel[id] >= MAX_LEVEL)
- {
- set_hudmessage(0, 0, 255, HUD_X, HUD_Y, 0, 2.0, 2.0)
- ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i]", g_PlayerLevel[id], g_PlayerExp[id])
- } else {
- set_hudmessage(0, 0, 255, HUD_X, HUD_Y, 0, 2.0, 2.0)
- ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i/%i]", g_PlayerLevel[id], g_PlayerExp[id], LevelExp[g_PlayerLevel[id]+1])
- }
- } else {
- if(g_PlayerLevel[id] >= MAX_LEVEL)
- {
- set_hudmessage(255, 0, 0, HUD_X, HUD_Y, 0, 2.0, 2.0)
- ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i]", g_PlayerLevel[id], g_PlayerExp[id])
- } else {
- set_hudmessage(255, 0, 0, HUD_X, HUD_Y, 0, 2.0, 2.0)
- ShowSyncHudMsg(id, g_Hud, "[Level: %i]^n[Exp: %i/%i]", g_PlayerLevel[id], g_PlayerExp[id], LevelExp[g_PlayerLevel[id]+1])
- }
- }
- }
- // ============================================================
- // ------------------------- Check Info -----------------------
- public CMD_PlayerInfo(id)
- {
- if(!is_user_connected(id))
- return
- static Body, Target; get_user_aiming(id, Target, Body, 9999)
- static Menu; Menu = menu_create("Players Infomation", "MenuHandle_PlayerInfo")
- static Name[32], Text[64], IdNumber[4]
- for(new i = 0; i < g_MaxPlayers; i++)
- {
- if(!is_user_connected(i))
- continue
- get_user_name(i, Name, sizeof(Name))
- switch(cs_get_user_team(i))
- {
- case CS_TEAM_SPECTATOR: formatex(Text, sizeof(Text), "%s (SPEC)", Name)
- case CS_TEAM_T: formatex(Text, sizeof(Text), "%s (T)", Name)
- case CS_TEAM_CT: formatex(Text, sizeof(Text), "%s (CT)", Name)
- }
- num_to_str(i, IdNumber, sizeof(IdNumber))
- menu_additem(Menu, Text, IdNumber)
- }
- menu_setprop(Menu, MPROP_EXIT, MEXIT_ALL)
- menu_display(id, Menu, 0)
- }
- public MenuHandle_PlayerInfo(id, Menu, Item)
- {
- if(Item == MENU_EXIT)
- {
- menu_destroy(Menu)
- return PLUGIN_HANDLED
- }
- static Name[32], IdNumber[4]
- static ItemCallback, ItemAccess
- menu_item_getinfo(Menu, Item, ItemAccess, IdNumber, charsmax(IdNumber), Name, charsmax(Name), ItemCallback)
- static Player; Player = str_to_num(IdNumber)
- if(!is_user_connected(Player))
- {
- menu_destroy(Menu)
- return PLUGIN_HANDLED
- }
- Show_Information(id, Player)
- menu_destroy(Menu)
- return PLUGIN_HANDLED
- }
- public Show_Information(id, Player)
- {
- static Name[32]; get_user_name(Player, Name, sizeof(Name))
- static Header[64]; formatex(Header, sizeof(Header), "Player Information: %s", Name)
- static Motd[512], Float:Percent
- Percent = float(g_PlayerExp[Player]) / float(LevelExp[g_PlayerLevel[Player] + 1]) * 100.0
- formatex(Motd, sizeof(Motd), "<center><h2><b>%s</b></h2><br><br><b>Level:</b> %i<br><b>Experience:</b> %i/%i (%i%%)</center>", Name, g_PlayerLevel[Player], g_PlayerExp[Player], LevelExp[g_PlayerLevel[Player] + 1], floatround(Percent))
- #if defined USE_MEDALSYSTEM
- static MedalText[400]
- if(CSO_System_Medal_GetUsingMedal(Player) != -1)
- {
- static Medal[32]; CSO_System_Medal_GetTitle(Player, Medal)
- static HonorPoint; HonorPoint = CSO_System_Medal_GetTotalHonorPoint(Player)
- CSO_System_Medal_GetList(Player, MedalText)
- formatex(Motd, sizeof(Motd), "<center><h2><b>[%s] %s</b></h2><br><br><b>Level:</b> %i<br><b>Experience:</b> %i/%i (%i%%)<br><b>Total Honor Points:</b> %i<br><b>Medal List:</b> %s</center>", Medal, Name, g_PlayerLevel[Player], g_PlayerExp[Player], LevelExp[g_PlayerLevel[Player] + 1], floatround(Percent), HonorPoint, MedalText)
- } else {
- static HonorPoint; HonorPoint = CSO_System_Medal_GetTotalHonorPoint(Player)
- CSO_System_Medal_GetList(Player, MedalText)
- formatex(Motd, sizeof(Motd), "<center><h2><b>%s</b></h2><br><br><b>Level:</b> %i<br><b>Experience:</b> %i/%i (%i%%)<br><b>Total Honor Points:</b> %i<br><b>Medal List:</b> %s</center>", Name, g_PlayerLevel[Player], g_PlayerExp[Player], LevelExp[g_PlayerLevel[Player] + 1], floatround(Percent), HonorPoint, MedalText)
- }
- #endif
- show_motd(id, Motd, Header)
- }
- // ============================================================
- // --------------------------- Event --------------------------
- public Event_StatusValue(id)
- {
- static Num; Num = read_data(1)
- if(Num <= 0 || Num >= MAX_TYPES)
- return
- static Update; Update = StatusValue[Num] = read_data(2)
- switch(Num)
- {
- case TYPE_RELATION:
- {
- if(!Update && is_user_alive(id))
- {
- message_begin(MSG_ONE_UNRELIABLE, g_MsgStatusText, _, id)
- write_byte(0)
- write_string("")
- message_end()
- }
- }
- case TYPE_PLAYER:
- {
- if(is_user_alive(id))
- {
- new Message[192], Float:Percent
- new PlayerName[32];
- copy(PlayerName, sizeof(PlayerName), "%p2")
- switch(StatusValue[TYPE_RELATION])
- {
- case LOOK_FRIEND:
- {
- Percent = float(g_PlayerExp[Update]) / float(LevelExp[g_PlayerLevel[Update] + 1]) * 100.0
- formatex(Message, sizeof(Message), STATUS_FRIEND, PlayerName, get_user_health(Update), g_PlayerLevel[Update], floatround(Percent))
- #if defined USE_MEDALSYSTEM
- if(CSO_System_Medal_GetUsingMedal(Update) != -1)
- {
- static Medal[64]; CSO_System_Medal_GetTitle(Update, Medal)
- formatex(Message, sizeof(Message), STATUS_FRIEND_MEDAL, Medal, PlayerName, get_user_health(Update), g_PlayerLevel[Update], floatround(Percent))
- }
- #endif
- }
- case LOOK_ENEMY:
- {
- Percent = float(g_PlayerExp[Update]) / float(LevelExp[g_PlayerLevel[Update] + 1]) * 100.0
- formatex(Message, sizeof(Message), STATUS_ENEMY, PlayerName, g_PlayerLevel[Update], floatround(Percent))
- #if defined USE_MEDALSYSTEM
- if(CSO_System_Medal_GetUsingMedal(Update) != -1)
- {
- static Medal[64]; CSO_System_Medal_GetTitle(Update, Medal)
- formatex(Message, sizeof(Message), STATUS_ENEMY_MEDAL, Medal, PlayerName, g_PlayerLevel[Update], floatround(Percent))
- }
- #endif
- }
- case LOOK_HOSTAGE:
- {
- return;
- }
- }
- message_begin(MSG_ONE_UNRELIABLE, g_MsgStatusText, _, id)
- write_byte(0)
- write_string(Message)
- message_end()
- }
- }
- }
- }
- // ============================================================
- // ---------------------- MySQL Functions ---------------------
- public MySQL_Init()
- {
- server_print("[MySQL] Initializing...")
- g_SQL_Id = SQL_MakeDbTuple(SQL_HOST, SQL_USERNAME, SQL_PASSWORD, SQL_DB)
- new ErrorCode, Handle:SqlConnection = SQL_Connect(g_SQL_Id, ErrorCode, g_SQL_Error, charsmax(g_SQL_Error))
- if(SqlConnection == Empty_Handle)
- set_fail_state(g_SQL_Error)
- new Handle:Queries
- Queries = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS Level (PlayerName varchar(32), Level INT(8), Exp INT(16))")
- if(!SQL_Execute(Queries))
- {
- SQL_QueryError(Queries, g_SQL_Error, charsmax(g_SQL_Error))
- set_fail_state(g_SQL_Error)
- }
- SQL_FreeHandle(Queries)
- SQL_FreeHandle(SqlConnection)
- server_print("[MySQL] Initialize: Completed!")
- }
- public Load_PlayerLevel(id)
- {
- new Type; Type = SAVE_TYPE
- static PlayerName[32]
- get_user_name(id, PlayerName, sizeof(PlayerName))
- if(Type == 1)
- {
- static VaultKey[64], VaultData[256]
- // Search
- format(VaultKey, 63,"%s-Level", PlayerName)
- format(VaultData, 255,"%i#%i#", g_PlayerExp[id], g_PlayerLevel[id])
- // Load the Data
- nvault_get(g_VaultID, VaultKey, VaultData,255)
- replace_all(VaultData, 255, "#", " ")
- static PlayerExp[32], PlayerLevel[32]
- parse(VaultData, PlayerExp, 31, PlayerLevel, 31)
- // Set Data
- g_PlayerExp[id] = str_to_num(PlayerExp)
- g_PlayerLevel[id] = str_to_num(PlayerLevel)
- } else if(Type == 2) {
- static Data[1]; Data[0] = id
- format(g_SQL_Query, charsmax(g_SQL_Query),"SELECT * FROM `Level` WHERE (`Level`.`PlayerName` = '%s')", PlayerName)
- SQL_ThreadQuery(g_SQL_Id, "SQLHandle_LoadLevel", g_SQL_Query, Data, sizeof(Data))
- }
- }
- public Save_PlayerLevel(id)
- {
- new Type; Type = SAVE_TYPE
- static PlayerName[32]
- get_user_name(id, PlayerName, sizeof(PlayerName))
- if(Type == 1)
- {
- // get the players steam id. We need this because we are saving by steam id
- static VaultKey[64], VaultData[256]
- // format wat is going to be in the animal mod vault file
- format(VaultKey, 63,"%s-Level", PlayerName)
- format(VaultData, 255,"%i#%i#", g_PlayerExp[id], g_PlayerLevel[id])
- // save the data
- nvault_set(g_VaultID, VaultKey, VaultData)
- } else if(Type == 2) {
- format(g_SQL_Query, charsmax(g_SQL_Query),"UPDATE `Level` SET `Level` = '%i', `Exp` = '%i' WHERE `Level`.`PlayerName` = '%s';", g_PlayerLevel[id], g_PlayerExp[id], PlayerName)
- SQL_ThreadQuery(g_SQL_Id, "SQLHandle_Ignore", g_SQL_Query)
- }
- }
- public Clear_PlayerLevel(id)
- {
- g_PlayerLevel[id] = 1
- g_PlayerExp[id] = 0
- }
- public SQLHandle_LoadLevel(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
- {
- if(FailState == TQUERY_CONNECT_FAILED)
- log_amx("[MySQL] Error (Load): Could not connect to SQL Database. [%d] %s", Errcode, Error)
- else if(FailState == TQUERY_QUERY_FAILED)
- log_amx("[MySQL] Error (Load): Query failed. [%d] %s", Errcode, Error)
- static id; id = Data[0]
- if(SQL_NumResults(Query) < 1)
- { // if there are no results found
- static PlayerName[32]
- get_user_name(id, PlayerName, sizeof(PlayerName))
- format(g_SQL_Query, charsmax(g_SQL_Query), "INSERT INTO `Level` ( `PlayerName` , `Level` , `Exp`)VALUES ('%s' , '1' , '0');", PlayerName)
- SQL_ThreadQuery(g_SQL_Id, "SQLHandle_Ignore", g_SQL_Query)
- } else {
- g_PlayerLevel[id] = SQL_ReadResult(Query, 1)
- g_PlayerExp[id] = SQL_ReadResult(Query, 2)
- client_printc(id, "!g[Level]!n Loading Completed!")
- }
- return PLUGIN_HANDLED
- }
- public SQLHandle_Ignore(FailState, Handle:Query, Error[], Errcode, Data[], DataSize)
- {
- SQL_FreeHandle(Query)
- return PLUGIN_HANDLED
- }
- // ===================================================
- // ---------------------- Stocks ---------------------
- stock PlaySound(id, const sound[])
- {
- if(equal(sound[strlen(sound)-4], ".mp3")) client_cmd(id, "mp3 play ^"sound/%s^"", sound)
- else client_cmd(id, "spk ^"%s^"", sound)
- }
- stock client_printc(index, const text[], any:...)
- {
- static szMsg[128]; vformat(szMsg, sizeof(szMsg) - 1, text, 3)
- replace_all(szMsg, sizeof(szMsg) - 1, "!g", "^x04")
- replace_all(szMsg, sizeof(szMsg) - 1, "!n", "^x01")
- replace_all(szMsg, sizeof(szMsg) - 1, "!t", "^x03")
- if(!index)
- {
- for(new i = 0; i < g_MaxPlayers; i++)
- {
- if(!is_user_connected(i))
- continue
- message_begin(MSG_ONE_UNRELIABLE, g_MsgSayText, _, i);
- write_byte(i);
- write_string(szMsg);
- message_end();
- }
- } else {
- message_begin(MSG_ONE_UNRELIABLE, g_MsgSayText, _, index);
- write_byte(index);
- write_string(szMsg);
- message_end();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement