求助,本人一个奖励插件遇到了问题,求懂的朋友帮忙(代码)
本帖最后由 scsfqqssyy 于 2011-6-27 22:04 编辑求助,本人一个奖励插件遇到了点问题,求懂的朋友帮忙
万分感谢,本人QQ182394553
目前的问题是:
1.当玩家的钱+奖励的钱有时超过10000W后会变为10000,我想把他去了
2.当玩家的钱+奖励的钱有时超过10000W会瞬间达到160000
希望能帮我看看,我上兆秒毫国外下在的,我把代码铁出来 本帖最后由 scsfqqssyy 于 2011-6-27 22:03 编辑
/********************************************************************************
Plugin name: Money All-in-One
Version: 3.3
Author: tomcash@263.net
*********************************************************************************
Cvars & default value
------------------------------
Amx_startmoney 800 //Fully instead of mp_startmoney.
Amx_maxmoney 30000 // Max money player can have.
The format of 9 cvars below here: cvarname "<bonus> <0|1>"(2nd argument control show chat msg or not, put nothing=1)
**NOTICE**
1. If set 2 arguments, double quotation is needed, even in console
2. DO NOT put too much blank between the two arguments, otherwise something bad will happen :D
**********
Amx_bonus_planter "500 1"// Bonus for C4 planter. Set 0 to disable.
Amx_bonus_explode "500 1"// Bonus for the planter when C4 was exploded. Set 0 to disable.
Amx_bonus_defuser "1000 1" // Bonus for who defused C4 bomb. Set 0 to disable.
Amx_bonus_headshot "200 1"// Bonus for player who headshot someone. Set 0 to disable.
Amx_bonus_o4killer "200 1"// Bonus for player who killed someone by grenade. Set 0 to disable.
Amx_bonus_9fkiller "5000 1"// Bonus for player who killed someone by knife. Set 0 to disable.
Amx_bonus_1stkiller "1000 1"// Bonus for the first killer in a round. Set 0 to disable as well as tow cvars followed.
Amx_bonus_2ndkiller "500 1"// Bonus for the second killer in a round. Set 0 to disable.
Amx_bonus_3rdkiller "300 1"// Bonus for the third killer in a round. Set 0 to disable.
Amx_servertag "" // A tag displayed at the head of color message, Need restart to enable change.
Amx_setgmnum 200 500 1000 2000 5000 10000 // See command explaination
Commands
-------------------------------
Amx_moneymenu
// Display Give Money to Player Menu.
Amx_setgmnum <amount1> ...
// Set the menu’s option amount.
Amx_givemoney <target> <amount>
//Give player money Command, <target> should be player name, or put a ‘@’ as prefix to group player.
********************************************************************************************/
// Modules...
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <csx>
#include <fakemeta>
//Constants..
#define MAX_CLIENTS 32 + 1
// Globle variables...
new g_client_connected
new g_client_money
new g_check_money
new g_rankcounter
new g_restartround
new Array:g_moneysettings
new g_tag
new g_money_msgid
new g_saytext_msgid
// Cvars........
new amx_servertag
new amx_startmoney
new amx_maxmoney
new amx_bonus_planter
new amx_bonus_explode
new amx_bonus_defuser
new amx_bonus_1stkiller
new amx_bonus_2ndkiller
new amx_bonus_3rdkiller
new amx_bonus_headshot
new amx_bonus_9fkiller
new amx_bonus_o4killer
public plugin_init() {
register_plugin("Money All-in-One", "3.3", "tomcash@263.net")
register_dictionary("money_aio.txt")
register_logevent("fn_restartround",2,"0=World triggered","1&Restart_Round_","1&Game_Commencing")
register_logevent("fn_roundstart",2,"0=World triggered","1&Round_Start")
register_logevent("fn_joinfromspec",3,"1=joined team")
register_event("RoundTime","fn_newround","bde")
register_event("Money","fn_event_money","b")
register_srvcmd("amx_setgmnum", "fn_setgmnum")
register_concmd("amx_givemoney", "fn_cmd_givemoney", ADMIN_USER, "<target> <amount>")
register_concmd("amx_moneymenu", "fn_cmdGM2PMenu", ADMIN_USER, "- displays Give Money to Player Menu")
register_menucmd(register_menuid("Give Money to Player Menu"), 1023, "fn_actionGM2PMenu")
amx_servertag = register_cvar("amx_bonus_servertag","")
amx_startmoney = register_cvar("amx_startmoney", "800")
amx_maxmoney = register_cvar("amx_maxmoney", "30000")
amx_bonus_planter = register_cvar("amx_bonus_planter", "500 1")
amx_bonus_explode = register_cvar("amx_bonus_explode", "500 1")
amx_bonus_defuser = register_cvar("amx_bonus_defuser", "1000 1")
amx_bonus_1stkiller = register_cvar("amx_bonus_1stkiller", "1000 1")
amx_bonus_2ndkiller = register_cvar("amx_bonus_2ndkiller", "500 1")
amx_bonus_3rdkiller = register_cvar("amx_bonus_3rdkiller", "300 1")
amx_bonus_headshot = register_cvar("amx_bonus_headshot", "200 1")
amx_bonus_9fkiller = register_cvar("amx_bonus_9fkiller", "5000 1")
amx_bonus_o4killer = register_cvar("amx_bonus_o4killer", "200 1")
g_money_msgid = get_user_msgid("Money")
g_saytext_msgid = get_user_msgid("SayText")
g_moneysettings = ArrayCreate()
ArrayPushCell(g_moneysettings, 200)
ArrayPushCell(g_moneysettings, 500)
ArrayPushCell(g_moneysettings, 1000)
ArrayPushCell(g_moneysettings, 2000)
ArrayPushCell(g_moneysettings, 5000)
ArrayPushCell(g_moneysettings, 10000)
register_forward(FM_UpdateClientData,"fn_fwd_money")
}
public plugin_cfg(){
get_pcvar_string(amx_servertag,g_tag,31)
}
public client_connect(id){
g_client_connected = 1
}
public fn_restartround(){
g_restartround = 1
}
public fn_newround(id){
if(g_restartround)
fn_resetmoney(id)
fn_breakmoney(id,0)
}
public fn_roundstart(){
g_restartround = 0
g_rankcounter = 0
}
public fn_joinfromspec(){
new text,name,previous_team
read_logargv(0,text,63)
parse_loguser(text,name,31,_,_,_,previous_team,7)
if(previous_team == 'S')
fn_resetmoney(get_user_index(name))
}
public fn_resetmoney(id){
g_client_money = get_pcvar_num(amx_startmoney)
fn_breakmoney(id,g_client_money) // fn_breakmoney(id,flash_offset), flash_offset:the value flashing on HUD...
}
public fn_fwd_money(id, sendweapons, cd_handle ){
if(!is_user_connected(id))
return PLUGIN_HANDLED
new new_money = cs_get_user_money(id)
if(new_money != g_check_money){
fn_event_money(id)
g_check_money = new_money
}
return PLUGIN_CONTINUE
}
public fn_event_money(id){
if(!is_user_connected(id))
return PLUGIN_HANDLED
if(g_client_connected){
fn_resetmoney(id)
g_client_connected = 0
return PLUGIN_HANDLED
}
new current_money = cs_get_user_money(id)
new money_offset = 0
if(g_client_money>=10000){
money_offset = current_money - 10000
}
else{
money_offset = current_money - g_client_money
}
if(money_offset)
fn_add_player_money(id,money_offset) //fn_add_player_money(id,addtion), addtion:the value to add.
return PLUGIN_CONTINUE
}
public fn_add_player_money(id,addtion){
g_client_money+= addtion
fn_breakmoney(id,addtion)
}
public fn_breakmoney( id, flash_offset ){
if(!is_user_connected(id))
return PLUGIN_HANDLED
new maxmoney = get_pcvar_num(amx_maxmoney)
g_client_money = (g_client_money>maxmoney)?maxmoney:g_client_money
g_client_money = (g_client_money<0)?0:g_client_money
if(g_client_money>=10000){// When I clear my brain, I found it is very simple....
cs_set_user_money(id,10000,0)
}
else{
cs_set_user_money(id, g_client_money, 0)
}
message_begin( MSG_ONE_UNRELIABLE,g_money_msgid,{0,0,0},id)// Code from Ramono, very cute method :)
write_long(g_client_money-flash_offset)
write_byte(0)
message_end()
message_begin( MSG_ONE_UNRELIABLE,g_money_msgid,{0,0,0},id)
write_long(g_client_money)
write_byte(1)
message_end()
return PLUGIN_CONTINUE
} //----------------------------Bonus----------------------------------------------
public fn_parse_cvar(p_cvar, &arg1, &arg2){
new str_cvar, str_arg1, str_arg2
get_pcvar_string(p_cvar,str_cvar,32)
parse(str_cvar,str_arg1,16,str_arg2,16)
arg1 = str_to_num(str_arg1)
if(strlen(str_arg2))
arg2 = str_to_num(str_arg2)
else
arg2 = 1
}
public bomb_planted(planter){ //CSX native function...
new bonus, chatmsg
fn_parse_cvar(amx_bonus_planter,bonus,chatmsg)
if(!bonus)
return PLUGIN_HANDLED
fn_add_player_money(planter,bonus)
new name, s_bonus, msg
get_user_name(planter,name,31)
format(name,33,"^x03%s^x01",name)
format(s_bonus,7,"^x04%d^x01",bonus)
new i,players,player_num
get_players(players,player_num)
if(chatmsg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"BOMB_PLANTED",name,s_bonus)
fn_colorprint(players,planter,msg)
}
}
return PLUGIN_CONTINUE
}
public bomb_defused(defuser){ //CSX native function...
new bonus, chatmsg
fn_parse_cvar(amx_bonus_defuser,bonus,chatmsg)
if(!bonus)
return PLUGIN_HANDLED
fn_add_player_money(defuser,bonus)
new name, s_bonus, msg
get_user_name(defuser,name,31)
format(name,33,"^x03%s^x01",name)
format(s_bonus,7,"^x04%d^x01",bonus)
new i,players,player_num
get_players(players,player_num)
if(chatmsg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"BOMB_DEFUSED",name,s_bonus)
fn_colorprint(players,defuser,msg)
}
}
return PLUGIN_CONTINUE
}
public bomb_explode(planter){ //CSX native function...
new bonus, chatmsg
fn_parse_cvar(amx_bonus_explode,bonus,chatmsg)
if(!bonus)
return PLUGIN_HANDLED
fn_add_player_money(planter,bonus)
new name, s_bonus, msg
get_user_name(planter,name,31)
format(name,33,"^x03%s^x01",name)
format(s_bonus,7,"^x04%d^x01",bonus)
new i,players,player_num
get_players(players,player_num)
if(chatmsg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"BOMB_EXPLODE",name,s_bonus)
fn_colorprint(players,planter,msg)
}
}
return PLUGIN_CONTINUE
}
public client_death(killer,victim,wpnindex,hitplace,TK){ //CSX native function...
if(TK || killer == victim)
return PLUGIN_HANDLED
new i,players,player_num
get_players(players,player_num)
new name, s_bonus, msg
new bonus=0
get_user_name(killer,name,31)
format(name,33,"^x03%s^x01",name)
new hs_bonus, hs_msg
new o4_bonus, o4_msg
new kf_bonus, kf_msg
new r1_bonus, r1_msg
new r2_bonus, r2_msg
new r3_bonus, r3_msg
fn_parse_cvar(amx_bonus_headshot,hs_bonus,hs_msg)
fn_parse_cvar(amx_bonus_o4killer,o4_bonus,o4_msg)
fn_parse_cvar(amx_bonus_9fkiller,kf_bonus,kf_msg)
fn_parse_cvar(amx_bonus_1stkiller,r1_bonus,r1_msg)
fn_parse_cvar(amx_bonus_2ndkiller,r2_bonus,r2_msg)
fn_parse_cvar(amx_bonus_3rdkiller,r3_bonus,r3_msg)
if(hs_bonus && hitplace==HIT_HEAD){
bonus += hs_bonus
format(s_bonus,7,"^x04%d^x01", hs_bonus)
if(hs_msg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"HEAD_SHOT",name,s_bonus)
fn_colorprint(players,killer,msg)
}
}
}
if(o4_bonus && wpnindex==CSW_HEGRENADE){
bonus += o4_bonus
format(s_bonus,7,"^x04%d^x01",o4_bonus)
if(o4_msg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"GRENADE_KILL",name,s_bonus)
fn_colorprint(players,killer,msg)
}
}
}
if(kf_bonus && wpnindex==CSW_KNIFE){
bonus += kf_bonus
format(s_bonus,7,"^x04%d^x01",get_pcvar_num(amx_bonus_9fkiller))
if(kf_msg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"KNIFE_KILL",name,s_bonus)
fn_colorprint(players,killer,msg)
}
}
}
new rk_bonus
if(r1_bonus && g_rankcounter<3){
switch(g_rankcounter){
case 0:rk_bonus = r1_bonus
case 1:rk_bonus = r2_bonus
case 2:rk_bonus = r3_bonus
}
bonus += rk_bonus
format(s_bonus,7,"^x04%d^x01",rk_bonus)
if(r1_msg){
for(i=0;i<player_num;i++){
format(msg,255,"^x01%s :: %L",g_tag,players,"RUSH_KILL",name,g_rankcounter+1,s_bonus)
fn_colorprint(players,killer,msg)
}
}
}
fn_add_player_money(killer,bonus)
g_rankcounter++
return PLUGIN_CONTINUE
}
public fn_colorprint(playerid, colorid, msg[]){ //the code from google...Thanks the origin author.
message_begin(playerid?MSG_ONE_UNRELIABLE:MSG_ALL,g_saytext_msgid,_,playerid)
write_byte(colorid)
write_string(msg)
message_end()
}
public client_disconnect(id){
g_client_money = 0
}
//------------------------------------MENU-------------------------------------------------------
/*
The idea from plmenu.sma, but modify the code was not a easy task.
*/
new g_menuPosition
new g_menuPlayers
new g_menuPlayersNum
new g_menuOption
new g_menuSettings
public fn_cmdGM2PMenu(id, level, cid){
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
g_menuOption = 0
if (ArraySize(g_moneysettings) > 0){
g_menuSettings = ArrayGetCell(g_moneysettings, g_menuOption);
}
else{
g_menuSettings = 0
}
fn_displayGM2PMenu(id, g_menuPosition = 0)
return PLUGIN_CONTINUE
}
fn_displayGM2PMenu(id, pos){
if (pos < 0)
return
get_players(g_menuPlayers, g_menuPlayersNum)
new menuBody
new b = 0
new i
new name
new start = pos * 7
if (start >= g_menuPlayersNum+3)
start = pos = g_menuPosition = 0
new end = start + 7
if (end > g_menuPlayersNum+3)
end = g_menuPlayersNum+3
new keys = MENU_KEY_0|MENU_KEY_8
new len = format(menuBody, 511,"\y%L\R%d/%d^n\w^n",id,"MENU_NAME", pos + 1, ((g_menuPlayersNum+3) / 7 + (((g_menuPlayersNum+3) % 7) ? 1 : 0)))
for (new a = start; a < end; ++a)
{
keys |= (1<<b)
if(a < g_menuPlayersNum){
i = g_menuPlayers
get_user_name(i, name, 31)
if (is_user_admin(i)){
if(!access(id,ADMIN_KICK)){
len += format(menuBody, 511-len, "%d. %s \r*\y\R^n\w" , ++b, name)
}
else{
len += format(menuBody, 511-len, "%d. %s \r*\y\R%d$^n\w" , ++b, name,g_client_money)
}
}
else{
if(!access(id,ADMIN_KICK)){
len += format(menuBody, 511-len, "%d. %s\y\R^n\w" , ++b, name)
}
else{
len += format(menuBody, 511-len, "%d. %s\y\R%d$^n\w" , ++b, name,g_client_money)
}
}
}
if(a==g_menuPlayersNum)
len += format(menuBody, 512-len, "^n%d. \y%L ^n\w" , ++b, id,"ALL_CTS")
if(a==g_menuPlayersNum+1)
len += format(menuBody, 512-len,"%d. \y%L ^n\w" , ++b, id, "ALL_TS")
if(a==g_menuPlayersNum+2)
len += format(menuBody, 512-len,"%d. \y%L ^n\w" , ++b, id,"ALL_PLAYERS")
}
len += format(menuBody, 511-len, "^n8. %L: %d^n", id,"MENU_AMOUNT", g_menuSettings)
if (end != g_menuPlayersNum+3){
keys |= MENU_KEY_9
format(menuBody, 511-len, "^n9. %L...^n0. %L", id, "MENU_MORE",id,pos ? "MENU_BACK" : "MENU_EXIT")
}
else{
format(menuBody, 511-len, "^n0. %L",id, pos ? "MENU_BACK" : "MENU_EXIT")
}
show_menu(id, keys, menuBody, -1, "Give Money to Player Menu")
}
public fn_actionGM2PMenu(id, key){
switch (key)
{
case 7:{
++g_menuOption
g_menuOption %= ArraySize(g_moneysettings)
g_menuSettings = ArrayGetCell(g_moneysettings, g_menuOption)
fn_displayGM2PMenu(id, g_menuPosition)
}
case 8: fn_displayGM2PMenu(id, ++g_menuPosition)
case 9: fn_displayGM2PMenu(id, --g_menuPosition)
default:{
if(g_menuPosition * 7 + key < g_menuPlayersNum){
new player = g_menuPlayers * 7 + key]
if(!access(id,ADMIN_KICK)){
if(g_menuSettings<0)
return PLUGIN_HANDLED
if(g_client_money<g_menuSettings){
client_print(id,print_center,"You have insufficient fund!")
return PLUGIN_HANDLED
}
fn_add_player_money(id,-g_menuSettings)
}
fn_add_player_money(player,g_menuSettings)
fn_displayGM2PMenu(id, g_menuPosition)
}
if(g_menuPosition * 7 + key ==g_menuPlayersNum){
for(new i=0;i<g_menuPlayersNum;i++){
if(get_user_team(g_menuPlayers)==2){
if(!access(id,ADMIN_KICK)){
if(g_menuSettings<0)
return PLUGIN_HANDLED
if(g_client_money<g_menuSettings){
client_print(id,print_center,"You have insufficient fund!")
return PLUGIN_HANDLED
}
fn_add_player_money(id,-g_menuSettings)
}
fn_add_player_money(g_menuPlayers,g_menuSettings)
}
}
fn_displayGM2PMenu(id, g_menuPosition)
//add all CTs money
}
if(g_menuPosition * 7 + key ==g_menuPlayersNum+1){
for(new i=0;i<g_menuPlayersNum;i++){
if(get_user_team(g_menuPlayers)==1){
if(!access(id,ADMIN_KICK)){
if(g_menuSettings<0)
return PLUGIN_HANDLED
if(g_client_money<g_menuSettings){
client_print(id,print_center,"You have insufficient fund!")
return PLUGIN_HANDLED
}
fn_add_player_money(id,-g_menuSettings)
}
fn_add_player_money(g_menuPlayers,g_menuSettings)
}
}
fn_displayGM2PMenu(id, g_menuPosition)
//add all Ts money
}
if(g_menuPosition * 7 + key ==g_menuPlayersNum+2){
for(new i=0;i<g_menuPlayersNum;i++){
if(!access(id,ADMIN_KICK)){
if(g_menuSettings<0)
return PLUGIN_HANDLED
if(g_client_money<g_menuSettings){
client_print(id,print_center,"You have insufficient fund!")
return PLUGIN_HANDLED
}
fn_add_player_money(id,-g_menuSettings)
}
fn_add_player_money(g_menuPlayers,g_menuSettings)
}
fn_displayGM2PMenu(id, g_menuPosition)
//add all Players money
}
}
}
return PLUGIN_CONTINUE
}
public fn_setgmnum(){
new buff
new args = read_argc()
if (args <= 1){
server_print("usage: amx_setgmnum <num1> ...")
return PLUGIN_HANDLED
}
ArrayClear(g_moneysettings)
for (new i = 1; i < args; i++) {
read_argv(i, buff, charsmax(buff))
ArrayPushCell(g_moneysettings, str_to_num(buff))
}
return PLUGIN_CONTINUE
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil\\ fcharset134 Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2052\\ f0\\ fs16 \n\\ par }
*/
if(g_client_money>=10000){// When I clear my brain, I found it is very simple....
cs_set_user_money(id,10000,0) new maxmoney = get_pcvar_num(amx_maxmoney)
g_client_money = (g_client_money>maxmoney)?maxmoney:g_client_money
g_client_money = (g_client_money<0)?0:g_client_money
主要是这几句的关系,自己修改一下
页:
[1]