CSFWEED Posted October 21, 2019 Share Posted October 21, 2019 #Denumire plugin: Advanced Slot [2.0] #Autor: cyby #Informatii: Un plugin destul de avansat ce ofera slot printr-o comanda simpla dupa ce ati jucat un anumit timp pe server. Minutele nu cresc celor care nu si-au ales echipa sau sunt spectatori. Restul vedeti din poze si din script. #Link download: SMA | #include <amxmodx> #include <amxmisc> #include <hamsandwich> #include <nvault> enum { MIN = 1, HOURS = 60, DAYS = 1440 } const TIME_HANDLED = 97; #define CONFIGURATION_FILE "advanced_slot.ini" #define LOG_FILE "slot_register.log" #define LOG_DEVELOPER "slot_developer.log" #define flag_get(%1,%2) (%1 & (1 << (%2 & 31))) #define flag_set(%1,%2) %1 |= (1 << (%2 & 31)) #define flag_unset(%1,%2) %1 &= ~(1 << (%2 & 31)) #define TASK_MINUTES 10101 #define ID_MINUTES (taskid - TASK_MINUTES) new g_minutes[33], g_name[33][32], g_developeridt[33], g_loaded, g_isregistered, g_isdeveloper; new g_nvaultsave, g_msg_saytext, g_maxplayers, g_fw_load_pre, g_fw_load_post, bool:g_settings_loaded = false; new g_hours_need, tag_string[32], Array:g_developer, db_name[32], g_access_flag, field[10]; public plugin_init() { register_plugin("Advanced Slot Free", "2.0", "cyby & S.Cosmin"); RegisterHam(Ham_Spawn, "player", "spawn_post", 1); register_clcmd("say /slot", "slot_cmd"); register_clcmd("say /ore", "timeplayed_cmd"); register_clcmd("PASSWORD_SLOT", "password_for_slot"); register_clcmd("say /ored", "developer_menu"); register_clcmd("ADD_MINUTES", "add_developer_min"); register_clcmd("REM_MINUTES", "rem_developer_min"); g_maxplayers = get_maxplayers(); g_msg_saytext = get_user_msgid("SayText"); g_fw_load_pre = CreateMultiForward("get_loadtime_pre", ET_IGNORE, FP_CELL); g_fw_load_post = CreateMultiForward("get_loadtime_post", ET_IGNORE, FP_CELL); } public plugin_cfg() { g_developer = ArrayCreate(32, 1); load_conf_extern_files(); set_task(1.0, "take_nvault"); } public take_nvault() { g_nvaultsave = nvault_open(db_name); if(g_nvaultsave == INVALID_HANDLE) set_fail_state("[Advanced Slot Free] Eroare la deschiderea bazei de date."); for(new i = 1; i <= g_maxplayers; i++) { if(!is_user_connected(i)) continue; takedata(i); } } public load_conf_extern_files() { g_settings_loaded = false; g_hours_need = native_load_setting_int(CONFIGURATION_FILE, "Setari Rezervare", "HOURS SLOT"); native_load_setting_string(CONFIGURATION_FILE, "Setari Rezervare", "TAG", tag_string, charsmax(tag_string)); native_load_setting_string_arr(CONFIGURATION_FILE, "Setari Rezervare", "DEVELOPER", g_developer); native_load_setting_string(CONFIGURATION_FILE, "Setari Rezervare", "NVAULT NAME", db_name, charsmax(db_name)); new flags[32]; native_load_setting_string(CONFIGURATION_FILE, "Setari Rezervare", "FLAG REGISTER", flags, charsmax(flags)); g_access_flag = read_flags(flags); native_load_setting_string(CONFIGURATION_FILE, "Setari Rezervare", "FIELD", field, charsmax(field)); server_print("[Advanced Slot Free] Setarile au fost preluate cu succes."); g_settings_loaded = true; } public plugin_natives() { register_native("get_registered", "native_get_registered", 1); register_native("get_developer", "native_get_developer", 1); register_native("get_playedtime", "native_get_string_time", 1); register_native("get_loadedtime", "native_get_loadedtime", 1); register_native("get_inttime", "native_get_int_time", 1); } public native_get_registered(id) { if(!flag_get(g_loaded, id)) return false; if(flag_get(g_isregistered, id)) return true; return false; } public native_get_developer(id) { if(!flag_get(g_loaded, id)) return false; if(flag_get(g_isdeveloper, id)) return true; return false; } public native_get_string_time(plugin_id, param_nums) { if(param_nums != 3) return -1; new id = get_param(1); if(!flag_get(g_loaded, id)) return -1; new time_played[32]; formatex(time_played, charsmax(time_played), "%s", convert_minutes(id)); set_string(2, time_played, get_param(3)); return 1; } public native_get_loadedtime(id) { if(flag_get(g_loaded, id)) return true; return false; } public native_get_int_time(id, what) { if(!flag_get(g_loaded, id)) return -1; if(what == MIN) return g_minutes[id]; new extract = 0, int_min = g_minutes[id]; while(int_min >= what) { extract++; int_min -= what; } return extract; } public plugin_end() nvault_close(g_nvaultsave); public client_putinserver(id) { get_user_name(id, g_name[id], charsmax(g_name[])); set_register(id); set_developer(id); } public client_disconnected(id) { g_developeridt[id] = 0; savedata(id); flag_unset(g_isregistered, id) flag_unset(g_isdeveloper, id) } public spawn_post(id) { if(!is_user_alive(id) || !g_settings_loaded) return; if(!flag_get(g_loaded, id)) { new dummy; ExecuteForward(g_fw_load_pre, dummy, id); if(dummy >= TIME_HANDLED) return; takedata(id); set_task(60.0, "increase_minutes", id+TASK_MINUTES, _, _, "b"); flag_set(g_loaded, id); ExecuteForward(g_fw_load_post, dummy, id); } } public slot_cmd(id) { if(flag_get(g_isregistered, id)) { color(id, ".v%s.g Acest nume este deja inregistrat!", tag_string); return PLUGIN_HANDLED; } if((g_minutes[id] / 60) < g_hours_need) { color(id, ".v%s.g Ai nevoie de.v %d.g ore pentru slot!", tag_string, g_hours_need); return PLUGIN_HANDLED; } client_cmd(id, "messagemode PASSWORD_SLOT"); color(id, ".v%s.g Parola trebuie sa contina doar litere!", tag_string); color(id, ".v%s.g Ti-a aparut sus loc pentru a scrie parola!", tag_string); return PLUGIN_HANDLED; } public timeplayed_cmd(id) { if(!flag_get(g_loaded, id)) { color(id, ".v%s.g Ne pare rau, dar nu ti-am preluat inca orele!", tag_string); return PLUGIN_HANDLED; } color(id, ".v%s.g Ai jucat pana acum.v %s.g!", tag_string, convert_minutes(id)); return PLUGIN_HANDLED; } public developer_menu(id) { if(!flag_get(g_isdeveloper, id)) return PLUGIN_CONTINUE; new menu = menu_create("\rDeveloper Menu", "developer_handler"); menu_additem(menu, "\yAdaugă minute", ""); menu_additem(menu, "\yȘterge minute", ""); menu_display(id, menu, 0); return PLUGIN_HANDLED; } public developer_handler(id, menu, item) { if(!flag_get(g_isdeveloper, id)) { menu_destroy(menu); return PLUGIN_HANDLED; } if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; } switch(item) { case 0: open_addmin(id); case 1: open_remmin(id); } menu_destroy(menu); return PLUGIN_HANDLED; } public open_addmin(id) { if(!flag_get(g_isdeveloper, id)) return PLUGIN_HANDLED; new menu = menu_create("\yAdauga minute la jucatori", "add_minutes"); new menu_item[100], userid[32]; for(new i = 1; i <= g_maxplayers; i++) { if(!is_user_connected(i) || !flag_get(g_loaded, i)) continue; formatex(menu_item, charsmax(menu_item), "\r%s - \y%s", g_name, convert_minutes(i)); formatex(userid, charsmax(userid), "%d", get_user_userid(i)); menu_additem(menu, menu_item, userid, 0); } menu_display(id, menu, 0); return PLUGIN_HANDLED; } public add_minutes(id, menu, item) { if(!flag_get(g_isdeveloper, id)) { menu_destroy(menu); return PLUGIN_HANDLED; } if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; } new menu_data[6], menu_name[64]; new _access, item_callback; menu_item_getinfo(menu, item, _access, menu_data, charsmax(menu_data), menu_name, charsmax(menu_name), item_callback); new userid = str_to_num(menu_data); new player = find_player("k", userid); if(player) { client_cmd(id, "messagemode ADD_MINUTES"); g_developeridt[id] = player; color(id, ".v%s.g L-ai selectat pe.v %s.g!", tag_string, g_name[player]); } else { color(id, ".v%s.g Jucatorul nu exista!", tag_string); g_developeridt[id] = 0; } menu_destroy(menu); return PLUGIN_HANDLED; } public open_remmin(id) { if(!flag_get(g_isdeveloper, id)) return PLUGIN_HANDLED; new menu = menu_create("\yAdauga minute la jucatori", "rem_minutes"); new menu_item[100], userid[32]; for(new i = 1; i <= g_maxplayers; i++) { if(!is_user_connected(i) || !flag_get(g_loaded, i)) continue; formatex(menu_item, charsmax(menu_item), "\r%s - \y%s", g_name, convert_minutes(i)); formatex(userid, charsmax(userid), "%d", get_user_userid(i)); menu_additem(menu, menu_item, userid, 0); } menu_display(id, menu, 0); return PLUGIN_HANDLED; } public rem_minutes(id, menu, item) { if(!flag_get(g_isdeveloper, id)) { menu_destroy(menu); return PLUGIN_HANDLED; } if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; } new menu_data[6], menu_name[64]; new _access, item_callback; menu_item_getinfo(menu, item, _access, menu_data, charsmax(menu_data), menu_name, charsmax(menu_name), item_callback); new userid = str_to_num(menu_data); new player = find_player("k", userid); if(player) { client_cmd(id, "messagemode REM_MINUTES"); g_developeridt[id] = player; color(id, ".v%s.g L-ai selectat pe.v %s.g!", tag_string, g_name[player]); } else { color(id, ".v%s.g Jucatorul nu există!", tag_string); g_developeridt[id] = 0; } menu_destroy(menu); return PLUGIN_HANDLED; } public add_developer_min(id) { if(!flag_get(g_isdeveloper, id)) { g_developeridt[id] = 0; return PLUGIN_HANDLED; } if(!is_user_connected(g_developeridt[id]) || !flag_get(g_loaded, g_developeridt[id])) { color(id, ".v%s.g Jucatorul care l-ai selectat a parasit serverul!", tag_string); g_developeridt[id] = 0; return PLUGIN_HANDLED; } new amount[16]; read_args(amount, charsmax(amount)); remove_quotes(amount); new much = str_to_num(amount); if(much <= 0) { color(id, ".v%s.g Suma introdusa este mai mica sau egala cu 0!", tag_string); g_developeridt[id] = 0; return PLUGIN_HANDLED; } g_minutes[g_developeridt[id]] += much; color(0, ".v%s.g Developer.v %s.g ii adauga.v %s %d minute.g!", tag_string, g_name[id], g_name[g_developeridt[id]], much); log_developer(id, g_developeridt[id], much, 1); g_developeridt[id] = 0; return PLUGIN_HANDLED; } public rem_developer_min(id) { if(!flag_get(g_isdeveloper, id)) { g_developeridt[id] = 0; return PLUGIN_HANDLED; } if(!is_user_connected(g_developeridt[id]) || !flag_get(g_loaded, g_developeridt[id])) { color(id, ".v%s.g Jucatorul care l-ai selectat a parasit serverul!", tag_string); g_developeridt[id] = 0; return PLUGIN_HANDLED; } new amount[16]; read_args(amount, charsmax(amount)); remove_quotes(amount); new much = str_to_num(amount); if(much <= 0) { color(id, ".v%s.g Suma introdusa este mai mica sau egala cu 0!", tag_string); g_developeridt[id] = 0; return PLUGIN_HANDLED; } g_minutes[g_developeridt[id]] -= much; color(0, ".v%s.g Developer.v %s.g ii scade.v %s.v %d minute.g!", tag_string, g_name[id], g_name[g_developeridt[id]], much); log_developer(id, g_developeridt[id], much, 2); g_developeridt[id] = 0; return PLUGIN_HANDLED; } public client_infochanged(id) { new name[32]; get_user_info(id, "name", name, charsmax(name)); if(!(equali(name, g_name[id]))) { savedata(id); formatex(g_name[id], charsmax(g_name[]), "%s", name); set_register(id); set_developer(id); } } public password_for_slot(id) { new password[17]; read_args(password, charsmax(password)); remove_quotes(password); if(!check_string(password)) { color(id, ".v%s.g Parola nu respecta regulile!", tag_string); color(id, ".v%s.g Parola trebuie sa contină doar litere!", tag_string); return PLUGIN_HANDLED; } register_slot(id, password); return PLUGIN_HANDLED; } public increase_minutes(taskid) { if(get_user_team(ID_MINUTES) == 0 || get_user_team(ID_MINUTES) == 3 || !flag_get(g_loaded, ID_MINUTES)) return; g_minutes[ID_MINUTES]++; } public takedata(id) { if(flag_get(g_loaded, id)) return; new vaultkey[32], vaultdata[256]; formatex(vaultkey, charsmax(vaultkey), "%s", g_name[id]); formatex(vaultdata, charsmax(vaultdata), "^"%i^"", g_minutes[id]); nvault_get(g_nvaultsave, vaultkey, vaultdata, charsmax(vaultdata)); new minutes[32]; parse(vaultdata, minutes, charsmax(minutes)); g_minutes[id] = str_to_num(minutes); } public savedata(id) { if(!flag_get(g_loaded, id)) return; new vaultkey[32], vaultdata[256]; formatex(vaultkey, charsmax(vaultkey), "%s", g_name[id]); formatex(vaultdata, charsmax(vaultdata), "^"%i^"", g_minutes[id]); nvault_set(g_nvaultsave, vaultkey, vaultdata); g_minutes[id] = 0; flag_unset(g_loaded, id) remove_task(id+TASK_MINUTES); } public register_slot(id, const password[]) { new line[192], configsdir[128], flag[32]; get_flags(g_access_flag, flag, charsmax(flag)); formatex(line, charsmax(line), "^"%s^" ^"%s^" ^"%s^" ^"a^" ; Slot de la /slot cu %d ore", g_name[id], password, flag, g_hours_need); get_configsdir(configsdir, charsmax(configsdir)); formatex(configsdir, charsmax(configsdir), "%s/users.ini", configsdir); write_file(configsdir, line, -1); color(id, ".v%s.g Ai luat slot pentru.v %d.g de joc!", tag_string, g_hours_need); color(id, ".v%s.g Parola ta este:.v %s.g!", tag_string, password); set_user_info(id, field, password); color(0, ".v%s.g Felicitari lui.v %s.g! Si-a luat slot pentru.v %d ore jucate.g!", tag_string, g_name[id], g_hours_need); log_slot(id); flag_set(g_isregistered, id) server_cmd("amx_reloadadmins"); } stock convert_minutes(id) { new szminutes[32], len = 0; new days, hours; new actual_minutes = g_minutes[id]; while(actual_minutes >= 1440) { days++; actual_minutes -= 1440; } while(actual_minutes >= 60) { hours++; actual_minutes -= 60; } if(days > 0) len += formatex(szminutes[len], charsmax(szminutes) - len, "%d zi%s ", days, days == 1 ? "" : "le"); if(hours > 0) len += formatex(szminutes[len], charsmax(szminutes) - len, "%d or%s ", hours, hours == 1 ? "a" : "e"); if(actual_minutes > 0) len += formatex(szminutes[len], charsmax(szminutes) - len, "%d minut%s", actual_minutes, actual_minutes == 1 ? "" : "e"); if(!days && !hours && actual_minutes == 0) len += formatex(szminutes[len], charsmax(szminutes) - len, "nimic"); return szminutes; } stock bool:check_string(const string[]) { new len = strlen(string); if(len < 3) return false; if(len > 15) return false; new bool:isntright = false; for(new i = 1; i <= len; i++) { if(!is_letter(string)) { isntright = true; break; } } if(isntright) return false; return true; } stock bool:is_letter(u) { if(u >= 65 || u <= 90) return true; if(u >= 97 || u <= 122) return true; return false; } stock color(const id, const input[], any:...) { new count = 1, players[32]; static msg[191]; vformat(msg, 190, input, 3); replace_all(msg, 190, ".v", "^4"); replace_all(msg, 190, ".g", "^1"); replace_all(msg, 190, ".e", "^3"); if(id) players[0] = id; else get_players(players, count, "ch") { for (new i = 0; i < count; i++) { if(is_user_connected(players)) { message_begin(MSG_ONE_UNRELIABLE, g_msg_saytext, _, players); write_byte(players); write_string(msg); message_end(); } } } } stock set_developer(id) { flag_unset(g_isdeveloper, id) new name[32]; for(new i = 0; i < ArraySize(g_developer); i++) { ArrayGetString(g_developer, i, name, charsmax(name)); if(equali(g_name[id], name)) { flag_set(g_isdeveloper, id) break; } } } stock set_register(id) { if(!is_user_connected(id)) flag_unset(g_isregistered, id) if(get_user_flags(id) & g_access_flag) flag_set(g_isregistered, id) else flag_unset(g_isregistered, id) } stock log_slot(id) { new content[192], ip[35], authid[34]; get_user_ip(id, ip, charsmax(ip), 1); get_user_authid(id, authid, charsmax(authid)); formatex(content, charsmax(content), "%s [IP: %s | STEAM: %s] si-a inregistrat numele, ore: %s", g_name[id], ip, authid, convert_minutes(id)); log_to_file(LOG_FILE, content); } stock log_developer(admin, id, time, type) { new content[192], ip[35], authid[34]; get_user_ip(admin, ip, charsmax(ip), 1); get_user_authid(admin, authid, charsmax(authid)); switch(type) { case 1: formatex(content, charsmax(content), "Developer: %s [IP: %s | STEAM: %s] ii ofera %d minute lui %s. [timp total: %s]", g_name[admin], ip, authid, time, g_name[id], convert_minutes(id)); case 2: formatex(content, charsmax(content), "Developer: %s [IP: %s | STEAM: %s] ii scoate %d minute lui %s. [timp total: %s]", g_name[admin], ip, authid, time, g_name[id], convert_minutes(id)); } log_to_file(LOG_DEVELOPER, content); } // Credite MeRcyLeZZ - pentru https://forums.alliedmods.net/showthread.php?t=243202 public native_load_setting_int(const filename[], const section[], const key[]) { // Open file for read new path[64], file, file_name[64]; formatex(file_name, charsmax(file_name), "%s", filename); OpenCustomFileRead(path, charsmax(path), file_name, file); new section_str[64]; formatex(section_str, charsmax(section_str), "%s", section); SectionExists(file, section_str) // Try to find key in section new keypos_start, keypos_end, key_str[64]; formatex(key_str, charsmax(key_str), "%s", key); KeyExists(file, key_str, keypos_start, keypos_end); new value[16]; SeekReturnValues(file, keypos_start, value, charsmax(value)); new valoare = str_to_num(value); return valoare; } public native_load_setting_string(const filename[], const section[], const key[], setting_string[], len) { // Open file for read new path[64], file, file_str[64]; formatex(file_str, charsmax(file_str), "%s", filename); OpenCustomFileRead(path, charsmax(path), file_str, file) // Try to find section new section_str[64]; formatex(section_str, charsmax(section_str), "%s", section); SectionExists(file, section_str) // Try to find key in section new keypos_start, keypos_end, key_str[64]; formatex(key_str, charsmax(key_str), "%s", key); KeyExists(file, key_str, keypos_start, keypos_end); // Return string by reference new value[128] SeekReturnValues(file, keypos_start, value, charsmax(value)) formatex(setting_string, len, "%s", value); // Value succesfully retrieved fclose(file); return true; } public native_load_setting_string_arr(const filename[], const section[], const key[], Array:array_handle) { // Open file for read new path[64], file, file_str[64]; formatex(file_str, charsmax(file_str), "%s", filename); if (!OpenCustomFileRead(path, charsmax(path), file_str, file)) return false; // Try to find section new section_str[64]; formatex(section_str, charsmax(section_str), "%s", section); if (!SectionExists(file, section_str)) { fclose(file) return false; } // Try to find key in section new keypos_start, keypos_end, key_str[64]; formatex(key_str, charsmax(key_str), "%s", key); if (!KeyExists(file, key_str, keypos_start, keypos_end)) { fclose(file) return false; } // Return array new values[1024] SeekReturnValues(file, keypos_start, values, charsmax(values)) ParseValuesArrayString(values, charsmax(values), array_handle) // Values succesfully retrieved fclose(file) return true; } OpenCustomFileRead(path[], len1, filename[], &file, create = false) { // Build customization file path get_configsdir(path, len1) format(path, len1, "%s/%s", path, filename) // File not present, create new file? if (!file_exists(path)) { if (create) write_file(path, "", -1) else return false; } // Open customization file for reading file = fopen(path, "rt") if(!file) return false; return true; } SectionExists(file, setting_section[]) { // Seek to setting's section new linedata[96], section[64] while (!feof(file)) { // Read one line at a time fgets(file, linedata, charsmax(linedata)) // Replace newlines with a null character replace(linedata, charsmax(linedata), "^n", "") // New section starting if (linedata[0] == '[') { // Store section name without braces copyc(section, charsmax(section), linedata[1], ']') // Is this our setting's section? if (equal(section, setting_section)) return true; } } return false; } KeyExists(file, setting_key[], &keypos_start, &keypos_end) { // Seek to setting's key new linedata[96], key[64] while (!feof(file)) { // Read one line at a time keypos_start = ftell(file) fgets(file, linedata, charsmax(linedata)) // Replace newlines with a null character replace(linedata, charsmax(linedata), "^n", "") // Blank line or comment if (!linedata[0] || linedata[0] == ';') continue; // Section ended? if (linedata[0] == '[') break; // Get key keypos_end = ftell(file) copyc(key, charsmax(key), linedata, '=') trim(key) // Is this our setting's key? if (equal(key, setting_key)) return true; } return false; } SeekReturnValues(file, keypos_start, values[], len1) { // Seek to key and parse it new linedata[1024], key[64] fseek(file, keypos_start, SEEK_SET) fgets(file, linedata, charsmax(linedata)) // Replace newlines with a null character replace(linedata, charsmax(linedata), "^n", "") // Get values strtok(linedata, key, charsmax(key), values, len1, '=') trim(values) } ParseValuesArrayString(values[], len1, Array:array_handle) { // Parse values new current_value[128] while (values[0] != 0 && strtok(values, current_value, charsmax(current_value), values, len1, ',')) { // Trim spaces trim(current_value) trim(values) // Add to array ArrayPushString(array_handle, current_value) } } advanced_slot.ini | [Setari Rezervare] (setari care sunt preluate la fiecare schimbare de harta fara a fi nevoita modificata sursa) HOURS SLOT = 10 TAG = [SLOT] DEVELOPER = cyby, cosmin NVAULT NAME = hours_played FLAG REGISTER = b FIELD = _pw // ca sa mai adaugi developeri, separi cu virgula, deci nu ai voie sa adaugi developeri cu virgula la nume[/spoiler] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.