搜索
查看: 2696|回复: 4

插件中的这一句不明白,register_forward是干什么的

[复制链接]
发表于 2007-6-18 11:57:58 | 显示全部楼层 |阅读模式 来自 山东烟台
register_forward(FM_Touch, "forward_touch")
转发?
发表于 2007-6-18 12:26:13 | 显示全部楼层 来自 福建漳州

回复: 插件中的这一句不明白,register_forward是干什么的

forward在这个地方我也不知道怎么翻译比较好,有向前、转发的意思。这个函数的作用是注册一个forward,比如你说的例子,当发生Touch(接触)事件时,就会执行forward_touch函数。比如,你可以在此函数中,判断玩家是否接触到掉到地上的枪。
回复

使用道具 举报

发表于 2007-6-18 13:51:26 | 显示全部楼层 来自 广东潮州

回复: 插件中的这一句不明白,register_forward是干什么的

于fakemeta模块中,

其他的语言没学不清楚,不过在PAWN中,个人习惯理解为“转寄”;

具体意义在于:

某一个功能模块(HL引擎或其他mod dll中)“触发”(注意这里,此时功能模块“仍未”

按“原始”参数执行)时,把原功能函数的“原始”参数“转寄”到AMXX插件中你指定的

函数中(pass),此时你可以直接获取、更改(替换)某些参数,以达到你需要的结果,

当然也可利用来做你自己函数的触发“事件”。
回复

使用道具 举报

 楼主| 发表于 2007-6-18 14:30:45 | 显示全部楼层 来自 山东烟台

回复: 插件中的这一句不明白,register_forward是干什么的

public forward_touch(toucher, touched) {
        if (!g_weaponArena || toucher == 0 || touched == 0) //
                return FMRES_IGNORED

        entity_get_string(toucher, EV_SZ_classname, g_classnames[0], 14)
        entity_get_string(touched, EV_SZ_classname, g_classnames[1], 14)

        if (!equal(g_classnames[1], "player") || (!equal(g_classnames[0], "weaponbox") && !equal(g_classnames[0], "armoury_entity")))
                return FMRES_IGNORED

        entity_get_string(toucher, EV_SZ_model, g_model, 63) // models/w_ak47.mdl, check from [9]

        // You can touch my C4 any time ;-)
        if (equal(g_model, "models/w_backpack.mdl"))
                return FMRES_IGNORED

        // weapon_ak47
        new CsTeams:team = cs_get_user_team(touched)

        if (equal(g_model[9], g_weaponString[int:team][7], strlen(g_weaponString[int:team][7]))) {
                // If touching own team's weapon, ignore this = let player touch weapon
                return FMRES_IGNORED
        }
        else if (g_randomWeapon && get_cvar_num(CVAR_RANDOMTEAMSPECIFIC) && get_cvar_num(CVAR_STEALRANDOMWEAPON)) {
                new CsTeams:otherteam
                if (team == CS_TEAM_T)
                        otherteam = CS_TEAM_CT
                else
                        otherteam = CS_TEAM_T

                // If touching other team's weaponbox, and random mode is on and team specific weapons is on and you can steal the other team's weapon, ignore this = let player touch weapon
                // This means you can't pick up other team's weapon if it's on ground on map from start (ie, a armoury_entity)
                if (equal(g_classnames[0], "weaponbox") && equal(g_model[9], g_weaponString[int:otherteam][7], strlen(g_weaponString[int:otherteam][7]))) {
                        return FMRES_IGNORED
                }
        }

        //server_print("%s (%s/%d) BLOCKING touch of a %s (%d) strlen of current weapon from 7: %d", g_classnames[0], g_model,         toucher, g_classnames[1], touched,         strlen(g_weaponString[int:team][7]))

        // All else block touch!
        return FMRES_SUPERCEDE
}

日志中有以下错误记录
L 06/18/2007 - 11:31:48: Start of error session.
L 06/18/2007 - 11:31:48: Info (map "awp_map_32b") (logfile "error_061807.log")
L 06/18/2007 - 11:31:48: [ENGINE] Invalid entity 118
L 06/18/2007 - 11:31:48: [AMXX] Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:31:48: [AMXX] Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:31:48: [AMXX]    [0] weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:37:39: [ENGINE] Invalid entity 108
L 06/18/2007 - 11:37:39: [AMXX] Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:37:39: [AMXX] Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:37:39: [AMXX]    [0] weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:37:39: [ENGINE] Invalid entity 111
L 06/18/2007 - 11:37:39: [AMXX] Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:37:39: [AMXX] Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:37:39: [AMXX]    [0] weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:39:47: [ENGINE] Invalid entity 130
L 06/18/2007 - 11:39:47: [AMXX] Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:39:47: [AMXX] Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:39:47: [AMXX]    [0] weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:39:47: [ENGINE] Invalid entity 132
L 06/18/2007 - 11:39:47: [AMXX] Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:39:47: [AMXX] Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:39:47: [AMXX]    [0] weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:39:53: [ENGINE] Invalid entity 130

其实就是weaponarena.amxx武器竞技场
运行一段时间就出这个错误,时间再长点就出个hlds.exe,什么内存不能读,挂起死在那里。
版本1.9.7
回复

使用道具 举报

发表于 2007-6-18 18:03:53 | 显示全部楼层 来自 福建漳州

回复: 插件中的这一句不明白,register_forward是干什么的

在 entity_get_string(toucher, EV_SZ_classname, g_classnames[0], 14) 这句前面加个判断试试:
if(!is_valid_ent(toucher) || !is_valid_ent(touched) return FMRES_IGNORED

最好在 new CsTeams:team = cs_get_user_team(touched) 前面再加个判断:
if(!is_user_connected(touched)) return FMRES_IGNORED
回复

使用道具 举报

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

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