I want plugin that creat one NPC for each team. When I creat NPC by using menu that is OK. But when plugin load config to creat NPC that it didn't spawn. I have creat some server_print to check and i saw plugin already creat that NPC but I enter the server, I cannot see any NPC "."
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#define PLUGIN "NPC"
#define VERSION "1.0"
#define AUTHOR "VINAGHOST"
new const g_NpcCT[] = "ent_ct";
new const g_NpcModelCT[] = "models/npc_ct.mdl";
new const g_NpcT[] = "ent_ct";
new const g_NpcModelT[] = "models/npc_t.mdl";
new bool: g_NpcSpawn[256];
new const NPC_IdleAnimations[] = { 13, 14, 15, 16, 17, 18 };
enum _:tem
{
ct,
t
}
new index[tem]
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /npc", "ClCmd_NPC");
}
public plugin_precache()
{
precache_model(g_NpcModelCT)
precache_model(g_NpcModelT)
}
public plugin_cfg()
{
Load_Npc()
}
public ClCmd_NPC(id)
{
new menu = menu_create("NPC: Main Menu", "Menu_Handler");
menu_additem(menu, "Create NPC CT");
menu_additem(menu, "Create NPC T");
menu_additem(menu, "Save NPC");
menu_additem(menu, "Delete NPC CT");
menu_additem(menu, "Delete NPC T");
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu);
}
public Menu_Handler(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
switch(item)
{
case 0:
{
new Float:origin[3];
entity_get_vector(id, EV_VEC_origin, origin);
Create_Npc(origin, ct);
}
case 1:
{
new Float:origin[3];
entity_get_vector(id, EV_VEC_origin, origin);
Create_Npc(origin, t);
}
case 2:
{
Save_Npc();
client_print(id, print_chat, "[AMXX] NPC origin saved succesfully");
}
case 3:
{
remove_entity_name(g_NpcCT);
client_print(id, print_chat, "[AMXX] NPC CT deleted");
}
case 4:
{
remove_entity_name(g_NpcT);
client_print(id, print_chat, "[AMXX] NPC T deleted");
}
}
menu_display(id, menu);
return PLUGIN_HANDLED;
}
public Create_Npc(Float:Origin[3], team)
{
new iEnt = create_entity("info_target");
index[team] = iEnt
if (team == ct)
{
entity_set_string(iEnt, EV_SZ_classname, g_NpcCT);
entity_set_model(iEnt, g_NpcModelCT);
server_print("NPC: %d da duoc tao CT", iEnt)
}
else
{
entity_set_string(iEnt, EV_SZ_classname, g_NpcT);
entity_set_model(iEnt, g_NpcModelT);
server_print("NPC: %d da duoc tao T", iEnt)
}
entity_set_origin(iEnt, Origin);
entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_PUSHSTEP);
entity_set_int(iEnt, EV_INT_solid, SOLID_BBOX);
new Float: mins[3] = {-12.0, -12.0, 0.0 }
new Float: maxs[3] = { 12.0, 12.0, 75.0 }
entity_set_size(iEnt, mins, maxs);
entity_set_byte(iEnt,EV_BYTE_controller1,125);
drop_to_floor(iEnt);
g_NpcSpawn[iEnt] = true;
server_print("NPC: %d da duoc tao %d", iEnt, g_NpcSpawn[iEnt] ? 1 : 0)
//entity_set_float(iEnt, EV_FL_nextthink, get_gametime() + 0.01)
}
public Load_Npc()
{
new szConfigDir[256], szFile[256], szNpcDir[256];
get_configsdir(szConfigDir, charsmax(szConfigDir));
new szMapName[32];
get_mapname(szMapName, charsmax(szMapName));
formatex(szNpcDir, charsmax(szNpcDir),"%s/NPC", szConfigDir);
formatex(szFile, charsmax(szFile), "%s/%s.cfg", szNpcDir, szMapName);
//If the filepath does not exist then we will make one
if(!dir_exists(szNpcDir))
{
mkdir(szNpcDir);
}
//If the map config file does not exist we will make one
if(!file_exists(szFile))
{
write_file(szFile, "");
}
//Variables to store when reading our file
new szFileOrigin[3][32]
new Float:fOrigin[3]
new iLine, iLength, sBuffer[256];
//When we are reading our file...
while(read_file(szFile, iLine++, sBuffer, charsmax(sBuffer), iLength))
{
//Move to next line if the line is commented
if((sBuffer[0]== ';') || !iLength)
parse(sBuffer, szFileOrigin[0], charsmax(szFileOrigin[]), szFileOrigin[1], charsmax(szFileOrigin[]), szFileOrigin[2], charsmax(szFileOrigin[]));
fOrigin[0] = str_to_float(szFileOrigin[0]);
fOrigin[1] = str_to_float(szFileOrigin[1]);
fOrigin[2] = str_to_float(szFileOrigin[2]);
server_print("%d", iLine-1)
//Store the yawn angle
if (iLine - 1 == ct)
{
Create_Npc( fOrigin, ct)
server_print("CT")
}
else if (iLine - 1 == t)
{
Create_Npc( fOrigin, t)
server_print("T")
}
}
}
public Save_Npc()
{
new szConfigsDir[256], szFile[256], szNpcDir[256];
get_configsdir(szConfigsDir, charsmax(szConfigsDir));
new szMapName[32];
get_mapname(szMapName, charsmax(szMapName));
formatex(szNpcDir, charsmax(szNpcDir),"%s/NPC", szConfigsDir);
formatex(szFile, charsmax(szFile), "%s/%s.cfg", szNpcDir, szMapName);
if(file_exists(szFile))
delete_file(szFile);
new iEnt = -1, Float:fEntOrigin[3];
new sBuffer[256];
iEnt = index[ct]
entity_get_vector(iEnt, EV_VEC_origin, fEntOrigin);
formatex(sBuffer, charsmax(sBuffer), "%d %d %d", floatround(fEntOrigin[0]), floatround(fEntOrigin[1]), floatround(fEntOrigin[2]) );
write_file(szFile, sBuffer, -1);
iEnt = index[t]
entity_get_vector(iEnt, EV_VEC_origin, fEntOrigin);
formatex(sBuffer, charsmax(sBuffer), "%d %d %d", floatround(fEntOrigin[0]), floatround(fEntOrigin[1]), floatround(fEntOrigin[2]) );
write_file(szFile, sBuffer, -1);
}
Someone help me. And sorry for my bad english._.