Napisałem plugin, który co jakiś czas spawnował by prezenty na mapie.
Teraz przy pojawianiu się prezentów jest błąd, który w trybie debug pisze:
] zp_present 3 L 04/12/2018 - 18:06:32: [FAKEMETA] Invalid entity L 04/12/2018 - 18:06:32: [AMXX] Displaying debug trace (plugin "zp_presents.amxx") L 04/12/2018 - 18:06:32: [AMXX] Run time error 10: native error (native "set_pev") L 04/12/2018 - 18:06:32: [AMXX] [0] zp_presents.sma::SpawnPresent (line 140) L 04/12/2018 - 18:06:32: [AMXX] [1] zp_presents.sma::SpawnPresents (line 111) L 04/12/2018 - 18:06:32: [AMXX] [2] zp_presents.sma::Cmd_SpawnPresents (line 98)
Poza tym zamiast kilku prezentów, serwer próbuje zespawnować tylko 1.
Gdzie tu jest błąd ?
Spoiler
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <zombieplague>
#include <ColorChat>
#define PRESENT_CLASSNAME "zp_gift"
#define SPAWNGIFT_TASK 7394207
public plugin_init()
{
register_plugin("[ZP] Presents", "1.0", "FastKilleR/DAMIAN");
register_touch(PRESENT_CLASSNAME, "player", "GivePresent");
register_clcmd("zp_present", "Cmd_SpawnPresents", ADMIN_RCON, "<ile> - Spawnuje prezent");
register_clcmd("zp_present_spawns", "Cmd_AddSpawn", ADMIN_RCON, "- Menu ze spawnami prezentow");
register_logevent("RoundStart", 2, "1=Round_Start");
register_logevent("RoundEnd", 2, "1=Round_End");
register_event("HLTV", "NewRound", "a", "1=0", "2=0");
}
public plugin_precache()
{
precache_model("models/zombie_plague/w_mega_present.mdl");
}
public RoundStart()
{
set_task(90.0, "Task_SpawnPresents", SPAWNGIFT_TASK, _, _, "b");
}
public Cmd_AddSpawn(id, level, cid)
{
if(!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
new menu = menu_create("\r[ZP] \ySpawny Prezentow^n", "Cmd_AddSpawn_Handle");
menu_additem(menu, "Dodaj Spawn^n^t\rZapisana zostanie obecna pozycja^n");
menu_additem(menu, "Usun wszystkie spawny z mapy");
menu_setprop(menu, MPROP_EXITNAME, "Wyjdz");
menu_display(id, menu);
return PLUGIN_CONTINUE;
}
public Cmd_AddSpawn_Handle(id, menu, item)
{
if(!is_user_connected(id))
return;
if(item == MENU_EXIT)
return;
switch(item)
{
case 0: AddSpawn(id);
case 1: RemoveSpawns(id);
}
}
public AddSpawn(id)
{
new Float:origin[3], szMap[64], szWrite[128], szFile[128];
pev(id, pev_origin, origin);
get_mapname(szMap, charsmax(szMap));
format(szWrite, charsmax(szWrite), "%f %f %f", origin[0], origin[1], origin[2]);
format(szFile, charsmax(szFile), "addons/amxmodx/configs/presents/%s.cfg", szMap);
write_file(szFile, szWrite, -1);
ColorChat(id, GREEN, "[ZP]^3 Spawn dodany.");
client_cmd(id, "zp_present_spawns");
}
public RemoveSpawns(id)
{
new szMap[64], szFile[128];
get_mapname(szMap, charsmax(szMap));
format(szFile, charsmax(szFile), "addons/amxmodx/configs/presents/%s.cfg", szMap);
delete_file(szFile);
ColorChat(id, GREEN, "[ZP]^3 Usunieto wszystkie spawny z tej mapy.");
}
public Cmd_SpawnPresents(id, level, cid)
{
if(!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED;
new szIle[3];
read_argv(1, szIle, charsmax(szIle));
new ile = str_to_num(szIle);
if(!ile)
return PLUGIN_HANDLED;
SpawnPresents(ile);
return PLUGIN_CONTINUE;
}
public Task_SpawnPresents()
{
SpawnPresents(10);
}
public SpawnPresents(ile)
{
for(new i=1; i<=ile; i++)
{
SpawnPresent();
}
}
public SpawnPresent()
{
new ent = engfunc(EngFunc_CreateEntity, PRESENT_CLASSNAME);
new szMap[64], szFile[128];
get_mapname(szMap, charsmax(szMap));
format(szFile, charsmax(szFile), "addons/amxmodx/configs/presents/%s.cfg", szMap);
new origins = file_size(szFile, 1);
new szLine[128], iLen;
read_file(szFile, random(origins), szLine, charsmax(szLine), iLen);
new origin_x[40], origin_y[40], origin_z[40];
parse(szLine, origin_x, charsmax(origin_x), origin_y, charsmax(origin_y), origin_z, charsmax(origin_z));
new Float:origin[3];
origin[0] = str_to_float(origin_x);
origin[1] = str_to_float(origin_y);
origin[2] = str_to_float(origin_z);
origin[2] += 30.0;
new Float:size_min[3] = { -4.0, -4.0, -4.0 }
new Float:size_max[3] = { 4.0, 4.0, 4.0 }
set_pev(ent, pev_origin, origin);
set_pev(ent, pev_classname, PRESENT_CLASSNAME);
set_pev(ent, pev_model, "models/zombie_plague/w_mega_present.mdl");
set_pev(ent, pev_size, size_min, size_max);
set_pev(ent, pev_body, random(5));
set_pev(ent, pev_skin, random(3));
set_pev(ent, pev_movetype, MOVETYPE_TOSS);
set_pev(ent, pev_solid, SOLID_TRIGGER);
fm_set_rendering(ent, kRenderFxGlowShell, random(256), random(256), random(256), kRenderNormal, 30);
engfunc(EngFunc_DropToFloor, ent);
}
public RoundEnd()
{
if(task_exists(SPAWNGIFT_TASK))
remove_task(SPAWNGIFT_TASK);
}
public NewRound()
{
fm_remove_entity_name(PRESENT_CLASSNAME);
}
public GivePresent(ent, id)
{
switch(random(3))
{
case 0:
{
new ap = random_num(5, 20);
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + ap);
ColorChat(id, GREEN, "[ZP]^3 Znalazles prezent, w ktorym bylo^4 %d Ammo Packow^3.", ap);
}
case 1:
{
new hp;
if(zp_get_user_zombie(id))
hp = random_num(200, 800);
else
hp = random_num(10, 30);
set_pev(id, pev_health, pev(id, pev_health) + hp);
ColorChat(id, GREEN, "[ZP]^3 Znalazles prezent, w ktorym bylo^4 %d HP^3.", hp);
}
case 2:
{
switch(random(3))
{
case 0:
{
fm_give_item(id, "weapon_hegrenade");
ColorChat(id, GREEN, "[ZP]^3 Znalazles prezent, w ktorym byl^4 Granat Podpalajacy^3.");
}
case 1:
{
fm_give_item(id, "weapon_flashbang");
ColorChat(id, GREEN, "[ZP]^3 Znalazles prezent, w ktorym byl^4 Granat Zamrazajacy^3.");
}
case 2:
{
fm_give_item(id, "weapon_smokegrenade");
ColorChat(id, GREEN, "[ZP]^3 Znalazles prezent, w ktorym byla^4 Flara^3.");
}
}
}
}
}


Dodatki SourceMod















