搜索
查看: 7614|回复: 9

关于AMX的送钱插件

[复制链接]
发表于 2003-6-20 13:40:53 | 显示全部楼层 |阅读模式 来自 中国–广东–汕头
AMX的送钱插件,但是可以键入负数的钱,就相等从别人偷钱。原程序在下面。帮我看看能不能对cash加个绝对值。

/* AMX Mod script.
*
* (c) 2003, AssKicR
* This file is provided as is (no warranties).
* Thanx to Vud911 for the idea
*
* Example: say /transfer "persononyourteam" "amount" and it'll deducte the amount from your cash pool and add it to the targets.
*
* Result Of Example
* SuperNewbie: "Can someone send me some $$$ for awp???"
* SuperElitePlayerWhoHasTooMuch$$$: "I'm Bill Gates!!! 4000$ coming your way!!!
* SuperElitePlayerWhohasTooMuch$$$: "/transfer newbie 4000"
* [AMX] SuperElitePlayerWhohasTooMuch$$$ has transferred 4000$ to SuperNewbie. Give him a thanks  
* SuperNewbie: "Thank You SuperElitePlayerWhohasTooMuch$$$"
*
* Changelog
* v.1.0.0 - Released
* v 1.0.1 - Added a little more restriction... Dead People can't handle money anymore
*/

#include <amxmod>
#include <amxmisc>

public plugin_init() {  
        register_plugin("Cash Transfer","1.0.1","AssKicR")  
        register_concmd("say","handle_say",ADMIN_USER)
        register_concmd("say_team","handle_say",ADMIN_USER)
        return PLUGIN_CONTINUE  
}

