normen2 发表于 2007-6-18 11:57:58

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

register_forward(FM_Touch, "forward_touch")
转发?

Rulzy 发表于 2007-6-18 12:26:13

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

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

Ryu2877 发表于 2007-6-18 13:51:26

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

于fakemeta模块中,

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

具体意义在于:

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

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

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

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

normen2 发表于 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, 14)
        entity_get_string(touched, EV_SZ_classname, g_classnames, 14)

        if (!equal(g_classnames, "player") || (!equal(g_classnames, "weaponbox") && !equal(g_classnames, "armoury_entity")))
                return FMRES_IGNORED

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

        // 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, g_weaponString, strlen(g_weaponString))) {
                // 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, "weaponbox") && equal(g_model, g_weaponString, strlen(g_weaponString))) {
                        return FMRES_IGNORED
                }
        }

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

        // 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: Invalid entity 118
L 06/18/2007 - 11:31:48: Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:31:48: Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:31:48:     weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:37:39: Invalid entity 108
L 06/18/2007 - 11:37:39: Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:37:39: Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:37:39:     weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:37:39: Invalid entity 111
L 06/18/2007 - 11:37:39: Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:37:39: Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:37:39:     weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:39:47: Invalid entity 130
L 06/18/2007 - 11:39:47: Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:39:47: Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:39:47:     weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:39:47: Invalid entity 132
L 06/18/2007 - 11:39:47: Displaying debug trace (plugin "weaponarena.amxx")
L 06/18/2007 - 11:39:47: Run time error 10: native error (native "entity_get_string")
L 06/18/2007 - 11:39:47:     weaponarena.sma::forward_touch (line 2510)
L 06/18/2007 - 11:39:53: Invalid entity 130

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

Rulzy 发表于 2007-6-18 18:03:53

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

在 entity_get_string(toucher, EV_SZ_classname, g_classnames, 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
页: [1]
查看完整版本: 插件中的这一句不明白,register_forward是干什么的