搜索
查看: 5484|回复: 18

求助,write_short函数使用方法(已解决)

[复制链接]
发表于 2009-9-10 04:51:42 | 显示全部楼层 |阅读模式 来自 日本
本帖最后由 cityhonghu 于 2009-10-4 12:03 编辑

这是死亡变红插件的代码,想知道其中的3行write_short部分是什么意思。
括号里的数字的取值范围和单位是多少。
谢谢

public death() {
    new id=read_data(2)
    message_begin(MSG_ONE,get_user_msgid("ScreenFade"),{0,0,0},id)
    write_short( 10<<12 ) // fade lasts this long duration
    write_short( 10<<16 ) // fade lasts this long hold time
    write_short( 1<<1 ) // fade type (in / out)
    write_byte( 255 ) // fade red
    write_byte( 0 ) // fade green
    write_byte( 0 ) // fade blue
    write_byte( 255 ) // fade alpha
    message_end()
    new deadname[33]
    get_user_name(id,deadname,32)
    set_hudmessage(255, 255, 255, -1.0, -1.0, 2, 0.2, 10.0, 0.1, 0.2, 2)
    show_hudmessage(id,"Thanks for trying %s, come again..", deadname)
    return PLUGIN_CONTINUE
}
发表于 2009-9-10 12:31:42 | 显示全部楼层 来自 福建漳州
write_short()后面只不过是跟了一个短整形数,10<<16与write_short无相关联系。为什么写的是这个数据,那得查看ScreenFade这个事件的定义了。
回复

使用道具 举报

 楼主| 发表于 2009-9-10 13:49:36 | 显示全部楼层 来自 日本
你来了,太好了。下面的代码是O3的闪光时间部分。默认是1.5秒,如果我想改为5秒或者其他任意时间,要如何改呢?
public Flash(id) {
        message_begin(MSG_ONE,gMsgScreenFade,{0,0,0},id)
        write_short( 1<<15 )
        write_short( 1<<10 )
        write_short( 1<<12 )
        write_byte( 255 )
        write_byte( 255 )
        write_byte( 255 )
        write_byte( 255 )
        message_end()
        emit_sound(id,CHAN_BODY, "weapons/flashbang-2.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH)
}

public plugin_init() {
   register_plugin("Admin Flash","1.0","AssKicR")
   register_concmd("amx_flash","admin_flash",ADMIN_LEVEL_A,"< Nick, UniqueID, #userid, @TEAM, or * > flashes selected client(s)")
   gMsgScreenFade = get_user_msgid("ScreenFade")
   return PLUGIN_CONTINUE
}
回复

使用道具 举报

发表于 2009-9-10 14:16:54 | 显示全部楼层 来自 台湾
http://wiki.amxmodx.org/index.ph ... e_Events#ScreenFade
看看這個吧
裡面有詳細說明用法
這個比較基礎一點
回复

使用道具 举报

 楼主| 发表于 2009-9-10 21:13:52 | 显示全部楼层 来自 日本
谢谢,楼上的。可惜我看不懂英文。:dizzy:
回复

使用道具 举报

发表于 2009-9-10 22:15:48 | 显示全部楼层 来自 台湾
看不懂英文 可以翻譯阿= =
回复

使用道具 举报

 楼主| 发表于 2009-9-10 22:51:22 | 显示全部楼层 来自 日本
本帖最后由 cityhonghu 于 2009-9-10 22:54 编辑

翻译了一下,但是不敢确定是否正确。
write_short( 1<<15 )   这是效果持续时间?
write_short( 1<<10 )   这是效果冻结时间?冻结是什么意思?
write_short( 1<<12 )   这是玩家标记?

Note: Duration and HoldTime is in special units. 1 second is equal to (1<<12) i.e. 4096 units.

这是说明部分,是在说持续时间和冻结时间是特别单位。(1<<12)为1秒,最大4096单位 ?

如果我想设置为5秒,这样设置是否正确呢?(修改了第一行的write_short)
  1. public Flash(id) {
  2.         message_begin(MSG_ONE,gMsgScreenFade,{0,0,0},id)
  3.         write_short( 1<<60 )   //此部分由15改为60
  4.         write_short( 1<<10 )
  5.         write_short( 1<<12 )
  6.         write_byte( 255 )
  7.         write_byte( 255 )
  8.         write_byte( 255 )
  9.         write_byte( 255 )
  10.         message_end()
  11.         emit_sound(id,CHAN_BODY, "weapons/flashbang-2.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH)
  12. }

  13. public plugin_init() {
  14.    register_plugin("Admin Flash","1.0","AssKicR")
  15.    register_concmd("amx_flash","admin_flash",ADMIN_LEVEL_A,"< Nick, UniqueID, #userid, @TEAM, or * > flashes selected client(s)")
  16.    gMsgScreenFade = get_user_msgid("ScreenFade")
  17.    return PLUGIN_CONTINUE
  18. }
复制代码
回复

使用道具 举报

发表于 2009-9-11 18:08:10 | 显示全部楼层 来自 北京海淀
我来给你解释一下吧,

  1. void Flashbang_ScreenFade(CBaseEntity *pEntity, const vec3_t &color, float fadeTime, float fadeHold, int alpha, int flags)
  2. {
  3.         MESSAGE_BEGIN(MSG_ONE, MSGID_ScreenFade, NULL, pEntity->pev());
  4.         WRITE_SHORT(UTIL_CLAMP_UNSIGNED_SHORT(int(fadeTime * (1<<12))));
  5.         WRITE_SHORT(UTIL_CLAMP_UNSIGNED_SHORT(int(fadeHold * (1<<12))));
  6.         WRITE_SHORT(flags);
  7.         WRITE_BYTE((int)color->x);
  8.         WRITE_BYTE((int)color->y);
  9.         WRITE_BYTE((int)color->z);
  10.         WRITE_BYTE(alpha);
  11.         MESSAGE_END();
  12. }
复制代码
第一个是fadetime是你从现在的状态进入你要设置的屏幕状态的时间
第二个是fadehold是你设置的屏幕状态持续的时间
flags有四种:
0-淡入
1-淡出
2-不混合(新的与上一个不叠加效果)
4-持续
short最大值为0xFFFF
回复

使用道具 举报

 楼主| 发表于 2009-9-11 18:35:11 | 显示全部楼层 来自 日本
本帖最后由 cityhonghu 于 2009-9-11 18:38 编辑

非常感谢jim_yang。
以下代码是不是可以实现,在15/12秒之后效果生效,其效果为淡出并叠加效果 ?
  1. public Flash(id) {
  2.         message_begin(MSG_ONE,gMsgScreenFade,{0,0,0},id)
  3.         write_short( 1<<15 )   
  4.         write_short( 1<<60 )
  5.         write_short( 1<<1 )
  6.         write_byte( 255 )
  7.         write_byte( 255 )
  8.         write_byte( 255 )
  9.         write_byte( 255 )
  10.         message_end()
  11.         emit_sound(id,CHAN_BODY, "weapons/flashbang-2.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH)
  12. }
复制代码
回复

使用道具 举报

发表于 2009-9-11 18:47:47 | 显示全部楼层 来自 北京海淀
12秒 12<<12
15秒 15<<12
回复

使用道具 举报

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

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