| MrMaCEEE |
08-16-2010 20:23 |
Save this by Mysql
Hi, this plugin save the points by nVault but i want this saving by MySQL someone can help me? i dont know how i can put this by mysql, i try 100x but i fail pls help,,, thanks a lot
PHP Code:
#include <amxmodx> #include <amxmisc> #include <csx> #include <nvault> #include <cstrike> #include <fun> #include <fakemeta> #include <regex> #define Plugin "Points" #define Version "1.0" #define Author "MACE" #define MAX_BUFFER_LENGTH 2047 #define MAX_NAME_LENGTH 31 // User stats parms id #define STATS_KILLS 0 #define STATS_DEATHS 1 #define STATS_HS 2 #define STATS_TKS 3 #define STATS_SHOTS 4 #define STATS_HITS 5 #define STATS_DAMAGE 6 #define PATTERN "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" // \b #define REASON "Publicidade" #define CVAR_BANMINUTES "ip_banminutes" #define CVAR_BANVIOLATORS "ip_banviolators" new Regex:g_result new g_returnvalue new g_error[64] new g_allArgs[1024] #define MAXSLOTS 32 enum Color { YELLOW = 1, GREEN, TEAM_COLOR, GREY, RED, BLUE } new TeamName[][] = { "", "TERRORIST", "CT", "SPECTATOR" } new amx_arenag; new kill_points, death_points, time_points; new def_points, boom_points; new head_points, knife_points, nade_points, tk_points, skill_points; new TeamInfo,SayText,MaxSlots; new points[32], vote_choices[3] new bool:IsConnected[MAXSLOTS + 1]; new const HOSTNAME_TAG[ ] = "[ServersPT.com] "; public plugin_modules() { require_module("regex") } public hook_say(id, level, cid) { read_args(g_allArgs, 1023) g_result = regex_match(g_allArgs, PATTERN, g_returnvalue, g_error, 63) switch (g_result) { case REGEX_MATCH_FAIL: { log_amx("REGEX_MATCH_FAIL! %s", g_error) return PLUGIN_CONTINUE } case REGEX_PATTERN_FAIL: { log_amx("REGEX_PATTERN_FAIL! %s", g_error) return PLUGIN_CONTINUE } case REGEX_NO_MATCH: { return PLUGIN_CONTINUE } default: { if (get_cvar_num(CVAR_BANVIOLATORS)) { new userid = get_user_userid(id) new minutesString[10] get_cvar_string(CVAR_BANMINUTES, minutesString, 9) new temp[64], banned[16], minutes = get_cvar_num(CVAR_BANMINUTES) if (minutes) format(temp, 63, "%L", id, "FOR_MIN", minutesString) else format(temp, 63, "%L", id, "PERM") format(banned, 15, "%L", id, "BANNED") new authid[32] get_user_authid(id, authid, 31) new name[32] get_user_name(id, name, 31) log_amx("%s (%s), %s %s because of advertising an IP address. This was written: ^"%s^"", name, authid, banned, temp, g_allArgs) server_cmd("kick #%d ^"%s (%s %s)^";wait;banid ^"%d^" ^"%s^";wait;writeid", userid, REASON, banned, temp, minutes, authid) } else { client_cmd(id, "say ^"Publicacao de outros IPs nao permitido!^"") } regex_free(g_result) return PLUGIN_HANDLED // block msg } } return PLUGIN_CONTINUE } public plugin_init() { register_plugin(Plugin, Version, Author); kill_points = register_cvar("PS_kill_points", "1"); death_points = register_cvar("PS_death_points", "1"); def_points = register_cvar("PS_defusion_points", "5"); boom_points = register_cvar("PS_boom_points", "4"); time_points = register_cvar("PS_time_points", "15"); head_points = register_cvar("PS_head_points", "2"); knife_points = register_cvar("PS_knife_points", "4"); nade_points = register_cvar("PS_nade_points", "4"); tk_points = register_cvar("PS_tk_points", "8"); skill_points = register_cvar("PS_skill_points", "3"); register_clcmd("say .skill", "show_points"); register_clcmd("say /skill", "show_points") register_clcmd("say .sp", "show_points") register_clcmd("say /sp", "show_points") register_clcmd("say .skillpoints", "show_points") register_clcmd("say /skillpoints", "show_points") register_clcmd("say .pontos", "show_points") register_clcmd("say /pontos", "show_points") register_clcmd("say .points", "show_points") register_clcmd("say /points", "show_points") register_clcmd("say .top15", "show_top15"); register_clcmd("say /top15", "show_top15"); register_clcmd("say .topskill", "show_top15"); register_clcmd("say /topskill", "show_top15"); register_concmd("amx_points", "cmd_points", ADMIN_BAN, " - <name> <points> Set's someones points"); register_concmd("amx_vote_point", "cmd_vote_points", ADMIN_BAN, " - <name> <reason> <give/remove> Start's a point vote"); register_concmd("amx_showpoints","cmd_show_points",ADMIN_BAN," - <name> Show points of a player!"); register_dictionary("statsx.txt") register_clcmd("say .hp", "show_points", 0, "- display current round stats (chat)") register_clcmd("say_team .hp", "show_points", 0, "- display current round stats (chat)") amx_arenag = register_cvar( "amx_arenag", "theARENA .EU" ); register_forward( FM_GetGameDescription, "GameDesc" ); TeamInfo = get_user_msgid("TeamInfo"); SayText = get_user_msgid("SayText"); MaxSlots = get_maxplayers(); register_clcmd("say", "hook_say") register_cvar(CVAR_BANVIOLATORS, "0") register_cvar(CVAR_BANMINUTES, "30") register_dictionary("admincmd.txt") new pCvar_HostName = get_cvar_pointer( "hostname" ); new szHostName[ 64 ]; get_pcvar_string( pCvar_HostName, szHostName, charsmax( szHostName ) ); if( contain( szHostName, HOSTNAME_TAG ) != 0 ) { format( szHostName, charsmax( szHostName ), "%s %s", HOSTNAME_TAG, szHostName ); set_pcvar_string( pCvar_HostName, szHostName ); } } public GameDesc( ) { static gamename[32]; get_pcvar_string( amx_arenag, gamename, 31 ); forward_return( FMV_STRING, gamename ); return FMRES_SUPERCEDE; } public cmd_show_points(id, level, cid) { if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED; new arg[32], pname[32] read_argv(1, arg, 31) new player = cmd_target(id, arg, 8) get_user_name(player,pname,31); if(!player) return PLUGIN_HANDLED; client_print(id,print_console,"%s, tens %d skillpoints!",pname,points[player]); return 1; } public cmd_points(id, level, cid) { if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED; new arg1[32], arg2[11], name[32] read_argv(1, arg1, 31) read_argv(2, arg2, 10) new player = cmd_target(id, arg1, 1) if(!player) return PLUGIN_HANDLED; points[player] = str_to_num(arg2) get_user_name(player, name, 31) client_print(id, print_console,"Successfully set %s skillpoints to %s!", name, arg2) // ColorChat(player,GREY,"Admin deu skillpoints a ^x04%s", arg2) return PLUGIN_HANDLED; } public cmd_vote_points(id, level, cid) { if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED; new arg1[32], arg2[132], arg3[17] read_argv(1, arg1, 31) read_argv(2, arg2, 131) read_argv(3, arg3, 16) if(!equal(arg3, "give") & !equal(arg3, "remove")) { client_print(id, print_chat, "invalid mode. Valid modes are: give, remove.") return PLUGIN_HANDLED; } new player = cmd_target(id, arg1, 2) display_menu(player, arg2, arg3) return PLUGIN_HANDLED; } public save_points(id) { new valut = nvault_open("points") if(valut == INVALID_HANDLE) set_fail_state("nValut returned invalid handle") new key[62], value[10], ip[33] //get_user_ip(id, ip, 32, 1); get_user_authid(id, ip, 32); format(key, 61,"%s-points", ip) format(value, 9,"%d", points[id]) nvault_set(valut, key, value) nvault_close(valut) return PLUGIN_CONTINUE; } public load_points(id) { new valut = nvault_open("points") if(valut == INVALID_HANDLE) set_fail_state("nValut returned invalid handle") new key[100], ip[33] //get_user_ip(id, ip, 32, 1); get_user_authid(id, ip, 32); formatex(key, 99,"%s-points", ip) points[id] = nvault_get(valut, key) nvault_close(valut) return PLUGIN_CONTINUE; } public show_points(id) { ColorChat(id, GREEN, "[ARENA] ^x01Tu tens ^x03%d ^x01skillpoints!", points[id]) } public give_time_points(id) { if(cs_get_user_team(id) != CS_TEAM_SPECTATOR) { points[id] += get_pcvar_num(time_points) } } public client_putinserver(id) { set_task(3600.0, "give_time_points", id,_,_,"b") set_task(20.0, "advertise", id) load_points(id) } public client_disconnect(id) { save_points(id) } public client_death(killer, victim, weapon, hitplace, TK) { if(TK ) { points[killer] -= get_pcvar_num(tk_points) return PLUGIN_CONTINUE } points[killer] += get_pcvar_num(kill_points) if(points[victim] >= 100) { points[victim] -= get_pcvar_num(death_points) } if(hitplace == HIT_HEAD ) { points[killer] += get_pcvar_num(head_points) } if(weapon == CSW_KNIFE ) { points[killer] += get_pcvar_num(knife_points) } if(weapon == CSW_HEGRENADE ) { points[killer] += get_pcvar_num(nade_points) } if(weapon == CSW_KNIFE && hitplace == HIT_HEAD ) { points[killer] += get_pcvar_num(skill_points) } return PLUGIN_CONTINUE; } public bomb_explode(planter) { points[planter] += get_pcvar_num(boom_points) } public bomb_defused(defuser) { points[defuser] += get_pcvar_num(def_points) } public show_top15(id) { new i, count; static sort[33][2], maxPlayers; if(!maxPlayers) maxPlayers = get_maxplayers(); for(i=1;i<=maxPlayers;i++) { sort[count][0] = i; sort[count][1] = points[i]; count++; } SortCustom2D(sort,count,"stats_custom_compare"); new motd[1024], len len = format(motd, 1023,"<body bgcolor=#000000><font color=#FFB000><pre>") len += format(motd[len], 1023-len,"%2s %-22.22s %6s^n", "#", "Nick", "SkillPoints") static name[32] for(new a = 0; a < 15; a++) { get_user_name(sort[a][0], name, 31) len += format(motd[len], 1023-len,"%2d %-22.22s %6d^n", a + 1, name, sort[a][1]) } len += format(motd[len], 1023-len,"</body></font></pre>") show_motd(id, motd, "SkillTOPs:") return PLUGIN_CONTINUE; } public stats_custom_compare(elem1[],elem2[]) { if(elem1[1] > elem2[1]) return -1; else if(elem1[1] < elem2[1]) return 1; return 0; } public display_menu(id, reason[], mode[]) { new temp[56], name[32] get_user_name(id, name, 31) if(equal(mode, "give")) format(temp, 55, "\rGive %s a point because %s?", name, reason) else if(equal(mode, "remove")) format(temp, 55, "\rRemove a point from %s because %s?", name, reason) new menu = menu_create(temp, "menu_handler") menu_additem(menu, "\wSim", "1", 0) menu_additem(menu, "\wNao", "2", 0) for(new i = 1; i < get_playersnum(); i++) menu_display(i, menu, 0) set_task(30.0, "finish_vote", id, mode, 16) } public finish_vote(id, mode[]) { client_print(0, print_chat, "Voting over...") if(vote_choices[1] > vote_choices[2]) { if(equal(mode, "give")) { points[id]++ client_print(0, print_chat, "Choise ^"yes^" has won the vote!") client_print(id, print_chat, "You have been given a point") } else if(equal(mode, "remove")) { points[id]-- client_print(0, print_chat, "Choise ^"yes^" has won the vote!") client_print(id, print_chat, "You have lost a point") } } else if(vote_choices[1] < vote_choices[2]) { if(equal(mode, "give")) { client_print(0, print_chat, "Choise ^"no^" has won the vote!") client_print(id, print_chat, "Sorry, no point for you! =)") } else if(equal(mode, "remove")) { client_print(0, print_chat, "Choise ^"no^" has won the vote!") client_print(id, print_chat, "You where lucky and didn't lose any points") } } for(new i = 1; i < get_playersnum(); i++) menu_cancel(i) return PLUGIN_CONTINUE; } public menu_handler(id, menu, item) { if (item == MENU_EXIT) { menu_destroy(menu) return PLUGIN_HANDLED } new data[6], name[32] new access, callback menu_item_getinfo(menu, item, access, data, 5, _, _, callback) new key = str_to_num(data) get_user_name(id, name, 31) vote_choices[key]++ client_print(0, print_chat,"%s voted on %s", name, vote_choices[key] == 2 ? "yes":"no") menu_cancel(id) return PLUGIN_HANDLED; } public advertise(id) { client_print(id,print_chat,"[ARENA] Comandos: .skill .top15 .topskill .hp .add .remove .stop .demo") } stock ColorChat(id, Color:type, const msg[], any:...) { static message[256]; switch(type) { case YELLOW: { message[0] = 0x01; } case GREEN: { message[0] = 0x04; } default: { message[0] = 0x03; } } vformat(message[1], 251, msg, 4); message[192] = '^0'; new team, ColorChange, index, MSG_Type; if(!id) { index = FindPlayer(); MSG_Type = MSG_ALL; } else { MSG_Type = MSG_ONE; index = id; } team = get_user_team(index); ColorChange = ColorSelection(index, MSG_Type, type); ShowColorMessage(index, MSG_Type, message); if(ColorChange) { Team_Info(index, MSG_Type, TeamName[team]); } } stock ShowColorMessage(id, type, message[]) { message_begin(type, SayText, _, id); write_byte(id) write_string(message); message_end(); } stock Team_Info(id, type, team[]) { message_begin(type, TeamInfo, _, id); write_byte(id); write_string(team); message_end(); return 1; } stock ColorSelection(index, type, Color:Type) { switch(Type) { case RED: { return Team_Info(index, type, TeamName[1]); } case BLUE: { return Team_Info(index, type, TeamName[2]); } case GREY: { return Team_Info(index, type, TeamName[0]); } } return 0; } stock FindPlayer() { new i = -1; while(i <= MaxSlots) { if(IsConnected[++i]) { return i; } } return -1; }
|