请帮忙修改一个插件,制定权限玩家自动给与兔子帽子
以下是帽子插件源码,我搞了好几天都没弄好希望大家请教或者帮忙改好
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
//判断用户权限
new g_bwEnt
#define PLUG_NAME "HATS"
#define PLUG_AUTH "SgtBane"
#define PLUG_VERS "0.2"
#define PLUG_TAG "HATS"
//菜单大小
#define menusize 220
//帽子文件
new HatFile
//菜单顶部,所有帽子
new MenuPages, TotalHats
//当前菜单
new CurrentMenu
//最大帽子数
#define MAX_HATS 64
//帽子模型,最大数
new HATMDL
//帽子名字
new HATNAME
//公共插件配置
public plugin_init()
{
register_plugin(PLUG_NAME, PLUG_VERS, PLUG_AUTH)
//给与帽子
register_concmd("amx_givehat", "Give_Hat", ADMIN_RCON, "<nick> <mdl #>")
//删除所有的帽子
register_concmd("amx_removehats", "Remove_Hat", ADMIN_RCON, " - Removes hats from everyone.")
//菜单命令
register_menucmd(register_menuid("\yHat Menu: [Page"),(1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9),"MenuCommand")
//调出帽子菜单
register_clcmd("say /hats", "ShowMenu", -1, "Shows Knife menu")
}
//显示菜单
public ShowMenu(id)
{
//当前菜单
CurrentMenu = 1
//显示帽子
ShowHats(id)
return PLUGIN_HANDLED
}
//显示帽子菜单
public ShowHats(id)
{
new keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
new szMenuBody, WpnID //新的菜单主体,菜单大小
new nLen = format(szMenuBody, menusize, "\yHat Menu: ^n",CurrentMenu,MenuPages) //格式化菜单,菜单实体,菜单大小
// Get Hat Names And Add Them To The List
// 获得帽子名称,并将它们添加到列表
for (new hatid=0; hatid < 8; hatid++) {
WpnID = ((CurrentMenu * 8) + hatid - 8)
if (WpnID < TotalHats) {
nLen += format(szMenuBody, menusize-nLen, "^n\w %i. %s",hatid + 1,HATNAME)
}
}
// Next Page And Previous/Close
// 下一页和上一页/关闭
if (CurrentMenu == MenuPages) {
nLen += format(szMenuBody, menusize-nLen, "^n^n\d9. Next Page")
} else {
nLen += format(szMenuBody, menusize-nLen, "^n^n\w9. Next Page")
}
if (CurrentMenu > 1) {
nLen += format(szMenuBody, menusize-nLen, "^n\w0. Previous Page")
} else {
nLen += format(szMenuBody, menusize-nLen, "^n\w0. Close")
}
show_menu(id, keys, szMenuBody, -1)
return PLUGIN_HANDLED
}
//菜单命令
public MenuCommand(id, key)
{
switch(key) //开关键
{
case 8: //9 -
{
if (CurrentMenu < MenuPages) CurrentMenu++
ShowHats(id)
return PLUGIN_HANDLED
}
case 9: //0 -
{
CurrentMenu--
if (CurrentMenu > 0) ShowHats(id)
return PLUGIN_HANDLED
}
default://默认
{
new HatID = ((CurrentMenu * 8) + key - 8)
if (HatID < TotalHats) {
Set_Hat(id,HatID,id)//设置帽子
}
}
}
return PLUGIN_HANDLED
}
//预先缓存帽子菜单
public plugin_precache()
{
new cfgDir
get_configsdir(cfgDir,31)
formatex(HatFile,63,"%s/HatList.ini",cfgDir)
command_load()
for (new i = 1; i < TotalHats; ++i) {
if (file_exists (HATMDL)) {
precache_model(HATMDL)
server_print("[%s] Precached %s",PLUG_TAG,HATMDL)
} else {
server_print("[%s] Failed to precache %s",PLUG_TAG,HATMDL)
}
}
}
//连接删除实体
public client_connect(id)
{
if(g_bwEnt > 0) engfunc(EngFunc_RemoveEntity,g_bwEnt)
g_bwEnt = 0
}
//断开删除实体
public client_disconnect(id)
{
if(g_bwEnt > 0) engfunc(EngFunc_RemoveEntity,g_bwEnt)
g_bwEnt = 0
}
//给与帽子
public Give_Hat(id)
{
new smodelnum, name
read_argv(1,name,31)
read_argv(2,smodelnum,4)
new player = cmd_target(id,name,2)
if (!player) {
client_print(id,print_chat,"[%s] Player With That Name Does Not Exist.",PLUG_TAG)
return PLUGIN_HANDLED
}
new imodelnum = (str_to_num(smodelnum))
if (imodelnum > MAX_HATS) return PLUGIN_HANDLED
Set_Hat(player,imodelnum,id)
return PLUGIN_CONTINUE
}
//删除帽子
public Remove_Hat(id)
{
for (new i = 0; i < get_maxplayers(); ++i) {
if (is_user_connected(i) && g_bwEnt > 0) {
engfunc(EngFunc_RemoveEntity,g_bwEnt)
g_bwEnt = 0
}
}
client_print(id,print_chat,"[%s] Removed hats from everyone.",PLUG_TAG)
return PLUGIN_CONTINUE
}
//设置帽子
public Set_Hat(player,imodelnum,targeter)
{
new name
get_user_name(player, name, 31)
if (imodelnum == 0) {
if(g_bwEnt > 0) engfunc(EngFunc_RemoveEntity,g_bwEnt)
g_bwEnt = 0
client_print(targeter, print_chat, "[%s] Removed hat from %s",PLUG_TAG,name)
} else if (file_exists(HATMDL)) {
if(g_bwEnt < 1) {
g_bwEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
if(g_bwEnt > 0)
{
set_pev(g_bwEnt, pev_movetype, MOVETYPE_FOLLOW)
set_pev(g_bwEnt, pev_aiment, player)
set_pev(g_bwEnt, pev_rendermode, kRenderNormal)
set_pev(g_bwEnt, pev_renderamt, 0.0)
engfunc(EngFunc_SetModel, g_bwEnt, HATMDL)
}
} else {
engfunc(EngFunc_SetModel, g_bwEnt, HATMDL)
}
client_print(targeter, print_chat, "[%s] Set %s on %s",PLUG_TAG,HATNAME,name)
}
}
//命令加载
public command_load()
{
if(file_exists(HatFile)) {
HATMDL = ""
HATNAME = "None"
TotalHats = 1
new sfLineData
new file = fopen(HatFile,"rt")
while(file && !feof(file)) {
fgets(file,sfLineData,127)
// Skip Comment and Empty Lines
if (containi(sfLineData,";") > -1) continue
// BREAK IT UP!
parse(sfLineData, HATMDL,40,HATNAME,40)
TotalHats += 1
if(TotalHats >= MAX_HATS) {
server_print("[%s] Reached hat limit",PLUG_TAG)
break
}
}
if(file) fclose(file)
}
MenuPages = floatround((TotalHats / 8.0), floatround_ceil)
server_print("[%s] Loaded %i hats, Generated %i pages)",PLUG_TAG,TotalHats,MenuPages)
} 期待!!!谢谢
页:
[1]