搜索
查看: 2466|回复: 3

插件运行错误求助

[复制链接]
发表于 2009-3-1 04:08:30 | 显示全部楼层 |阅读模式 来自 日本–东京都–千代田区
本帖最后由 cityhonghu 于 2009-3-1 04:11 编辑

在日志里显示如下错误信息。求助修改次插件,谢谢。
L 03/01/2009 - 05:00:58: [CSTRIKE] Player out of range (0)
L 03/01/2009 - 05:00:58: [AMXX] Displaying debug trace (plugin "hnsdm.amxx")
L 03/01/2009 - 05:00:58: [AMXX] Run time error 10: native error (native "cs_set_user_team")
L 03/01/2009 - 05:00:58: [AMXX]    [0] hnsdm.sma::eventDeathMsg (line 112)


插件源代码如下:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <hamsandwich>

new const g_Plugin[] = "HNS Deathmatch";
new const g_Version[] = "2.1";
new const g_Author[] = "Jon";

new g_CvarEnable;
new g_CvarGameName;
new g_CvarStabOnly;
new g_CvarRespawnDelay;
new g_CvarProtectionTime;
new g_CvarNoFlash;
new g_CvarHidersFlashbangs;
new g_CvarHidersSmokegrenade;
new g_CvarHidersHegrenade;
new g_CvarSeekersFlashbangs;
new g_CvarSeekersSmokegrenade;
new g_CvarSeekersHegrenade;
new g_MsgScreenFade;

new const g_BuyCommands[][] =
{
        "usp", "glock", "deagle", "p228", "elites",
        "fn57", "m3", "xm1014", "mp5", "tmp", "p90",
        "mac10", "ump45", "ak47", "galil", "famas",
        "sg552", "m4a1", "aug", "scout", "awp", "g3sg1",
        "sg550", "m249", "vest", "vesthelm", "flash",
        "hegren", "sgren", "defuser", "nvgs", "shield",
        "primammo", "secammo", "km45", "9x19mm", "nighthawk",
        "228compact", "fiveseven", "12gauge", "autoshotgun",
        "mp", "c90", "cv47", "defender", "clarion", "krieg552",
        "bullpup", "magnum", "d3au1", "krieg550"
}

new const g_EntityClassNames[][] =
{
        "func_breakable",
        "func_door_rotating",
        "func_door",
        "func_vip_safetyzone",
        "func_escapezone",
        "hostage_entity",
        "monster_scientist",
        "func_bomb_target",
        "info_bomb_target"
}

new bool:g_Joined[33];

public plugin_init()
{
        register_plugin(g_Plugin, g_Version, g_Author);
        register_cvar("hns_deathmatch_version", g_Version, FCVAR_SERVER);
       
        g_CvarEnable = register_cvar("hnsdm_enable", "1");
       
        if(!get_pcvar_num(g_CvarEnable))
                return;
       
        new gamename[32];
        formatex(gamename, 31, "%s %s", g_Plugin, g_Version);
       
        g_CvarGameName = register_cvar("hnsdm_gamename", gamename);
        g_CvarStabOnly = register_cvar("hnsdm_stabonly", "1");
        g_CvarRespawnDelay = register_cvar("hnsdm_respawndelay", "1.5");
        g_CvarProtectionTime = register_cvar("hnsdm_protectiontime", "5.0");
        g_CvarNoFlash = register_cvar("hnsdm_noflash", "1");
        g_CvarHidersFlashbangs = register_cvar("hnsdm_hiders_flashbangs", "1")
        g_CvarHidersSmokegrenade = register_cvar("hnsdm_hiders_smokegrenade", "1")
        g_CvarHidersHegrenade = register_cvar("hnsdm_hiders_hegrenade", "0")
        g_CvarSeekersFlashbangs = register_cvar("hnsdm_seekers_flashbangs", "0")
        g_CvarSeekersSmokegrenade = register_cvar("hnsdm_seekers_smokegrenade", "0")
        g_CvarSeekersHegrenade = register_cvar("hnsdm_seekers_hegrenade", "0")
        g_MsgScreenFade = get_user_msgid("ScreenFade");
       
        register_event("DeathMsg", "eventDeathMsg", "a");
        register_message(g_MsgScreenFade, "msgScreenFade");
       
        register_forward(FM_CmdStart, "fwdCmdStart");
        register_forward(FM_ClientKill, "fwdClientKill");
        register_forward(FM_GetGameDescription,"fwdGetGameDescription");
        register_forward(FM_PlayerPostThink, "fwdPlayerPostThink");
       
        RegisterHam(Ham_Spawn, "player", "eventPlayerSpawn", 1);

        register_clcmd("buy", "HandleBlock");
        register_clcmd("buyammo1", "HandleBlock");
        register_clcmd("buyammo2", "HandleBlock");
        register_clcmd("buyequip", "HandleBlock");
        register_clcmd("cl_autobuy", "HandleBlock");
        register_clcmd("cl_rebuy", "HandleBlock");
        register_clcmd("cl_setautobuy", "HandleBlock");
        register_clcmd("cl_setrebuy", "HandleBlock");
        register_clcmd("chooseteam", "HandleBlock");
        register_clcmd("say /respawn", "RespawnPlayer");
}

