Raised This Month: $ Target: $400
 0% 

[Ayuda] No me carga los NPC en su origen.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
UnrealT
Member
Join Date: Jul 2013
Old 07-15-2013 , 11:34   [Ayuda] No me carga los NPC en su origen.
#1

Hola, vengo a pedirles una mano y si puden ayudarme a corregirlo.
El problema es que al crear y guardar el npc y luego cuando cambio al mismo mapa donde lo guarde , no aparecen en su origin.
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(PLUGINVERSIONAUTHOR)
    
    
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(menuMPROP_EXITMEXIT_ALL); 
    
    
menu_display(idmenu); 


public 
Menu_Handler(idmenuitem
{  
    if(
item == MENU_EXIT
    { 
        
menu_destroy(menu); 
        return 
PLUGIN_HANDLED
    } 
    
    new 
info[6], szName[64]; 
    new 
accesscallback
    
    
menu_item_getinfo(menuitemaccessinfocharsmax(info), szNamecharsmax(szName), callback); 
    
    new 
key str_to_num(info); 
    
    switch(
key
    { 
        case 
1
        { 
            
CreateNpc(id); 
        } 
        case 
2
        { 
            new 
iEntbodyszClassname[32]; 
            
get_user_aiming(idiEntbody); 
            
            if (
is_valid_ent(iEnt))  
            { 
                
entity_get_string(iEntEV_SZ_classnameszClassnamecharsmax(szClassname)); 
                
                if (
equal(szClassnameNpcName))  
                { 
                    
remove_entity(iEnt); 
                } 
                
            } 
        } 
        case 
3
        {
            
SaveNpc(); 
            
            
client_print(idprint_chat"Guardado con exito."); 
        } 
        case 
4
        {
            
remove_entity_name(NpcName); 
            
            
client_print(idprint_chat"Todo los NPC removidos."); 
        }
        case 
5:
        {
            
LoadNpc()
        }
    } 

    
menu_display(idmenu); 

    return 
PLUGIN_HANDLED
}

CreateNpc(idFloat:flOrigin[3]= { 0.00.00.0 }, Float:flAngle[3]= { 0.00.00.0 } ) 
{
    new 
ent create_entity("info_target")
    
    
entity_set_string(entEV_SZ_classnameNpcName)
    
    
entity_get_vector(idEV_VEC_originflOrigin); 
        
    
entity_set_origin(entflOrigin); 
        
    
flOrigin[2] += 125.0
    
entity_set_origin(idflOrigin); 
        
    
entity_get_vector(idEV_VEC_anglesflAngle); 
        
    
flAngle[0] = 0.0
        
    
entity_set_vector(entEV_VEC_anglesflAngle); 
    
    
entity_set_float(entEV_FL_takedamage1.0)
    
entity_set_float(entEV_FL_health9999999999999999.0)
    
    
entity_set_model(entNpcModel)
    
    
entity_set_int(entEV_INT_solid2)
 
    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(entEV_FL_nextthinkhalflife_time() + 0.01)
}

public 
SaveNpc()
{
    new 
szConfigsDir[256], szFile[256], szNpcDir[256]
    
    
get_configsdir(szConfigsDircharsmax(szConfigsDir))
    
    new 
szMapName[32]
    
    
get_mapname(szMapNamecharsmax(szMapName))
    
    
formatex(szNpcDircharsmax(szNpcDir), "%s/NPC"szConfigsDir)
    
    
formatex(szFilecharsmax(szFile), "%s/%s.cfg"szNpcDirszMapName)
    
    if (
file_exists(szFile))
        
delete_file(szFile)
        
    new 
iEnt = -1Float:fEntOrigin[3], Float:fEntAngles[3]; 
    new 
sBuffer[256]
    
    while ( ( 
iEnt find_ent_by_class(iEntNpcName) ) ) 
    {
        
entity_get_vector(iEntEV_VEC_originfEntOrigin); 
        
entity_get_vector(iEntEV_VEC_anglesfEntAngles); 
        
        
formatexsBuffercharsmax(sBuffer), "%d | %d | %d | %d"floatround(fEntOrigin[0]), floatround(fEntOrigin[1]), floatround(fEntOrigin[2]), floatround(fEntAngles[1]) )
        
        
write_file(szFilesBuffer, -1)
    }
    
    
    return 
PLUGIN_HANDLED;
}

public 
LoadNpc()
{
    new 
szConfigDir[256], szFile[256], szNpcDir[256]; 
    
    
get_configsdir(szConfigDircharsmax(szConfigDir)); 
    
    new 
szMapName[32]; 
    
get_mapname(szMapNamecharsmax(szMapName)); 
    
    
formatex(szNpcDircharsmax(szNpcDir),"%s/NPC"szConfigDir); 
    
formatex(szFilecharsmax(szFile),  "%s/%s.cfg"szNpcDirszMapName); 
    
    
// 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 
iLineiLengthsBuffer[256]; 
    
    
// Cuando leemos el archivo... 
    
while(read_file(szFileiLine++, sBuffercharsmax(sBuffer), iLength)) 
    { 
        
// Ir a la siguiente línea si se comenta la línea
        
if((sBuffer[0]== ';') || !iLength
            continue; 
        
        
strtok(sBuffersOrigincharsmax(sOrigin), sAnglecharsmax(sAngle), '|'0); 
        
parse(sOriginszFileOrigin[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(0fOriginfAngles
        
    } 


Last edited by UnrealT; 07-15-2013 at 11:41.
UnrealT is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode