Raised This Month: $ Target: $400
 0% 

[SOLVED] Why doesn't this NPC Code works ?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
yan1255
Senior Member
Join Date: Jul 2011
Old 01-09-2015 , 11:57   [SOLVED] Why doesn't this NPC Code works ?
Reply With Quote #1

It creates an NPC but doesn't save it...
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < fakemeta >

#define MODEL         "models/player/vip/vip.mdl"    // Model

new const szPrefix[ ] = "AMXX";

new 
szFile256 ], entNPC;

public 
plugin_init()
{
    
register_plugin"NPC""1.0""Rejack" );
    
    
/* Loading NPC */
    
    
static szConfigsFolder32 ];
    
    
get_mapnameszFilecharsmaxszFile ) );
    
    
get_configsdirszConfigsFoldercharsmaxszConfigsFolder ) );
    
    
formatszFilecharsmaxszFile ), "%s/NPC/%s.coord"szConfigsFolderszFile );
    
    
set_task3.5"taskLoadNPC" );
    
    
register_concmd"create_npc""CmdCreateNPC"ADMIN_RCON"- Create an NPC" );
}

public 
plugin_precache()
    
precache_modelMODEL );
    
public 
taskLoadNPC()
    
CmdCreateNPC);

public 
CmdCreateNPCclient )
{
    static 
FloatiOrigin], FloatfAngles];
    
    if ( 
client )
    {
        
pevclientpev_originiOrigin );
        
        
pevclientpev_anglesfAngles );
    }
    
    else
    {
        static 
File;
        
        static 
fData][ 128 ];
        
        
File fopenszFile"r" );
        
        if ( 
File )    /* File Exists */
        
{
            static 
szData128 ], i0;
            
            while ( !
feofFile ) )
            {
                
fgetsFileszDatacharsmaxszData ) );
                
                if ( 
szData] == ';' || strlenszData ) < 10 )
                    continue;
                
                
remove_quotesszData );
                
                
replace_allszDatacharsmaxszData ), "#"" " );
                
                
parseszDatafData], 127fData], 127fData], 127fData], 127fData], 127fData], 127 );
                
                for ( 
06i++ )
                {
                    if ( 
)    // 1 - 3 = Origin
                        
iOrigini] = str_to_floatfData] );
                    
                    else if ( 
)
                        
fAngles] = str_to_floatfData] );
                }
                
                
create_npcclientfAnglesiOrigin );
            }
            
            
fcloseFile );
        }
        
        else    
/* File was not found */
        
{
            
log_amx"Error: Could not create an NPC." );
            
            
log_amx"Error: The file ^"%s^" was not found!"szFile );
            
            return 
1;
        }
    }
    
    
/* Save the NPC to the file */
    
    
if ( client )
    {
        static 
iFile;
        
        static 
szText128 ];
        
        
iFile fopenszFile"a" );
        
        if ( 
iFile )
        {
            
formatexszTextcharsmaxszText ), "^"%f#%f#%f#%f#%f#%f^"", iOrigin[ 0 ], iOrigin[ 1 ], iOrigin[ 2 ], fAngles[ 0 ], fAngles[ 1 ], fAngles[ 2 ] );
            
            
write_fileszFileszText, -);
            
            
fcloseiFile );
            
            
create_npcclientfAnglesiOrigin );
            
            
ColorPrintclient"You successfuly created an^3 NPC^1." );
        }
    }
    
    return 
FMRES_HANDLED;
}

/* Stocks */

stock ColorPrint( const index, const string[], any:... )
{
    new 
szMsg191 ], Players32 ], PNum 1;
    
    static 
iLeniLen formatexszMsgcharsmaxszMsg ), "^4[%s]^1 "szPrefix );
    
    
vformatszMsgiLen ], charsmaxszMsg ) - iLenstring);
    
    if ( 
index )
        
Players] = index;
    
    else
        
get_playersPlayersPNum"ch" );
    
    for ( new 
iPNumi++ )
    {
        if( 
is_user_connectedPlayers] ) )
        {
            
message_beginMSG_ONE_UNRELIABLEget_user_msgid"SayText" ), _Players] );
            
            
write_bytePlayers] );
            
            
write_stringszMsg );
            
            
message_end( );
        }
    }
    
    return 
1;
}

stock create_npc( const indexFloatfAngles], FloatiOrigin] )
{
    
/* Creating the NPC ent */
    
    
entNPC engfuncEngFunc_CreateNamedEntityengfuncEngFunc_AllocString"info_target" ) );
    
    
engfuncEngFunc_SetModelentNPCMODEL );
    
    
engfuncEngFunc_SetSizeentNPCFloat: { -17.0, -17.0, -36.0 }, Float: { 17.017.036.0 } );
    
    
fAngles] = 0.0;
    
    
set_peventNPCpev_anglesfAngles );
    
    
engfuncEngFunc_SetOriginentNPCiOrigin );
    
    if ( 
is_user_connectedindex ) )
    {
        
iOrigin] += 80;
        
        
engfuncEngFunc_SetOriginindexiOrigin );
    }
    
    
set_peventNPCpev_solidSOLID_BBOX );
    
    
set_peventNPCpev_classname"thenpc" );
    
    
/* Setting Default Animation */
    
    
set_peventNPCpev_animtime2.0 );
    
    
set_peventNPCpev_framerate1.0 );
    
    
set_peventNPCpev_sequence);
    
    
/* Setting bones positions */
    
    
set_peventNPCpev_controller_0125 );
    
    
set_peventNPCpev_controller_1125 );
    
    
set_peventNPCpev_controller_2125 );
    
    
set_peventNPCpev_controller_3125 );
    
    
/* Setting damage and HP */
    
    
set_peventNPCpev_takedamage0.0 );
    
    
/* Drop NPC to the ground */
    
    
engfuncEngFunc_DropToFloorentNPC );

__________________

Last edited by yan1255; 01-10-2015 at 19:47.
yan1255 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 15:23.


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