回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
还有编译没提示错误,而运行则出现以上情况。我的SPR文件是绝对没问题的
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
用8返回+用9翻页就OK啦。。。回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
我真是佩服你啊,真的定义这么多菜单。。。。。。第一,第一,第二,第三个定义的菜单中,"\w0. EXIT" 没有换行符。
第二,你定义的第四页有点问题哦,你只有两个选择,所以,你大可不必用循环,而且你的热键定义的也有问题,应该是 keys = (1<<0|1<<9),再者你定义的第四页菜单命令中有三个case,但是你菜单只有两个选择。。。
编译的时候没有错误,是因为你语法上没有错误。
恩,你再仔细检查一下代码,看看前后时候符合!!
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
我素回答楼主D9楼滴。。。回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
这是我改进后的代码,我觉得用循环还不如用你之前说地那种,我到没觉得节约了好多代码。。。。#include <amxmod>
#define TE_PLAYERATTACHMENT 124
new boss
new byebye
new cold
new cool
new cry
new gogogo
new haixiu
new happy
new kiss
new koushui
new mad
new qiang
new sad
new se
new shangxiang
new shaxiao
new smile
new spiderman
new sure
new sweat
new wenhao
new wunai
new wuyu
new xieyan
new xinzui
new zhoumei
public plugin_init()
{
register_plugin("face show","0.3","")
register_clcmd( "amx_facemenu","FirstPageMenu",0)
register_menucmd(register_menuid("\wFirstPage"),1023,"FirstMenuCmd")
register_menucmd(register_menuid("\wSecondPage"),1023,"SecondMenuCmd")
register_menucmd(register_menuid("\wThirdPage"),1023,"ThirdMenuCmd")
register_menucmd(register_menuid("\wFourthPage"),1023,"FourthMenuCmd")
return PLUGIN_CONTINUE
}
public plugin_precache()
{
boss = precache_model("sprites/boss.spr")
byebye = precache_model("sprites/byebye.spr")
cold = precache_model("sprites/cold.spr")
cool = precache_model("sprites/cool.spr")
cry = precache_model("sprites/cry.spr")
gogogo = precache_model("sprites/gogogo.spr")
haixiu = precache_model("sprites/haixiu.spr")
happy = precache_model("sprites/happy.spr")
kiss = precache_model("sprites/kiss.spr")
koushui = precache_model("sprites/koushui.spr")
mad = precache_model("sprites/mad.spr")
qiang = precache_model("sprites/qiang.spr")
sad = precache_model("sprites/sad.spr")
se = precache_model("sprites/se.spr")
shangxiang = precache_model("sprites/shangxiang.spr")
shaxiao = precache_model("sprites/shaxiao.spr")
smile = precache_model("sprites/smile.spr")
spiderman = precache_model("sprites/spiderman.spr")
sure = precache_model("sprites/sure.spr")
sweat = precache_model("sprites/sweat.spr")
wenhao = precache_model("sprites/wenhao.spr")
wunai = precache_model("sprites/wunai.spr")
wuyu = precache_model("sprites/wuyu.spr")
xieyan = precache_model("sprites/xieyan.spr")
xinzui = precache_model("sprites/xinzui.spr")
zhoumei = precache_model("sprites/zhoumei.spr")
}
public cmdboss(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(boss)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdbyebye(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(byebye)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdcold(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(cold)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdcool(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(cool)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdcry(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(cry)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdgogogo(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(gogogo)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdhaixiu(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(haixiu)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdhappy(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(happy)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdkiss(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(kiss)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdkoushui(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(koushui)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdmad(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(mad)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdqiang(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(qiang)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdsad(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(sad)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdse(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(se)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdshangxiang(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(shangxiang)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdshaxiao(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(shaxiao)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdsmile(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(smile)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdspiderman(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(spiderman)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdsure(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(sure)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdsweat(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(sweat)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdwenhao(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(wenhao)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdwunai(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(wunai)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdwuyu(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(wuyu)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdxieyan(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(xieyan)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdxinzui(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(xinzui)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public cmdzhoumei(id)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(zhoumei)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
public FirstPageMenu( id )
{
new testMenu
new keys
new newLen = format(testMenu,1023,"\wFirstPage^n^n")
newLen += format( testMenu, 1023-newLen, "^n\w1. " )
newLen += format( testMenu, 1023-newLen, "^n\w2. byebye" )
newLen += format( testMenu, 1023-newLen, "^n\w3. cold" )
newLen += format( testMenu, 1023-newLen, "^n\w4. cool" )
newLen += format( testMenu, 1023-newLen, "^n\w5. 娴娉" )
newLen += format( testMenu, 1023-newLen, "^n\w6. GOGOGO" )
newLen += format( testMenu, 1023-newLen, "^n\w7. 瀹崇" )
newLen += format( testMenu, 1023-newLen, "^n\w8. 楂" )
newLen += format( testMenu, 1023-newLen, "^n^n\w9. NEXT" )
newLen += format( testMenu, 1023-newLen, "^n\w0. Exit" )
keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
show_menu(id,keys,testMenu,-1)
return PLUGIN_CONTINUE
}
public SecondPageMenu( id )
{
new testMenu
new keys
new newLen = format(testMenu,1023,"\wSecondPage^n^n")
newLen += format( testMenu, 1023-newLen, "^n\w1. KISS" )
newLen += format( testMenu, 1023-newLen, "^n\w2. f按" )
newLen += format( testMenu, 1023-newLen, "^n\w3. unhappy" )
newLen += format( testMenu, 1023-newLen, "^n\w4. qiang" )
newLen += format( testMenu, 1023-newLen, "^n\w5. 蹭激" )
newLen += format( testMenu, 1023-newLen, "^n\w6. 茬" )
newLen += format( testMenu, 1023-newLen, "^n\w7. 涓" )
newLen += format( testMenu, 1023-newLen, "^n\w8. 荤" )
newLen += format( testMenu, 1023-newLen, "^n^n\w9. NEXT" )
newLen += format( testMenu, 1023-newLen, "^n\w0. BACK" )
keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
show_menu(id,keys,testMenu,-1)
return PLUGIN_CONTINUE
}
public ThirdPageMenu( id )
{
new testMenu
new keys
new newLen = format(testMenu,1023,"\wThirdPage^n^n")
newLen += format( testMenu, 1023-newLen, "^n\w1. 寰绗" )
newLen += format( testMenu, 1023-newLen, "^n\w2. 渚" )
newLen += format( testMenu, 1023-newLen, "^n\w3. 姘" )
newLen += format( testMenu, 1023-newLen, "^n\w4. 姹姘" )
newLen += format( testMenu, 1023-newLen, "^n\w5. " )
newLen += format( testMenu, 1023-newLen, "^n\w6. 濂" )
newLen += format( testMenu, 1023-newLen, "^n\w7. 璇" )
newLen += format( testMenu, 1023-newLen, "^n\w8. " )
newLen += format( testMenu, 1023-newLen, "^n^n\w9. NEXT" )
newLen += format( testMenu, 1023-newLen, "^n\w0. BACK" )
keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
show_menu(id,keys,testMenu,-1)
return PLUGIN_CONTINUE
}
public FourthPageMenu( id )
{
new testMenu
new keys
new newLen = format(testMenu,1023,"\wFourthPage^n^n")
newLen += format( testMenu, 1023-newLen, "^n\w1. 蹇" )
newLen += format( testMenu, 1023-newLen, "^n\w2. 辩" )
newLen += format( testMenu, 1023-newLen, "^n^n\w0. BACK" )
keys = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
show_menu(id,keys,testMenu,-1)
return PLUGIN_CONTINUE
}
public FirstMenuCmd(id,key)
{
switch( key )
{
case 0: cmdboss(id)
case 1: cmdbyebye(id)
case 2: cmdcold(id)
case 3: cmdcool(id)
case 4: cmdcry(id)
case 5: cmdgogogo(id)
case 6: cmdhaixiu(id)
case 7: cmdhappy(id)
case 8: SecondPageMenu( id )
case 9: return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public SecondMenuCmd(id,key)
{
switch( key )
{
case 0: cmdkiss(id)
case 1: cmdkoushui(id)
case 2: cmdmad(id)
case 3: cmdqiang(id)
case 4: cmdsad(id)
case 5: cmdse(id)
case 6: cmdshangxiang(id)
case 7: cmdshaxiao(id)
case 8: ThirdPageMenu( id )
case 9: FirstPageMenu( id )
}
return PLUGIN_HANDLED
}
public ThirdMenuCmd(id,key)
{
switch( key )
{
case 0: cmdsmile(id)
case 1: cmdspiderman(id)
case 2: cmdsure(id)
case 3: cmdsweat(id)
case 4: cmdwenhao(id)
case 5: cmdwunai(id)
case 6: cmdwuyu(id)
case 7: cmdxieyan(id)
case 8: FourthPageMenu( id )
case 9: SecondPageMenu( id )
}
return PLUGIN_HANDLED
}
public FourthMenuCmd(id,key)
{
switch( key )
{
case 0: cmdxinzui(id)
case 1: cmdzhoumei(id)
case 9: ThirdPageMenu( id )
}
return PLUGIN_HANDLED
}
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
我对你无话可说了,你实在是厉害。不过,你这足有六百多行代码啊,我真是佩服你,好在CTRL+V可以复制,如果要手写,那还不累死了啊。
其实如果要用循环和变量来完成的话,估计也就一百多行代码。我正在调试中,遇到点问题,相信很快能解决!
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
晕了,每个菜单都定义。。。麻烦了,其实一个循环就把显示人的菜单都定义了。
还有相同的部分,单独做成函数,里面用到时就调用,这样代码会少很多的。
比如这个,
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(xieyan)
write_short(30)
message_end()
----------------------------
外面定义一个新函数,如showspr(id,sprname)---(玩家索引,和显示的spr)
这样你就只需要一段上面这样的,要用时,就这样
public cmd(id,sprname)
{
showspr(id,sprname)
}
这样响应菜单的部分只需要定义一个,显示spr的部分也只需要一个。
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
改了一下,spr只用了10个,有翻页,就算再多,也是有多少,增加多少行没有其他的文件(spr),运行的话,肯定会弹出警告窗口的,所有没有在cs里测试。ssj4gogeta 你试试吧。
另外,ssj4gogeta,你上面几楼的代码都没有考虑多人同时选择时的情况。
做惩罚插件时我也遇到这个问题,不知道需不需要考虑,而其他的很多插件是考虑了的,可想了好几次,还是
没想通。到现在也不大清楚,谁能解释解释??
是否需要定义为数组 如num ?不定义数组会出错的话,出错过程是怎么样的?
参看*** 号处。
#include <amxmod>
#define TE_PLAYERATTACHMENT 124
new num
new sprname[]={"boss","byebye","cold","cool","cry","gogogo","haixiu","happy","kiss","koushui"}
new page = {1,...}
new choices
new sprnum
public plugin_init()
{
register_plugin("showspr","0.1","Enigmaya")
register_clcmd( "amx_facemenu","showmenu",0)
register_menucmd(register_menuid("\wmenu"),1023,"menucmd")
return PLUGIN_CONTINUE
}
public plugin_precache()
{
num = precache_model("sprites/boss.spr")
num = precache_model("sprites/byebye.spr")
num = precache_model("sprites/cold.spr")
num = precache_model("sprites/cool.spr")
num = precache_model("sprites/cry.spr")
num = precache_model("sprites/gogogo.spr")
num = precache_model("sprites/haixiu.spr")
num = precache_model("sprites/happy.spr")
num = precache_model("sprites/kiss.spr")
num = precache_model("sprites/koushui.spr")
}
public showmenu(id)
{
for(new n=0;n<9;n++)
{
choices = ""
}
new menu
format(menu,128," which ?( Page %d ):^n^n",page)
new pagecount = 10-((page-1)*8)
if(10-((page-1)*8) > 2)
pagecount = 2
new offset = (page * 8) - 8
for(new i=offset;i<pagecount+offset;i++)
{
new string
format(string,255,"\w%d. %s ^n",i+1-offset,sprname)
add(menu,255,string)
}
if(10-((page-1)*8) > 8)
{
choices = "Next"
add(menu,255,"\w^n9. Next")
}
add(menu,255,"\w^n0. Back")
show_menu(id,(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),menu,-1)
return PLUGIN_CONTINUE
}
public menucmd(id,key)
{
if(key == 9 && page == 1)
{
page=1
return 1
}
else if(key == 9 && page > 1)
{
page -=1
showmenu(id)
return 1
}
if(key < 8)
{
sprnum=(page-1)*8+key //------------------------*********************
sprshow(id,sprnum)
return 1
}
if(key == 8 && equal(choices,"Next"))
{
page += 1
showmenu(id)
return 1
}
return 1
}
public sprshow(id,sprnum)
{
if(!is_user_alive(id))
{
set_hudmessage(200, 100, 0, -1.0, 0.3, 0, 1.0, 5.0, 0.1, 0.2, 3)
show_hudmessage(id,"Sorry,You Are Dead!!!")
return PLUGIN_HANDLED
}
message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
write_byte(TE_PLAYERATTACHMENT)
write_byte(id)
write_coord(40)
write_short(num)
write_short(30)
message_end()
return PLUGIN_HANDLED
}
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
楼上的不利于更新SPR可以用文件来保存SPR名称,那就要简单好多。
这样一来,更新方便,代码也少!
回复: 【原创】怎样使用循环语句来精简代码--表情插件多页菜单制作
稍稍改一下,增加几个宏定义,更新就只是增加模块定义和改宏定义而已。文件??读ini列表???嗯,那样设置确实方便。