插件运行错误求助
本帖最后由 cityhonghu 于 2009-3-1 04:11 编辑在日志里显示如下错误信息。求助修改次插件,谢谢。
L 03/01/2009 - 05:00:58: Player out of range (0)
L 03/01/2009 - 05:00:58: Displaying debug trace (plugin "hnsdm.amxx")
L 03/01/2009 - 05:00:58: Run time error 10: native error (native "cs_set_user_team")
L 03/01/2009 - 05:00:58: 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;
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;
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"); 后续代码为
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, " 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)
{
if(0 < get_user_team(id) < 3 && !is_user_alive(id))
{
set_task(1.0, "RespawnPlayer", id)
g_Joined = true;
}
}
}
public fwdClientKill(id) return FMRES_SUPERCEDE;
public fwdSpawn(ent)
{
if(!pev_valid(ent)) return FMRES_IGNORED;
new class;
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;
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;
data = get_msg_arg_int(4);
data = get_msg_arg_int(5)
data = get_msg_arg_int(6);
data = get_msg_arg_int(7)
if(data == 255 && data == 255 && data == 255 && data > 199) return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public client_command(id)
{
new sArg;
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, iCT_num;
get_players(iPlayers, iCT_num, "ae", "CT");
if(!iCT_num)
return 0;
return iCT_num > 1 ? iPlayers : iPlayers;
}
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
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
RenderColor = float(r)
RenderColor = float(g)
RenderColor = 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
}
很常见的错误,执行cs_set_user_team函数之前没有判断玩家是否在线.加个is_user_connected(index) zwfgdlc ,谢谢。
页:
[1]