|
Member
|

07-15-2013
, 14:42
[Help] NPC no load in its origin
|
#1
|
Hi, I come to ask you a hand and help me correct it if puden.
The problem is that when you create and save the npc and then when you change the same map where you save it, do not appear on their origin.
Sorry my english is very bad
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
new const NpcName[] = "ZmNPC"
new const NpcModel[] = "models/player/zombie_source/zombie_source.mdl"
public plugin_precache()
{
precache_model(NpcModel)
}
public plugin_cfg()
{
LoadNpc()
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /npc", "Clcmd_NPC", ADMIN_IMMUNITY)
register_think(NpcName, "fw_Think")
}
public Clcmd_NPC(id)
{
new menu = menu_create("\y Menu NPC", "Menu_Handler");
menu_additem(menu, "Crear NPC", "1");
menu_additem(menu, "Borrar NPC", "2");
menu_additem(menu, "Guardar NPC", "3");
menu_additem(menu, "Borrar todos los NPC", "4");
menu_additem(menu, "Cargar NPC", "5")
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;
}
new info[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, info, charsmax(info), szName, charsmax(szName), callback);
new key = str_to_num(info);
switch(key)
{
case 1:
{
CreateNpc(id);
}
case 2:
{
new iEnt, body, szClassname[32];
get_user_aiming(id, iEnt, body);
if (is_valid_ent(iEnt))
{
entity_get_string(iEnt, EV_SZ_classname, szClassname, charsmax(szClassname));
if (equal(szClassname, NpcName))
{
remove_entity(iEnt);
}
}
}
case 3:
{
SaveNpc();
client_print(id, print_chat, "Guardado con exito.");
}
case 4:
{
remove_entity_name(NpcName);
client_print(id, print_chat, "Todo los NPC removidos.");
}
case 5:
{
LoadNpc()
}
}
menu_display(id, menu);
return PLUGIN_HANDLED;
}
CreateNpc(id, Float:flOrigin[3]= { 0.0, 0.0, 0.0 }, Float:flAngle[3]= { 0.0, 0.0, 0.0 } )
{
new ent = create_entity("info_target")
entity_set_string(ent, EV_SZ_classname, NpcName)
entity_get_vector(id, EV_VEC_origin, flOrigin);
entity_set_origin(ent, flOrigin);
flOrigin[2] += 125.0;
entity_set_origin(id, flOrigin);
entity_get_vector(id, EV_VEC_angles, flAngle);
flAngle[0] = 0.0;
entity_set_vector(ent, EV_VEC_angles, flAngle);
entity_set_float(ent, EV_FL_takedamage, 1.0)
entity_set_float(ent, EV_FL_health, 9999999999999999.0)
entity_set_model(ent, NpcModel)
entity_set_int(ent, EV_INT_solid, 2)
new Float:maxs[3] = {6.0,6.0,16.0}
new Float:mins[3] = {-6.0,-6.0,-16.0}
entity_set_size(ent,mins,maxs)
entity_set_float(ent,EV_FL_animtime,2.0)
entity_set_float(ent,EV_FL_framerate,1.0)
entity_set_int(ent,EV_INT_sequence,1);
drop_to_floor(ent)
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
return PLUGIN_HANDLED;
}
public fw_Think (ent)
{
entity_set_float(ent, EV_FL_nextthink, halflife_time() + 0.01)
}
public SaveNpc()
{
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], Float:fEntAngles[3];
new sBuffer[256]
while ( ( iEnt = find_ent_by_class(iEnt, NpcName) ) )
{
entity_get_vector(iEnt, EV_VEC_origin, fEntOrigin);
entity_get_vector(iEnt, EV_VEC_angles, fEntAngles);
formatex( sBuffer, charsmax(sBuffer), "%d | %d | %d | %d", floatround(fEntOrigin[0]), floatround(fEntOrigin[1]), floatround(fEntOrigin[2]), floatround(fEntAngles[1]) )
write_file(szFile, sBuffer, -1)
}
return PLUGIN_HANDLED;
}
public LoadNpc()
{
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);
// Si la ruta de acceso no existe, entonces vamos a hacer una
if(!dir_exists(szNpcDir))
{
mkdir(szNpcDir);
}
// Si el archivo de configuración de mapa no existe haremos una
if(!file_exists(szFile))
{
write_file(szFile, "");
}
// Variables para almacenar la lectura de un archivo
new szFileOrigin[3][32]
new sOrigin[128], sAngle[128];
new Float:fOrigin[3], Float:fAngles[3];
new iLine, iLength, sBuffer[256];
// Cuando leemos el archivo...
while(read_file(szFile, iLine++, sBuffer, charsmax(sBuffer), iLength))
{
// Ir a la siguiente línea si se comenta la línea
if((sBuffer[0]== ';') || !iLength)
continue;
strtok(sBuffer, sOrigin, charsmax(sOrigin), sAngle, charsmax(sAngle), '|', 0);
parse(sOrigin, 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]);
fAngles[1] = str_to_float(sAngle[1]);
CreateNpc(0, fOrigin, fAngles)
}
}
|
|