Kód:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <fun>
#include <cstrike>
#include <nvault>
#include <sqlx>
#define VERSION "1.0b3"
#define MAX_PLAYERS 32
#define UPDATE_INTERVAL 0.1 //do not modify
#define TID_TIMER 3536
#define MAX_LVL 50000
#define MAX_XP_MULTI 10000.0
#define MAX_UPGS 12
#define UPG_REGEN 0
#define UPG_HEALTH 1
#define UPG_RESUP 2
#define UPG_VAMP 3
#define UPG_STEALTH 4
#define UPG_LJ 5
#define UPG_ICESTAB 6
#define UPG_FROST 7
#define UPG_DENIAL 8
#define UPG_IMPULSE 9
#define UPG_MEDIC 10
#define UPG_BHOP 11
#define DENIAL_BLOCK -3
#define DENIAL_NEXT_SPAWN -4
#define DENIAL_START 10
#define DENIAL_STRIP 8
#define DENIAL_GIVE 7
#define CREDITS_PER_LVL 5
#define CXT_KILL 0 //arg1: attacker, arg2: victim
#define CXT_DMG 1 //arg1: attacker, arg2: victim, arg3: dmg_amount
#define XP_START 600
#define XP_INC 5
#define DATA_NOT_LOADED 0
#define DATA_NOT_FOUND 1
#define DATA_LOADED 2
#define DATA_LOADING 3
#define SAVEBY_STEAMID 1
#define SAVEBY_IP 2
#define SAVEBY_NAME 3
#define SAVEBY_LOGIN 4 //special case (g_saveby is never equal 4)
#define SAVEBY_BOT 5 //special case (g_saveby is never equal 5)
#define SAVEDB_NVAULT 1
#define SAVEDB_MYSQL 2
#define REG_NONE 1
#define REG_TRY 2
#define REG_DONE 3
#define DB_NONE 0
#define DB_CONNECTING 1
#define DB_READY 2
#define LOGIN_COOLDOWN 10.0
#define FREQ_S_NONE 0
#define FREQ_S_NEW_ROUND 1
#define FREQ_S_INTERVAL 2
#define MAX_SETTINGS 2
#define SETT_MENU_ON_SPAWN 0
#define SETT_INFO_UNDER_CHAT 1
new g_max_players
new Float:g_t_time
new g_timer_entid
new Float:g_p_login_time[MAX_PLAYERS+1]
new g_p_xp[MAX_PLAYERS+1]
new g_p_temp_xp[MAX_PLAYERS+1] //xp gained since last save
new g_p_credits[MAX_PLAYERS+1]
new g_p_upg[MAX_PLAYERS+1][MAX_UPGS]
new g_p_level[MAX_PLAYERS+1]
new g_p_progress[MAX_PLAYERS+1]
new g_p_menu_page[MAX_PLAYERS+1]
new g_p_team[MAX_PLAYERS+1]
new g_p_settings[MAX_PLAYERS+1][MAX_SETTINGS]
new g_settings_maxval[MAX_SETTINGS] = {1, 1}
new g_settings_default[MAX_SETTINGS+1] = "11"
new bool:g_p_authorized[MAX_PLAYERS+1]
new bool:g_upg_enabled[MAX_UPGS]
new g_enabled_upgs
new g_enabled_list[MAX_UPGS]
new g_upg_name[MAX_UPGS][32] = {"Regenera'cio'", "E'let+", "tolte'ny uta'npo'tla's", "Ve'rsziva's", "A'tla'tszo'sa'g",
"Hoszu' ugra's", "Dermeszto csapa's", "Fagyaszto lovede'kek", "Ragaszkoda's", "Impulzus", "Medikus", "Bunnyhop" }
new g_upg_sp[MAX_UPGS] = {20,30,10,60,30,30,110,5,100,40,20,100}
new g_upg_ip[MAX_UPGS] = {25,35,5,25,25,25,90,5,5,25,5,900}
new g_upg_maxlvl[MAX_UPGS] = {10, 10, 10, 15, 5, 5, 3, 15, 1, 5, 15, 2}
new g_p_sm_upg[MAX_PLAYERS+1][MAX_UPGS] //list of upgs displayed in sell menu
new g_p_sm_upg_cnt[MAX_PLAYERS+1] //amount of upgs on the list
new g_max_bpammo[33] = {0,52,0,90,1,32,1,100,90,1,120,100,100,90,90,90,100,120,30,120,200,32,90,120,90,2,35,90,90,0,100,0,0}
new g_gi_names[32][32] = {"", "weapon_p228", "", "weapon_scout", "weapon_hegrenade",
"weapon_xm1014", "weapon_c4", "weapon_mac10", "weapon_aug", "weapon_smokegrenade", "weapon_elite",
"weapon_fiveseven", "weapon_ump45", "weapon_sg550", "weapon_galil", "weapon_famas", "weapon_usp", "weapon_glock18",
"weapon_awp", "weapon_mp5navy", "weapon_m249", "weapon_m3", "weapon_m4a1", "weapon_tmp",
"weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552", "weapon_ak47",
"weapon_knife", "weapon_p90", ""}
new Float:g_weap_speed[32] = {0.0, 250.0, 0.0, 260.0, 250.0, 240.0, 250.0, 250.0, 240.0,
250.0, 250.0, 250.0, 250.0, 210.0, 240.0, 240.0, 250.0, 250.0, 210.0, 250.0, 220.0, 230.0,
230.0, 250.0, 210.0, 250.0, 250.0, 235.0, 221.0, 250.0, 245.0, 0.0}
new pc_xp_mult
new pc_upgs
new Float:g_mradius
new Float:g_sq_mradius
new Float:g_p_angle[MAX_PLAYERS+1][3]
new g_c_regen[MAX_PLAYERS+1]
new g_p_maxhealth[MAX_PLAYERS+1]
new g_c_resup[MAX_PLAYERS+1]
new Float:g_p_next_lj[MAX_PLAYERS+1]
new bool:g_p_jump[MAX_PLAYERS+1]
new g_c_frost[MAX_PLAYERS+1]
new g_c_ice[MAX_PLAYERS+1]
new g_c_denial[MAX_PLAYERS+1]
new g_c_impulse[MAX_PLAYERS+1]
new g_c_medic[MAX_PLAYERS+1]
new bool:g_block_denial //if true, denial will not work on next round
new g_p_buttons[MAX_PLAYERS+1]
new bool:g_p_alive[MAX_PLAYERS+1]
new g_p_weap_num[MAX_PLAYERS+1]
new g_p_weap[MAX_PLAYERS+1][32]
new g_p_has_c4[MAX_PLAYERS+1]
new CsArmorType:g_p_atype[MAX_PLAYERS+1]
new g_p_armor[MAX_PLAYERS+1]
new Float:g_xp_multipler
new g_msgStatusText
new pc_savedata
new pc_saveby
new pc_savedb
new pc_frequent_save
new pc_sql_host
new pc_sql_user
new pc_sql_pass
new pc_sql_db
new pc_start_lvl
new pc_bot_start_lvl
new pc_bot_savedata
new pc_bot_buy_upgrades
new pc_def_upgs
new pc_bot_def_upgs
new pc_user_control
new pc_in_team
new bool:g_freezetime
new g_p_authid[MAX_PLAYERS+1][32]
new g_p_ip[MAX_PLAYERS+1][32]
new g_p_name[MAX_PLAYERS+1][32]
new g_p_data_loaded[MAX_PLAYERS+1]
new g_p_defkit[MAX_PLAYERS+1]
new g_saveby
new g_saveby_name[6][16] = {"", "rpgm_sid", "rpgm_ip", "rpgm_name", "rpgm_reg", "rpgm_bot"}
new g_savedb
new g_p_username[MAX_PLAYERS+1][32]
new g_p_password[MAX_PLAYERS+1][32]
new g_p_login_status[MAX_PLAYERS+1]
new bool:g_p_pw_hidden[MAX_PLAYERS+1]
new Handle:g_sql_tuple
new Handle:g_sql_connection
new g_db_status
new g_sql_tables
new g_frequent_save
new g_bot_savedata
new g_bot_def_upgs[MAX_UPGS]
new g_bot_def_cost
new g_bot_def_lvl_req
new g_def_upgs[MAX_UPGS]
new g_def_cost
new g_def_lvl_req
new g_user_control
new g_in_team
public plugin_init(){
register_plugin("RPG mod", VERSION, "Sylwester")
register_cvar("rpgm_ver", VERSION, FCVAR_SERVER)
g_msgStatusText = get_user_msgid("StatusText")
g_max_players = get_maxplayers()
register_clcmd("say", "handle_say")
register_clcmd("say_team", "handle_say")
register_clcmd("rpgmenu", "menu_main")
register_clcmd("amx_rpglogin", "rpg_login", -1, "<felhaszna'lo'> <jelszo'> ")
register_clcmd("amx_rpg_lvl", "change_lvl_cmd", ADMIN_CVAR, "<@all|@t|@ct|#userid|name> <+|=|-> <amount> - changes target level ")
register_clcmd("amx_rpg_drop_upgs", "drop_upg_cmd", ADMIN_CVAR, "<@all|@t|@ct|#userid|name> - forces target(s) to sell all upgrades ")
register_clcmd("amx_rpg_set_upgs", "set_upg_cmd", ADMIN_CVAR, "<@all|@t|@ct|#userid|name> <upgrades string> - set target(s) upgrades ")
register_srvcmd("amx_rpg_global_reset", "global_data_reset", ADMIN_CVAR, "<RENAME|DELETE> - rename or delete all current data files/tables ")
pc_xp_mult = register_cvar("rpgm_xp_mult", "1.0", 0, 1.0)
pc_upgs = register_cvar("rpgm_upgs", "111111111111")
pc_savedata = register_cvar("rpgm_savedata", "1") //1 - yes //0 - no
pc_saveby = register_cvar("rpgm_saveby", "1") //1 - steamid //2 - ip //3 - name
pc_savedb = register_cvar("rpgm_savedb", "1") //1 - nvault //2 - sql
pc_frequent_save = register_cvar("rpgm_frequent_save", "0")
//0-save only on disconnect //1-save all on new round
//2-every 10secs save player with highest xp gained since last save
pc_start_lvl = register_cvar("rpgm_start_lvl", "0")
pc_bot_start_lvl = register_cvar("rpgm_bot_start_lvl", "0")
pc_bot_savedata = register_cvar("rpgm_bot_savedata", "0")
pc_bot_buy_upgrades = register_cvar("rpgm_bot_buy_upgrades", "0")
pc_def_upgs = register_cvar("rpgm_def_upgrades", "000000000000")
pc_bot_def_upgs = register_cvar("rpgm_bot_def_upgrades", "0000000000000")
pc_user_control = register_cvar("rpgm_user_control", "1")
pc_sql_host = register_cvar("rpgm_sql_host", "")
pc_sql_user = register_cvar("rpgm_sql_user", "")
pc_sql_pass = register_cvar("rpgm_sql_pass", "")
pc_sql_db = register_cvar("rpgm_sql_db", "")
pc_in_team = register_cvar("rpgm_in_team", "0") //0-both team //1-only terro //2-only ct
register_event("Damage", "damage_event", "b", "2!0")
register_event("DeathMsg", "player_death", "a")
register_event("CurWeapon", "event_CurWeapon", "be", "1=1")
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
register_logevent("logevent_round_start", 2, "1=Round_Start")
register_event("TextMsg", "block_denial", "a", "2&#Game_C") //game commencing
register_event("TextMsg", "block_denial", "a", "2&#Game_will_restart_in") //round restart
register_message(get_user_msgid("Health"), "fix_0hp")
register_menucmd(register_menuid("\yRPG mod \d[#]"), 1023, "hnd_menu_main")
register_menucmd(register_menuid("\yRPG mod \d[#.1]"), 1023, "hnd_menu_buy_upg")
register_menucmd(register_menuid("\yRPG mod \d[#.2]"), 1023, "hnd_menu_sell_upg")
register_menucmd(register_menuid("\yRPG mod \d[#.4]"), 1023, "hnd_menu_help")
register_menucmd(register_menuid("\yRPG mod \d[#.5]"), 1023, "hnd_menu_settings")
register_menucmd(register_menuid("\yRPG mod \d[#.6]"), 1023, "hnd_menu_data")
RegisterHam(Ham_Spawn, "player", "player_spawn", 1)
register_forward(FM_PlayerPreThink, "player_PreThink")
register_forward(FM_PlayerPostThink, "player_PostThink")
register_forward(FM_CmdStart,"fwd_CmdStart")
//exec_cfg_file() //rpg mod cfg file unfinished
create_timer()
g_db_status = DB_NONE
set_task(0.1, "prepare_database")
}
public global_data_reset(id, level, cid){
new arg[32], path[128], file[128], cache[128], temp[128], file2[128]
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
read_args(arg, 31)
if(g_db_status == DB_NONE){
log_amx("SERVER: [ amx_rpg_global_reset %s ] - adatba'zis nincs csatlakozva", arg)
return PLUGIN_HANDLED
}
get_datadir(path, 127)
format(path, 127, "%s/vault/", path)
if(contain(arg, "DELETE")==0){
g_db_status = DB_NONE
if(g_savedb==SAVEDB_NVAULT){
for(new i=1; i<6; i++){
format(file, 127, "%s%s.vault", path, g_saveby_name[i])
if(file_exists(file) && !delete_file(file)){
log_amx("SERVER: [ amx_rpg_global_reset %s ] - Sikertelen pro'ba'lja meg ujra %s", arg, file)
return PLUGIN_HANDLED
}
}
}else if(g_savedb==SAVEDB_MYSQL){
for(new i=1; i<6; i++){
format(cache, 127, "drop table if exists %s;", g_saveby_name[i])
SQL_ThreadQuery(g_sql_tuple, "handle_change_table_query", cache)
}
}
}else if(contain(arg, "RENAME")==0){
g_db_status = DB_NONE
get_time("%y%m%d%H%M%S", temp, 127)
if(g_savedb==SAVEDB_NVAULT){
for(new i=1; i<6; i++){
format(file, 127, "%s%s.vault", path, g_saveby_name[i])
format(file2, 127, "%s%s_%s.vault", path, temp, g_saveby_name[i])
if(file_exists(file) && !rename_file(file, file2, 1)){
log_amx("SERVER: [ amx_rpg_global_reset %s ] - Sikertelen proba'lja ma'shogy %s", arg, file)
return PLUGIN_HANDLED
}
}
}else if(g_savedb==SAVEDB_MYSQL){
for(new i=1; i<6; i++){
format(cache, 127, "RENAME TABLE %s TO %s_%s;", g_saveby_name[i], temp, g_saveby_name[i])
SQL_ThreadQuery(g_sql_tuple, "handle_change_table_query", cache)
}
}
}else{
log_amx("SERVER: [ amx_rpg_global_reset %s ], invalid argument - must be DELETE or RENAME", arg)
return PLUGIN_HANDLED
}
log_amx("SERVER: [ amx_rpg_global_reset %s ] - sikeres", arg)
prepare_database()
return PLUGIN_HANDLED
}
public handle_change_table_query(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(FailState){
log_amx("SQL Hiba: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public prepare_database(){
g_db_status = DB_NONE
g_frequent_save = get_pcvar_num(pc_frequent_save)
g_bot_savedata = get_pcvar_num(pc_bot_savedata)
if(get_pcvar_num(pc_savedata) == 0)
return
g_saveby = get_pcvar_num(pc_saveby)
if(g_saveby < 1 || g_saveby > 3) //1 - steamid //2 - ip //3 - name
g_saveby = 1
g_savedb = get_pcvar_num(pc_savedb)
if(g_savedb < 1 || g_savedb > 2)
g_savedb = 1
switch(g_savedb){
case SAVEDB_MYSQL: sql_init()
case SAVEDB_NVAULT: {
g_db_status = DB_READY
p_vars_reset_all()
data_load_all()
}
}
}
public incorrect_login_data(id){
client_print(id, print_chat, "[RPG mod]Hiba a felhaszna'lo' vagy jelszo' 3és 10 karakter kozott legyen!!")
client_print(id, print_chat, "[RPG mod]Hiba a felhaszna'lo' vagy jelszo' nem megengedett karaktereket tartalmaz,, '-' és '_'")
client_print(id, print_console, "[RPG mod]Hiba a felhaszna'lo' vagy jelszo' 3és 10 karakter kozott legyen!!")
client_print(id, print_console, "[RPG mod]Hiba a felhaszna'lo' vagy jelszo' nem megengedett karaktereket tartalmaz,, '-' és '_'")
return PLUGIN_HANDLED
}
public rpg_login(id, level, cid){
static cache[128], len, Float:time
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
if(g_p_login_status[id] == REG_DONE){
client_print(id, print_chat, "[RPG mod]Hiba: te ma'r bejelekezte'l")
client_print(id, print_console, "[RPG mod]Hiba: te ma'r bejelekezte'l")
return PLUGIN_HANDLED
}
time = get_gametime()
if(time - g_p_login_time[id] < LOGIN_COOLDOWN && g_p_login_time[id] != 0.0){
client_print(id, print_chat, "[RPG mod]Hiba: az amx_rpglogin-t csak minden %.-dik ma'sodpercben haszna'lhatod", LOGIN_COOLDOWN)
client_print(id, print_console, "[RPG mod]Hiba: az amx_rpglogin-t csak minden %.-dik ma'sodpercben haszna'lhatod", LOGIN_COOLDOWN)
return PLUGIN_HANDLED
}
g_p_login_time[id] = time
read_args(cache, 127)
strbreak(cache, g_p_username[id], 31, cache, 127)
remove_quotes(g_p_username[id])
len = strlen(g_p_username[id])
if(len<3 || len>10){
incorrect_login_data(id)
}
for(new i=0; i<len; i++){
if((g_p_username[id][i] < 'a' || g_p_username[id][i] > 'z') &&
(g_p_username[id][i] < 'A' || g_p_username[id][i] > 'Z') &&
(g_p_username[id][i] < '0' || g_p_username[id][i] > '9') &&
g_p_username[id][i] != '-' && g_p_username[id][i] != '_'){
incorrect_login_data(id)
}
}
strbreak(cache, g_p_password[id], 31, cache, 127)
remove_quotes(g_p_password[id])
len = strlen(g_p_password[id])
if(len<3 || len>10){
incorrect_login_data(id)
}
for(new i=0; i<len; i++){
if((g_p_password[id][i] < 'a' || g_p_password[id][i] > 'z') &&
(g_p_password[id][i] < 'A' || g_p_password[id][i] > 'Z') &&
(g_p_password[id][i] < '0' || g_p_password[id][i] > '9') &&
g_p_password[id][i] != '-' && g_p_password[id][i] != '_'){
incorrect_login_data(id)
}
}
for(new i=1; i<=g_max_players; i++){
if(i==id || !is_user_connected(i))
continue
if(equal(g_p_username[i], g_p_username[id])){
client_print(id, print_chat, "[RPG mod]Hiba: a felhaszna'lot ma'r haszna'lja'k.")
client_print(id, print_console, "[RPG mod]Hiba: a felhaszna'lot ma'r haszna'lja'k.")
g_p_username[id] = ""
g_p_password[id] = ""
return PLUGIN_HANDLED
}
}
g_p_login_status[id] = REG_TRY
g_p_data_loaded[id] = DATA_NOT_LOADED
data_load(id)
return PLUGIN_HANDLED
}
public fix_0hp(msg_id, msg_dest, id){
if(!is_user_alive(id))
return
if(get_msg_arg_int(1) % 256 == 0)
set_msg_arg_int(1, 0, 255)
}
public force_drop_upgrades(id){
for(new i=0; i<MAX_UPGS; i++){
g_p_credits[id] += as_sum_fn(g_p_upg[id][i], g_upg_sp[i], g_upg_ip[i])
g_p_upg[id][i] = 0
upgrade_change(id, i)
}
}
public drop_upg_cmd(id, level, cid){
static players[MAX_PLAYERS], pnum, arg[32], tmp, i, name[32]
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
read_argv(1, arg, 31)
pnum = 0
if(equali(arg, "@all")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i))
players[pnum++] = i
}else if(equali(arg, "@t")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_team(i)==1)
players[pnum++] = i
}else if(equali(arg, "@ct")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_team(i)==2)
players[pnum++] = i
}else if(arg[0] == '#'){
tmp = str_to_num(arg[1])
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_userid(i)==tmp)
players[pnum++] = i
}else{
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i)){
get_user_name(i, name, 31)
if(equal(name, arg)){
pnum = 0
players[pnum++] = i
break
}else if(contain(name, arg)>-1){
players[pnum++] = i
}
}
}
if(pnum<=0){
client_print(id, print_console, "[RPG mod]Hiba: Nem tala'lhato'")
return PLUGIN_HANDLED
}
for(i=0; i<pnum; i++){
force_drop_upgrades(players[i])
}
get_user_name(id, name, 31)
log_amx("ADMIN %s used cmd [ amx_rpg_drop_upg %s ], ettol a ja'te'kosto'l %d", name, arg, pnum)
client_print(0, print_chat, "ADMIN %s: [Elvette a fejleszte'se't: %s], ettol a ja'te'kosto'l: %d", name, arg, pnum)
return PLUGIN_HANDLED
}
public set_upg_cmd(id, level, cid){
static players[MAX_PLAYERS], pnum, arg[32], args[63], tmp, i, j, name[32]
if (!cmd_access(id, level, cid, 3))
return PLUGIN_HANDLED
read_argv(1, arg, 31)
pnum = 0
if(equali(arg, "@all")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i))
players[pnum++] = i
}else if(equali(arg, "@t")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_team(i)==1)
players[pnum++] = i
}else if(equali(arg, "@ct")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_team(i)==2)
players[pnum++] = i
}else if(arg[0] == '#'){
tmp = str_to_num(arg[1])
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_userid(i)==tmp)
players[pnum++] = i
}else{
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i)){
get_user_name(i, name, 31)
if(equal(name, arg)){
pnum = 0
players[pnum++] = i
break
}else if(contain(name, arg)>-1){
players[pnum++] = i
}
}
}
if(pnum<=0){
client_print(id, print_console, "[RPG mod]Hiba: nem tala'lhato'")
return PLUGIN_HANDLED
}
new cost, lvl_req, upgs[MAX_UPGS]
read_argv(2, arg, 31)
for(i=0; i<MAX_UPGS; i++){
if(!g_upg_enabled[i]){
upgs[i] = 0
continue
}
if(arg[i] >= '0' && arg[i] <= '9')
upgs[i] = arg[i]-'0'
else if(arg[i] >= 'a' && arg[i] <= 'z')
upgs[i] = arg[i]-'a'+10
else if(arg[i] >= 'A' && arg[i] <= 'Z')
upgs[i] = arg[i]-'A'+10
else
upgs[i] = 0
if(upgs[i] < 0)
upgs[i] = 0
if(upgs[i] > g_upg_maxlvl[i])
upgs[i] = g_upg_maxlvl[i]
cost += as_sum_fn(upgs[i], g_upg_sp[i], g_upg_ip[i])
}
lvl_req = cost / CREDITS_PER_LVL
for(i=0; i<pnum; i++){
for(j=0; j<MAX_UPGS; j++){
g_p_upg[players[i]][j] = upgs[j]
upgrade_change(players[i], j)
}
if(g_p_level[players[i]] < lvl_req){
g_p_level[players[i]] = lvl_req
g_p_xp[players[i]] = as_sum_fn(lvl_req, XP_START, XP_INC)
g_p_progress[players[i]] = 0
}
g_p_credits[players[i]] = g_p_level[players[i]]*CREDITS_PER_LVL - cost
data_save(players[i])
}
read_args(args, 63)
get_user_name(id, name, 31)
log_amx("ADMIN %s used cmd [ amx_rpg_set_upgs %s ], Ennek a ja'te'kosnak: %d", name, args, pnum)
client_print(0, print_chat, "ADMIN %s: [A1ta'littotta a fejleszte'seit: %s], Ennek a ja'te'kosnak: %d", name, args, pnum)
return PLUGIN_HANDLED
}
public change_lvl_cmd(id, level, cid){
static players[MAX_PLAYERS], pnum, arg[32], args[63], tmp, amount, i, j, name[32]
if (!cmd_access(id, level, cid, 4))
return PLUGIN_HANDLED
read_argv(1, arg, 31)
pnum = 0
if(equali(arg, "@all")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i))
players[pnum++] = i
}else if(equali(arg, "@t")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_team(i)==1)
players[pnum++] = i
}else if(equali(arg, "@ct")){
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_team(i)==2)
players[pnum++] = i
}else if(arg[0] == '#'){
tmp = str_to_num(arg[1])
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i) && get_user_userid(i)==tmp)
players[pnum++] = i
}else{
for(i=1; i<=g_max_players; i++)
if(is_user_connected(i)){
get_user_name(i, name, 31)
if(equal(name, arg)){
pnum = 0
players[pnum++] = i
break
}else if(contain(name, arg)>-1){
players[pnum++] = i
}
}
}
if(pnum<=0){
client_print(id, print_console, "[RPG mod]Hiba: Nem tala'lhato'")
return PLUGIN_HANDLED
}
read_argv(3, arg, 31)
amount = str_to_num(arg)
read_argv(2, arg, 1)
if(amount<0 || (amount==0 && arg[0]!='=')){
client_print(id, print_console, "[RPG mod]Hiba: Nem tala'hato'")
return PLUGIN_HANDLED
}
switch(arg[0]){
case '+': { //increases level and credits
for(i=0; i<pnum; i++){
g_p_level[players[i]] += amount
g_p_xp[players[i]] = as_sum_fn(g_p_level[players[i]], XP_START, XP_INC)
g_p_credits[players[i]] += amount * CREDITS_PER_LVL
g_p_progress[players[i]] = 0
set_default_lvl_upg(players[i])//will not set lvl if player has lvl > default lvl
data_save(players[i])
}
}
case '-': { //reduces level and credits
for(i=0; i<pnum; i++){
g_p_level[players[i]] -= amount
g_p_xp[players[i]] = as_sum_fn(g_p_level[players[i]], XP_START, XP_INC)
g_p_credits[players[i]] -= amount * CREDITS_PER_LVL
g_p_progress[players[i]] = 0
if(g_p_credits[players[i]] < 0)
force_drop_upgrades(players[i])
if(g_p_credits[players[i]] < 0)
g_p_level[players[i]] = 0 //will reset to default in set_default_lvl_upg
set_default_lvl_upg(players[i])//will not set lvl if player has lvl > default lvl
data_save(players[i])
}
}
case '=': { //set level and credits (all previous upg sell penalty is gone)
for(i=0; i<pnum; i++){
g_p_level[players[i]] = amount
g_p_xp[players[i]] = as_sum_fn(g_p_level[players[i]], XP_START, XP_INC)
g_p_credits[players[i]] = amount * CREDITS_PER_LVL
g_p_progress[players[i]] = 0
for(j=0; j<MAX_UPGS; j++)
g_p_credits[players[i]] -= as_sum_fn(g_p_upg[players[i]][j], g_upg_sp[j], g_upg_ip[j])
if(g_p_credits[players[i]] < 0)
force_drop_upgrades(players[i])
set_default_lvl_upg(players[i])//will not set lvl if player has lvl > default lvl
data_save(players[i])
}
}
default: {
client_print(id, print_console, "[RPG mod]Error: invalid 2nd argument - must be - or + or = ")
return PLUGIN_HANDLED
}
}
read_args(args, 63)
get_user_name(id, name, 31)
log_amx("ADMIN %s used cmd [ amx_rpg_lvl %s ], affected players: %d", name, args, pnum)
client_print(0, print_chat, "ADMIN %s: [level change: %s], affected players: %d", name, args, pnum)
return PLUGIN_HANDLED
}
/*
#########################################################################################
#########################################################################################
#########################################################################################
#########################################################################################
*/
public block_denial(){ //called on game commencing and round restart
g_block_denial = true
}
////////////////////////////////check_cfg_file() UNFINISHED
public check_cfg_file(){
new cfgdir[128], cache[256], fh
get_configsdir(cfgdir, 127)
format(cfgdir, 127, "%s%s", cfgdir, "/rpg_mod")
if(!dir_exists(cfgdir)){
log_amx("Config dir does not exist (%s), ke'szite's...", cfgdir)
if(mkdir(cfgdir)!=0){
log_amx("Error: Could not create dir (%s).", cfgdir)
return
}
}
formatex(cache, 255, "%s%s", cfgdir, "/rpg_mod.cfg")
if(!file_exists(cache)){
log_amx("Config file does not exist: (%s), ke'szite's...", cache)
fh = fopen(cache, "wt")
if(!fh){
log_amx("Error: Could not open file for writing (%s).", cache)
return
}else{
fputs(fh, "// RPG Mod Configuration File^n")
fputs(fh, "echo Executing RPG Mod Configuration File^n^n")
fputs(fh, "rpgm_save 1^t^t^t//1 = save data, 0 = don't save data^n")
fputs(fh, "rpgm_saveby 1^t^t^t//1 = STEAMID, 2 = ip, 3 = name^n")
fputs(fh, "rpgm_savedb 1^t^t^t//1 = nVault, 2 = MySql^n^n")
fputs(fh, "rpgm_upgs 111111111111^n")
fputs(fh, "rpgm_xp_mult 1.0^n")
fclose(fh)
}
}
server_cmd("exec %s", cache)
}
//xp needed to gain lvls, upgrades cost are elements of arithmetic sequence
//so I need functions to get number of elements from sum
//and sum from number of elements
public as_num_fs(sum, base, diff){ //returns number of elements
static l, r, mid, bool:found
if(sum<10000)
//this formula is not working with high values of sum (getting out of int max limit)
return (sqroot((2*base-diff)*(2*base-diff) + 8*diff*sum) - (2*base-diff))/(2*diff)
if(sum<base)
return 0
r = 1
//binary search - not as fast as formula above but still faster than linera search...
while( ( 2*base + diff*(r-1) )*r/2 < sum)
r = r*2
l = r/2
//now the number we are looking for is somewhere between l and r
found = false
while(!found){
mid = (l+r)/2
if(( 2*base + diff*(mid-1) )*mid/2 > sum)
r = mid-1
else if(( 2*base + diff*mid )*(mid+1)/2 <= sum)
l = mid+1
else
found = true
}
return mid
}
public as_sum_fn(num, base, diff) //returns sum of elements
return num*(base*2 + diff*(num-1))/2
public data_save_all(){
if(g_db_status != DB_READY)
return
for(new id=1; id<=g_max_players; id++){
if(is_user_connected(id) && (g_p_authorized[id] || g_saveby != SAVEBY_STEAMID))
data_save(id)
}
}
public data_load_all(){
for(new id=1; id<=g_max_players; id++){
if((is_user_connected(id) || is_user_connecting(id))
&& (g_p_authorized[id] || g_saveby != SAVEBY_STEAMID))
data_load(id)
}
}
public data_save(id){
static nv_hnd, data[256], cache[512], key[64], i, saveby, pos
if(g_db_status != DB_READY || g_p_data_loaded[id] == DATA_NOT_LOADED)
return
if(g_p_login_status[id] == REG_DONE){
saveby = SAVEBY_LOGIN
i = -3
}else{
saveby = g_saveby
i = -2
}
if(is_user_bot(id)){
if(g_bot_savedata == 0)
return
else
saveby = SAVEBY_BOT
}
switch(saveby){
case SAVEBY_STEAMID: copy(key, 31, g_p_authid[id])
case SAVEBY_IP: copy(key, 31, g_p_ip[id])
case SAVEBY_NAME:{
if(g_savedb == SAVEDB_NVAULT)
copy(key, 31, g_p_name[id])
else
SQL_QuoteString(g_sql_connection, key, 63, g_p_name[id])
}
case SAVEBY_LOGIN: copy(key, 31, g_p_username[id])
case SAVEBY_BOT:{ //
if(g_savedb == SAVEDB_NVAULT)
copy(key, 31, g_p_name[id])
else
SQL_QuoteString(g_sql_connection, key, 63, g_p_name[id])
}
}
pos = 0
data = ""
for(; i<MAX_UPGS; i++){
switch(i){
case -3: pos += formatex(data[pos], 255-pos, "%s ", g_p_password[id])
case -2: pos += formatex(data[pos], 255-pos, "%d ", g_p_xp[id])
case -1: pos += formatex(data[pos], 255-pos, "%d ", g_p_credits[id])
default: pos += formatex(data[pos], 255-pos, "%d ", as_sum_fn(g_p_upg[id][i], g_upg_sp[i], g_upg_ip[i]))
}
}
if(g_savedb == SAVEDB_NVAULT){
nv_hnd = nvault_open(g_saveby_name[saveby])
if(nv_hnd == INVALID_HANDLE){
log_amx("Nem sikerult megynyitni nVault-ot %s.", g_saveby_name[saveby])
g_p_login_status[id] = REG_NONE
return
}
nvault_set(nv_hnd, key, data)
g_p_temp_xp[id] = 0
nvault_close(nv_hnd)
}else{ // g_savedb == SAVEDB_MYSQL
formatex(cache, 511, "REPLACE INTO %s (db_key, data) VALUES ('%s', '%s');", g_saveby_name[saveby], key, data)
new temp[2]
temp[0] = id
SQL_ThreadQuery(g_sql_tuple, "handle_sql_save", cache, temp, 2)
}
if(saveby == SAVEBY_LOGIN){
data_delete(id, g_saveby)
}
}
public handle_sql_save(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(g_db_status != DB_READY)
return PLUGIN_HANDLED
if(FailState){
log_amx("SQL Hiba: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
g_p_temp_xp[Data[0]] = 0
return PLUGIN_CONTINUE
}
public data_load(id){
static nv_hnd, data[2], cache[256], ts, ret, key[32], i, saveby
if(g_db_status != DB_READY || g_p_data_loaded[id] != DATA_NOT_LOADED
|| g_p_login_status[id] == REG_DONE)
return
if(g_p_login_status[id] == REG_TRY){
saveby = SAVEBY_LOGIN
i = -3
}else{
i = -2
saveby = g_saveby
}
if(is_user_bot(id)){
if(g_bot_savedata == 0)
return
else
saveby = SAVEBY_BOT
}
switch(saveby){
case SAVEBY_STEAMID: copy(key, 31, g_p_authid[id])
case SAVEBY_IP: copy(key, 31, g_p_ip[id])
case SAVEBY_NAME: {
if(g_savedb == SAVEDB_NVAULT)
copy(key, 31, g_p_name[id])
else
SQL_QuoteString(g_sql_connection, key, 63, g_p_name[id])
}
case SAVEBY_LOGIN: copy(key, 31, g_p_username[id])
case SAVEBY_BOT: {
if(g_savedb == SAVEDB_NVAULT)
copy(key, 31, g_p_name[id])
else
SQL_QuoteString(g_sql_connection, key, 63, g_p_name[id])
}
}
if(g_savedb == SAVEDB_NVAULT){
nv_hnd = nvault_open(g_saveby_name[saveby])
if(nv_hnd == INVALID_HANDLE){
log_amx("nem sikerult megynitnin Vault-ot %s.", g_saveby_name[saveby])
client_print(id, print_chat, "[RPG mod]Hiba: Nem sikerult csatlakozni az adatba'zishoz.")
client_print(id, print_console, "[RPG mod]Hiba: Nem sikerult csatlakozni az adatba'zishoz.")
g_p_login_status[id] = REG_NONE
return
}
ret = nvault_lookup(nv_hnd, key, cache, 255, ts)
nvault_close(nv_hnd)
if(ret==0){
g_p_data_loaded[id] = DATA_NOT_FOUND
if(g_p_login_status[id] == REG_TRY){
g_p_login_status[id] = REG_DONE
data_save(id) //lets reserve this username
client_print(id, print_chat, "[RPG mod]Te sikeresen regriszta'lta'l!!")
client_print(id, print_console, "[RPG mod]Te sikeresen regriszta'lta'l!!")
g_p_pw_hidden[id] = true
set_default_lvl_upg(id)
}
}else{
decode_data_str(id, cache, i)
}
}else{ // g_savedb == SAVEDB_MYSQL
data[0] = id
data[1] = i
g_p_data_loaded[id] = DATA_LOADING
format(cache, 255, "kiva'lasztot adat innen: %s WHERE db_key = '%s'", g_saveby_name[saveby], key)
SQL_ThreadQuery(g_sql_tuple, "handle_sql_load", cache, data, 2)
}
}
public handle_sql_load(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
static id, i, cache[256]
if(g_db_status != DB_READY)
return PLUGIN_HANDLED
if(FailState){
log_amx("SQL Hiba: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
id = Data[0]
i = Data[1]
if(SQL_MoreResults(Query)){
SQL_ReadResult(Query, 0, cache, 255)
decode_data_str(id, cache, i)
}else{
//first time connect
g_p_data_loaded[id] = DATA_NOT_FOUND
if(g_p_login_status[id] == REG_TRY){
g_p_login_status[id] = REG_DONE
data_save(id) //lets reserve this username
client_print(id, print_chat, "[RPG mod]Te sikeresen regriszta'lta'l!!")
client_print(id, print_console, "[RPG mod]Te sikeresen regriszta'lta'l!!")
g_p_pw_hidden[id] = true
set_default_lvl_upg(id)
}
}
return PLUGIN_CONTINUE
}
public decode_data_str(id, data[], i){
static temp[32], num
for(; i<MAX_UPGS; i++){
strbreak(data, temp, 31, data, 255)
remove_quotes(temp)
switch(i){
case -3:{
if(!equal(temp, g_p_password[id])){
client_print(id, print_chat, "[RPG mod]Hiba a felhaszna'lo' nem tala'lhato az adatba'zisban, vagy rosz jelszo.")
client_print(id, print_console, "[RPG mod]Hiba a felhaszna'lo' nem tala'lhato az adatba'zisban, vagy rosz jelszo.")
g_p_username[id] = ""
g_p_password[id] = ""
g_p_login_status[id] = REG_NONE
g_p_data_loaded[id] = DATA_LOADED
set_default_lvl_upg(id)
return
}
client_print(id, print_chat, "[RPG mod] Sikeresen bejelentkezte'l")
client_print(id, print_console, "[RPG mod] Sikeresen bejelentkezte'l")
g_p_pw_hidden[id] = true
}
case -2:{
g_p_xp[id] = str_to_num(temp)
g_p_level[id] = as_num_fs(g_p_xp[id], XP_START, XP_INC)
g_p_progress[id] = 100-(as_sum_fn(g_p_level[id]+1, XP_START, XP_INC)-g_p_xp[id])*100/(XP_START+XP_INC*g_p_level[id])
}
case -1: g_p_credits[id] = str_to_num(temp)
default:{
num = str_to_num(temp)
g_p_upg[id][i] = as_num_fs(num, g_upg_sp[i], g_upg_ip[i])
if(g_p_upg[id][i] > g_upg_maxlvl[i])
g_p_upg[id][i] = g_upg_maxlvl[i]
if(!g_upg_enabled[i])
g_p_upg[id][i] = 0
upgrade_change(id, i)
g_p_credits[id] += num - as_sum_fn(g_p_upg[id][i], g_upg_sp[i], g_upg_ip[i])
}
}
}
g_p_data_loaded[id] = DATA_LOADED
if(g_p_login_status[id] == REG_TRY)
g_p_login_status[id] = REG_DONE
set_default_lvl_upg(id)
}
public data_delete(id, saveby){
static nv_hnd, key[64], cache[128]
if(g_db_status != DB_READY)
return
switch(saveby){
case SAVEBY_STEAMID: copy(key, 31, g_p_authid[id])
case SAVEBY_IP: copy(key, 31, g_p_ip[id])
case SAVEBY_NAME: {
if(g_savedb == SAVEDB_NVAULT)
copy(key, 31, g_p_name[id])
else
SQL_QuoteString(g_sql_connection, key, 63, g_p_name[id])
}
case SAVEBY_LOGIN:{
copy(key, 31, g_p_username[id])
g_p_username[id] = ""
g_p_password[id] = ""
}
case SAVEBY_BOT: {
if(g_savedb == SAVEDB_NVAULT)
copy(key, 31, g_p_name[id])
else
SQL_QuoteString(g_sql_connection, key, 63, g_p_name[id])
}
}
if(g_savedb == SAVEDB_NVAULT){
nv_hnd = nvault_open(g_saveby_name[saveby])
if(nv_hnd == -1){
log_amx("Nem sikerult megnyitni nvault-ot")
return
}
nvault_remove(nv_hnd, key)
nvault_close(nv_hnd)
}else{ //g_savedb == SAVEDB_MYSQL
formatex(cache, 127, "Torles innen %s WHERE db_key = '%s';", g_saveby_name[saveby], key)
SQL_ThreadQuery(g_sql_tuple, "handle_sql_delete", cache)
}
}
public handle_sql_delete(FailState,Handle:Query,Error[],Errcode,Data[],DataSize){
if(g_db_status != DB_READY)
return PLUGIN_HANDLED
if(FailState){
log_amx("SQL Hiba: %s (%d)", Error, Errcode)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public event_new_round(){
g_freezetime = true
if(g_block_denial){
g_block_denial = false
for(new id=1; id<=g_max_players; id++){
g_c_denial[id] = DENIAL_BLOCK
}
}
for(new id=1; id<=g_max_players; id++){
g_c_regen[id] = 0
g_c_resup[id] = 0
g_p_next_lj[id] = 0.0
g_p_jump[id] = false
g_c_frost[id] = 0
g_c_ice[id] = 0
g_c_impulse[id] = 0
g_c_medic[id] = 0
}
if(g_frequent_save==1)
data_save_all()
}
public logevent_round_start(){
g_freezetime = false
}
public update_StatusText(id){
static cache[512]
if(!g_user_control || (g_in_team && g_in_team != g_p_team[id])
|| !g_p_settings[id][SETT_INFO_UNDER_CHAT])
return
format(cache, 511, "[RPG mod][Szint: %d][Sza'szale'k: %d%s][Pontok: %d] ird /rpg", g_p_level[id], g_p_progress[id], "%%", g_p_credits[id])
message_begin(MSG_ONE_UNRELIABLE, g_msgStatusText, {0,0,0}, id)
write_byte(0)
write_string(cache)
message_end()
}
public event_CurWeapon(id){
reset_player_speed(id)
}
public player_death(id){
static attacker, victim
attacker = read_data(1)
victim = read_data(2)
if(!is_user_alive(victim)){
g_p_alive[victim] = false
}
g_p_weap_num[victim] = 0
get_user_weapons(victim, g_p_weap[victim], g_p_weap_num[victim])
g_p_defkit[victim] = cs_get_user_defuse(victim)
g_p_armor[victim] = cs_get_user_armor(victim, g_p_atype[victim])
if(g_p_upg[victim][UPG_DENIAL] && g_c_denial[victim] != DENIAL_BLOCK && !(g_in_team && g_in_team != g_p_team[id]))
g_c_denial[victim] = DENIAL_NEXT_SPAWN
if(attacker == victim)
return
if(attacker < 1 || attacker > g_max_players)
return
if(victim < 1 || victim > g_max_players)
return
if(cs_get_user_team(victim)==cs_get_user_team(attacker))
return
fn_addxp(attacker, fn_calcxp(CXT_KILL, attacker, victim, 0))
}