public plugin_precache() register_forward(FM_Spawn, "fwdSpawn");
 楼主| 发表于 2009-3-1 04:11:55 | 显示全部楼层 来自 日本–东京都–千代田区
后续代码为
       
public eventDeathMsg()
{
        new killer = read_data(1)
        new victim = read_data(2)
       
        if(killer == 0 && get_user_team(victim) == 1)
        {
                new lucky = GetRandomCT();
               
                cs_set_user_team(lucky, 1)
                client_print(lucky, print_chat, "[HNS] An idiot jumped off and you were lucky and got transfered to Terrorist.")
               
                cs_set_user_team(victim, 2);
               
                GiveItems(lucky)
                SetStealth(lucky)
        }
       
        else if(killer == victim)
        {
                set_task(get_pcvar_float(g_CvarRespawnDelay), "RespawnPlayer", victim)
               
                return PLUGIN_HANDLED;
        }
       
        else if(get_user_team(killer) == 2)        
        {
                cs_set_user_team(killer, 1);
                cs_set_user_team(victim, 2);
               
                GiveItems(killer)
                SetStealth(killer)
        }
                       
        set_task(get_pcvar_float(g_CvarRespawnDelay), "RespawnPlayer", victim)
       
        return PLUGIN_CONTINUE;
}

public eventPlayerSpawn(id)
{
        if(is_user_alive(id)) GiveItems(id);
}

public RespawnPlayer(id)
{
        if(!is_user_alive(id)) ExecuteHam(Ham_CS_RoundRespawn, id);       
}

public fwdCmdStart(id, handle, seed)
{
        if(!get_pcvar_num(g_CvarStabOnly) || !is_user_alive(id) || get_user_team(id) != 2) return FMRES_IGNORED;
               
        static clip, ammo;
       
        if(get_user_weapon(id, clip, ammo) != CSW_KNIFE) return FMRES_IGNORED;
               
        static button;
        button = get_uc(handle, UC_Buttons);
                                       
        if(button & IN_ATTACK) button = (button & ~IN_ATTACK) | IN_ATTACK2;
               
        set_uc(handle, UC_Buttons, button);
               
        return FMRES_SUPERCEDE;
}

public fwdPlayerPostThink(id)
{
        if(!g_Joined[id])
        {
                if(0 < get_user_team(id) < 3 && !is_user_alive(id))
                {
                        set_task(1.0, "RespawnPlayer", id)
                       
                        g_Joined[id] = true;
                }
        }
}

public fwdClientKill(id) return FMRES_SUPERCEDE;

public fwdSpawn(ent)
{
        if(!pev_valid(ent)) return FMRES_IGNORED;
       
        new class[32];
        pev(ent, pev_classname, class, 31);
       
        for(new i = 0; i < sizeof(g_EntityClassNames); i++)
        {
                if(equal(class, g_EntityClassNames))
                {
                        engfunc(EngFunc_RemoveEntity, ent);
                       
                        return FMRES_SUPERCEDE;
                }
        }
       
        return FMRES_IGNORED;
}

public fwdGetGameDescription()
{
        new gamename[32];
        get_pcvar_string(g_CvarGameName, gamename, 31)
       
        forward_return(FMV_STRING, gamename)
       
        return FMRES_SUPERCEDE;
}

public msgScreenFade(msgid, dest, id)
{
        if(is_user_alive(id) && get_pcvar_num(g_CvarNoFlash) == get_user_team(id))
        {
                static data[4];
                data[0] = get_msg_arg_int(4);
                data[1] = get_msg_arg_int(5)
                data[2] = get_msg_arg_int(6);
                data[3] = get_msg_arg_int(7)
                       
                if(data[0] == 255 && data[1] == 255 && data[2] == 255 && data[3] > 199) return PLUGIN_HANDLED;
        }
       
        return PLUGIN_CONTINUE;
}

public client_command(id)
{
        new sArg[13];
       
        if(read_argv(0, sArg, 12) > 11) return PLUGIN_CONTINUE;
       
        for(new i = 0; i < sizeof(g_BuyCommands); i++)
        {
                if(equali(g_BuyCommands, sArg, 0)) return PLUGIN_HANDLED;
        }
       
        return PLUGIN_CONTINUE;
}