public handle_say(id)
{
//Show me the money :D

new said[31]
new cmd[10]
new target[8]
new amount[6]
new rest[7]
                  
read_args(said, 30)
replace(said, 30, "^"", "")
parse(said, cmd,9, target,7, amount,5, rest,6)

new player = cmd_target(id,target,7)
new name[33]
new name2[33]
get_user_name(id,name,32)
get_user_name(player,name2,32)     
new team[32]
new team2[32]
get_user_team(id,team,32)
get_user_team(player,team2,32)

if (equal(cmd, "/transfer", 9)) {
        new money = get_user_money(id)
        new money2 = get_user_money(player)
        new cash = str_to_num(amount)

        if (!is_user_alive(id)) {
                client_print(id,print_center,"You can't give away money while dead")
                return PLUGIN_CONTINUE
        }
        if (!is_user_alive(player)) {
                client_print(id,print_center,"You can't give money to dead people")
                return PLUGIN_CONTINUE
        }
        if (equal(name, name2)) {
                client_print(id,print_center,"You can't give money to yourself")
                return PLUGIN_CONTINUE
        }
        if (!equal(team, team2)) {
                client_print(id,print_center,"You can't give money to the enemy team")
                return PLUGIN_CONTINUE
        }
        if ((money2 + cash) > 16000) {
                client_print(id,print_center,"%s can't carry that much money",name2)
                return PLUGIN_CONTINUE
                }
        if (money < cash) {
                client_print(id,print_center,"You don't have that much money")
                return PLUGIN_CONTINUE
        }else{
                set_user_money(id, money - cash,1)
                set_user_money(player, money2+ cash,1)
                client_print(0,print_chat,"[AMX] %s transferd %i $ to %s. Give him a thanks",name,cash,name2)
                engclient_cmd(player,"say Thank you %s",name)
                }
        }
return PLUGIN_CONTINUE                       
}
发表于 2003-6-21 01:08:17 | 显示全部楼层 来自 中国–福建–厦门

嗯,这个是改过的版本

郁闷得很,amx居然连一个取绝对值的函数都没有,只好用土办法了
下面是改过的代码,你自个儿编译一下吧

/* AMX Mod script.
*
* (c) 2003, AssKicR
* This file is provided as is (no warranties).
* Thanx to Vud911 for the idea
*
* Example: say /transfer "persononyourteam" "amount" and it'll deducte the amount from your cash pool and add it to the targets.
*
* Result Of Example
* SuperNewbie: "Can someone send me some $$$ for awp???"
* SuperElitePlayerWhoHasTooMuch$$$: "I'm Bill Gates!!! 4000$ coming your way!!!
* SuperElitePlayerWhohasTooMuch$$$: "/transfer newbie 4000"
* [AMX] SuperElitePlayerWhohasTooMuch$$$ has transferred 4000$ to SuperNewbie. Give him a thanks
* SuperNewbie: "Thank You SuperElitePlayerWhohasTooMuch$$$"
*
* Changelog
* v.1.0.0 - Released
* v 1.0.1 - Added a little more restriction... Dead People can't handle money anymore
*/

#include <amxmod>
#include <amxmisc>

public plugin_init() {
register_plugin("Cash Transfer","1.0.1","AssKicR")
register_concmd("say","handle_say",ADMIN_USER)
register_concmd("say_team","handle_say",ADMIN_USER)
return PLUGIN_CONTINUE
}

public handle_say(id)
{
//Show me the money

new said[31]
new cmd[10]
new target[8]
new amount[6]
new rest[7]

read_args(said, 30)
replace(said, 30, "^"", "")
parse(said, cmd,9, target,7, amount,5, rest,6)

new player = cmd_target(id,target,7)
new name[33]
new name2[33]
get_user_name(id,name,32)
get_user_name(player,name2,32)
new team[32]
new team2[32]
get_user_team(id,team,32)
get_user_team(player,team2,32)

if (equal(cmd, "/transfer", 9)) {
new money = get_user_money(id)
new money2 = get_user_money(player)
new cash = str_to_num(amount)

if (cash<0){
cash=-cash
}

if (!is_user_alive(id)) {
client_print(id,print_center,"You can't give away money while dead")
return PLUGIN_CONTINUE
}
if (!is_user_alive(player)) {
client_print(id,print_center,"You can't give money to dead people")
return PLUGIN_CONTINUE
}
if (equal(name, name2)) {
client_print(id,print_center,"You can't give money to yourself")
return PLUGIN_CONTINUE
}
if (!equal(team, team2)) {
client_print(id,print_center,"You can't give money to the enemy team")
return PLUGIN_CONTINUE
}
if ((money2 + cash) > 16000) {
client_print(id,print_center,"%s can't carry that much money",name2)
return PLUGIN_CONTINUE
}
if (money < cash) {
client_print(id,print_center,"You don't have that much money")
return PLUGIN_CONTINUE
}else{
set_user_money(id, money - cash,1)
set_user_money(player, money2+ cash,1)
client_print(0,print_chat,"[AMX] %s transferd %i $ to %s. Give him a thanks",name,cash,name2)
engclient_cmd(player,"say Thank you %s",name)
}
}
return PLUGIN_CONTINUE
}
回复

使用道具 举报

 楼主| 发表于 2003-6-21 10:20:33 | 显示全部楼层 来自 中国–广东–汕头
3q
回复

使用道具 举报

 楼主| 发表于 2003-6-21 13:40:45 | 显示全部楼层 来自 中国–广东–汕头
这是1。003版,我也是按你的方法加了
       if (cash<0){
       cash=-cash
       }
但却报65、69出错。我修改的如下,麻烦在帮我看看哪里有问题。

/* AMX Mod script.
*
* (c) 2003, AssKicR
* This file is provided as is (no warranties).
* Thanx to Vud911 for the idea
*
* Example: /transfer "persononyourteam" "amount" and it'll deducte the amount from your cash pool and add it to the targets.
*
* Result Of Example
* SuperNewbie: "Can someone send me some $$$ for awp???"
* SuperElitePlayerWhoHasTooMuch$$$: "I'm Bill Gates!!! 4000$ coming your way!!!
* SuperElitePlayerWhohasTooMuch$$$: "/transfer newbie 4000"
* [AMX] SuperElitePlayerWhohasTooMuch$$$ has transferred 4000$ to SuperNewbie. Give him a thanks  
* SuperNewbie: "Thank You SuperElitePlayerWhohasTooMuch$$$"
*
* Changelog
* v.1.0.0 - Released
* v 1.0.1 - Added a little more restriction... Dead People can't handle money anymore
* v 1.0.2 - Added Restrict for cash stealing
* v 1.0.3 - Added Cvars - mt_cashsteal, mt_cashdead, mt_cashteam
*/

#include <amxmod>
#include <amxmisc>

public plugin_init() {  
        register_plugin("Cash Transfer","1.0.3","AssKicR")  
        register_concmd("say","handle_say",ADMIN_USER)
        register_concmd("say_team","handle_say",ADMIN_USER)
        register_cvar("mt_cashsteal","1",0)
        register_cvar("mt_cashdead","1",0)
        register_cvar("mt_cashteam","1",0)
        return PLUGIN_CONTINUE  
}

public handle_say(id)
{
//Show me the money

new said[31]
new cmd[10]
new target[9]
new amount[7]
new rest[5]
                  
read_args(said, 30)
replace(said, 30, "^"", "")
parse(said, cmd,9, target,8, amount,6, rest,4)

new player = cmd_target(id,target,8)
new name[33]
new name2[33]
get_user_name(id,name,32)
get_user_name(player,name2,32)     
new team[32]
new team2[32]
get_user_team(id,team,32)
get_user_team(player,team2,32)

if (equal(cmd, "/transfer", 9)) {
        new money = get_user_money(id)
        new money2 = get_user_money(player)
        new cash = str_to_num(amount)
       
       if (cash<0){
       cash=-cash
       }

        if (get_cvar_num("mt_cashdead")==0) {
                if (!is_user_alive(id)) {
                        client_print(id,print_center,"You can't give away money while dead")
                        return PLUGIN_CONTINUE
                }
                if (!is_user_alive(player)) {
                        client_print(id,print_center,"You can't give money to dead people")
                        return PLUGIN_CONTINUE
                }
        }
        if (equal(name, name2)) {
                client_print(id,print_center,"You can't give money to yourself")
                return PLUGIN_CONTINUE
        }
        if (get_cvar_num("mt_cashteam")==0) {
                if (!equal(team, team2)) {
                        client_print(id,print_center,"You can't give money to the enemy team")
                        return PLUGIN_CONTINUE
                }
        }
        if ((money2 + cash) > 16000) {
                client_print(id,print_center,"%s can't carry that much money")
                return PLUGIN_CONTINUE
                }
        if (money < cash) {
                client_print(id,print_center,"You don't have that much money")
                return PLUGIN_CONTINUE
                }
        if (get_cvar_num("mt_cashsteal")==0) {
                if (cash < 0) {
                        client_print(id,print_center,"You can't steal %s's money",name2)
                        return PLUGIN_CONTINUE
                }
        }else{
                set_user_money(id, money - cash,1)
                set_user_money(player, money2+ cash,1)
                client_print(0,print_chat,"[AMX] %s transferd %i $ to %s. Give him a thanks",name,cash,name2)
                engclient_cmd(id,"say Thank you %s",name)
                }
        }
return PLUGIN_CONTINUE                       
}
回复

使用道具 举报

 楼主| 发表于 2003-6-21 13:42:50 | 显示全部楼层 来自 中国–广东–汕头
好了,没问题了,谢谢。
回复

使用道具 举报

发表于 2003-6-21 14:05:24 | 显示全部楼层 来自 中国–福建–厦门

一般来说

编译时出的warning xxx 都是因为脚本里的语句的缩进格式有问题造成的

所以,建议:修改amx的脚本的时候最好用ultraedit之类的编辑器会更加方便和不容易出错误一点点
回复

使用道具 举报

发表于 2003-6-21 15:31:45 | 显示全部楼层 来自 中国–福建–厦门

tony同志请注意

这个插件的1.03版已经有了你说的这个bug的解决方案了:

设置一个cvar
mt_cashsteal

0:如果玩家输入负数的话,不会对相关的玩家的金钱发生操作,并给输入负数的玩家一个警告

1:就跟原来的是一模一样的了,还是可以偷别人的钱的

该版本还增添了几个设置参数,具体的你可以自己去看看,一般用默认设置就好了

over
回复

使用道具 举报

 楼主| 发表于 2003-6-21 17:35:27 | 显示全部楼层 来自 中国–广东–汕头
恩,开始我是用记事本编辑,没有注意到空格的问题,现在明白了。THX
回复

使用道具 举报

 楼主| 发表于 2003-6-21 18:28:18 | 显示全部楼层 来自 中国–广东–汕头–澄海区
if (get_cvar_num("mt_cashsteal")==0) {
                if (cash < 0) {
                        client_print(id,print_center,"You can't steal %s's money",name2)
                        return PLUGIN_CONTINUE
                }
        }else{
                set_user_money(id, money - cash,1)
                set_user_money(player, money2+ cash,1)
                client_print(0,print_chat,"[AMX] %s transferd %i $ to %s. Give him a thanks",name,cash,name2)
                engclient_cmd(id,"say Thank you %s",name)
                }
        }


这一段好象不对,mt_cashsteal=0并且cash < 0时,不会出You can't steal %s's money的警告。
是不是不能用“==”,而是用“=”呢?
回复

使用道具 举报

发表于 2003-6-21 21:11:45 | 显示全部楼层 来自 中国–福建–厦门
这段东西是没错的,不过根据这段代码,你看不到的提示是比较不显眼的那种文字,你再仔细看看吧

至于符号的问题,相信你随便去找一本c相关的书过来看看就明白了

最初由 tony 发表


这一段好象不对,mt_cashsteal=0并且cash &lt; 0时,不会出You can't steal %s's money的警告。
是不是不能用“==”,而是用“=”呢?
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表