Raised This Month: $51 Target: $400
 12% 

NPC cannot spawn when server start


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VINAGHOST
Member
Join Date: Aug 2016
Location: Việt Nam
Old 07-06-2017 , 01:22   NPC cannot spawn when server start
Reply With Quote #1

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 "."

This is my code ._.
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 
boolg_NpcSpawn[256];
new const 
NPC_IdleAnimations[] = { 131415161718 }; 

enum _:tem
{
    
ct,
    
t
}

new 
index[tem]
public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
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(menuMPROP_EXITMEXIT_ALL); 
    
    
menu_display(idmenu); 


public 
Menu_Handler(idmenuitem

    if(
item == MENU_EXIT
    { 
        
menu_destroy(menu); 
        return 
PLUGIN_HANDLED
    } 
    
    switch(
item
    { 
        case 
0
        { 
            new 
Float:origin[3];
            
entity_get_vector(idEV_VEC_originorigin);
            
Create_Npc(originct); 
        } 
        case 
1
        { 
            new 
Float:origin[3];
            
entity_get_vector(idEV_VEC_originorigin);
            
Create_Npc(origint); 
        } 
        case 
2
        { 
            
Save_Npc(); 
            
            
client_print(idprint_chat"[AMXX] NPC origin saved succesfully"); 
        } 
        case 
3
        { 
            
remove_entity_name(g_NpcCT); 
            
            
client_print(idprint_chat"[AMXX] NPC CT deleted"); 
        } 
        case 
4
        { 
            
remove_entity_name(g_NpcT); 
            
            
client_print(idprint_chat"[AMXX] NPC T deleted"); 
        } 
    } 
    
menu_display(idmenu); 
    
    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(iEntEV_SZ_classnameg_NpcCT); 
        
entity_set_model(iEntg_NpcModelCT); 
        
server_print("NPC: %d da duoc tao CT"iEnt)
    }
    else
    {
        
entity_set_string(iEntEV_SZ_classnameg_NpcT); 
        
entity_set_model(iEntg_NpcModelT);
        
server_print("NPC: %d da duoc tao T"iEnt)
    }
    
    
entity_set_origin(iEntOrigin); 
    
    
entity_set_int(iEntEV_INT_movetypeMOVETYPE_PUSHSTEP); 
    
entity_set_int(iEntEV_INT_solidSOLID_BBOX); 
    
    new 
Floatmins[3] = {-12.0, -12.00.0 
    new 
Floatmaxs[3] = { 12.012.075.0 
    
    
entity_set_size(iEntminsmaxs); 
    
    
entity_set_byte(iEnt,EV_BYTE_controller1,125); 
    
drop_to_floor(iEnt); 
    
    
g_NpcSpawn[iEnt] = true
    
server_print("NPC: %d da duoc tao %d"iEntg_NpcSpawn[iEnt] ? 0)
    
    
//entity_set_float(iEnt, EV_FL_nextthink, get_gametime() + 0.01) 
}
public 
Load_Npc() 

    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); 
    
    
//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 
iLineiLengthsBuffer[256]; 
    
    
//When we are reading our file... 
    
while(read_file(szFileiLine++, sBuffercharsmax(sBuffer), iLength)) 
    { 
        
//Move to next line if the line is commented 
        
if((sBuffer[0]== ';') || !iLength
        
        
parse(sBufferszFileOrigin[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 == ct)
        {
            
Create_NpcfOriginct)
            
server_print("CT")
        }
            
        else if (
iLine == t)
        {            
            
Create_NpcfOrigint)
            
server_print("T")
        }
    } 
}
public  
Save_Npc() 

    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]; 
    new 
sBuffer[256]; 
    
    
iEnt index[ct]
    
entity_get_vector(iEntEV_VEC_originfEntOrigin); 
    
formatex(sBuffercharsmax(sBuffer), "%d %d %d"floatround(fEntOrigin[0]), floatround(fEntOrigin[1]), floatround(fEntOrigin[2]) ); 
    
write_file(szFilesBuffer, -1);
    
    
iEnt index[t]
    
entity_get_vector(iEntEV_VEC_originfEntOrigin); 
    
formatex(sBuffercharsmax(sBuffer), "%d %d %d"floatround(fEntOrigin[0]), floatround(fEntOrigin[1]), floatround(fEntOrigin[2]) ); 
    
write_file(szFilesBuffer, -1);
    

Someone help me. And sorry for my bad english._.
VINAGHOST is offline
Reply



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 10:32.


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