public HandleBlock(id) return PLUGIN_HANDLED;
       
public UnsetStealth(id) fm_set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 255);

SetStealth(id)
{
        if(get_user_health(id) != 100)
                fm_set_user_health(id, 100)
               
        fm_set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderTransColor, 0);
        set_task(get_pcvar_float(g_CvarProtectionTime), "UnsetStealth", id)
}

GiveItems(id)
{       
        cs_reset_user_model(id)
        fm_strip_user_weapons(id)
       
        switch(get_user_team(id))
        {
                case 1:
                {       
                        if(get_pcvar_num(g_CvarHidersFlashbangs))
                        {
                                fm_give_item(id, "weapon_flashbang")
                                cs_set_user_bpammo(id, CSW_FLASHBANG, get_pcvar_num(g_CvarHidersFlashbangs))
                        }
                       
                        if(get_pcvar_num(g_CvarHidersSmokegrenade))
                                fm_give_item(id, "weapon_smokegrenade")
                               
                        if(get_pcvar_num(g_CvarHidersHegrenade))
                                fm_give_item(id, "weapon_hegrenade")
                }
               
                case 2:
                {
                        fm_give_item(id, "weapon_knife")
                               
                        if(get_pcvar_num(g_CvarSeekersFlashbangs))
                        {
                                fm_give_item(id, "weapon_flashbang")
                                cs_set_user_bpammo(id, CSW_FLASHBANG, get_pcvar_num(g_CvarSeekersFlashbangs))
                        }
                       
                        if(get_pcvar_num(g_CvarSeekersSmokegrenade))
                                fm_give_item(id, "weapon_smokegrenade")
                               
                        if(get_pcvar_num(g_CvarSeekersHegrenade))
                                fm_give_item(id, "weapon_hegrenade")
                }
        }
}

GetRandomCT()
{
        static iPlayers[32], iCT_num;
        get_players(iPlayers, iCT_num, "ae", "CT");
        
        if(!iCT_num)
                return 0;
        
        return iCT_num > 1 ? iPlayers[random(iCT_num)] : iPlayers[iCT_num - 1];
}

stock fm_set_user_godmode(index, godmode = 0)
{
        set_pev(index, pev_takedamage, godmode == 1 ? DAMAGE_NO : DAMAGE_AIM)

        return 1
}

stock fm_set_user_rendering(index, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
        return fm_set_rendering(index, fx, r, g, b, render, amount)
}

stock fm_strip_user_weapons(index)
{
        new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip"))
        if (!pev_valid(ent))
                return 0

        dllfunc(DLLFunc_Spawn, ent)
        dllfunc(DLLFunc_Use, ent, index)
        engfunc(EngFunc_RemoveEntity, ent)

        return 1
}

stock fm_give_item(index, const item[])
{
        if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))
                return 0

        new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item))
        if (!pev_valid(ent))
                return 0

        new Float:origin[3]
        pev(index, pev_origin, origin)
        set_pev(ent, pev_origin, origin)
        set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN)
        dllfunc(DLLFunc_Spawn, ent)

        new save = pev(ent, pev_solid)
        dllfunc(DLLFunc_Touch, ent, index)
        if (pev(ent, pev_solid) != save)
                return ent

        engfunc(EngFunc_RemoveEntity, ent)

        return -1
}

stock fm_set_rendering(entity, fx = kRenderFxNone, r = 255, g = 255, b = 255, render = kRenderNormal, amount = 16)
{
        new Float:RenderColor[3]
        RenderColor[0] = float(r)
        RenderColor[1] = float(g)
        RenderColor[2] = float(b)

        set_pev(entity, pev_renderfx, fx)
        set_pev(entity, pev_rendercolor, RenderColor)
        set_pev(entity, pev_rendermode, render)
        set_pev(entity, pev_renderamt, float(amount))

        return 1
}

stock fm_set_user_health(index, health)
{
        health > 0 ? set_pev(index, pev_health, float(health)) : dllfunc(DLLFunc_ClientKill, index)

        return 1
}
回复

使用道具 举报

发表于 2009-3-1 14:16:37 | 显示全部楼层 来自 中国–广东–惠州–惠城区
很常见的错误,执行cs_set_user_team函数之前没有判断玩家是否在线.加个is_user_connected(index)
回复

使用道具 举报

 楼主| 发表于 2009-3-1 19:04:12 | 显示全部楼层 来自 日本–东京都–千代田区
zwfgdlc ,谢谢。
回复

使用道具 举报

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

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