Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
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
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 01-09-2015 , 12:05   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #2

write_file( szFile, szText, -1 )
I am not in my computer to check, but i think that -1 is the lengh. So you must use charsmax(szText) instead of -1

write_file( szFile, szText, charsmax(szText) )
__________________

Last edited by Jhob94; 01-09-2015 at 12:06.
Jhob94 is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-09-2015 , 12:10   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #3

Quote:
Originally Posted by Jhob94 View Post
write_file( szFile, szText, -1 )
I am not in my computer to check, but i think that -1 is the lengh. So you must use charsmax(szText) instead of -1

write_file( szFile, szText, charsmax(szText) )
Its the line not the length it writes the origins and angles in the .coord file

Example:
Code:
"-1560.553588#-711.383544#164.031250#-2.969970#10.612792#0.000000"
"-1242.431884#-769.521423#164.031250#-8.798217#4.020996#0.000000"
"-1145.808715#-754.835815#199.739730#-3.116455#175.715332#0.000000"
__________________
yan1255 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 01-09-2015 , 12:14   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #4

And what's happening right now?
__________________
Jhob94 is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-09-2015 , 12:15   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #5

Quote:
Originally Posted by Jhob94 View Post
And what's happening right now?
As I said the NPCs are created when i type "npc_create" in the console, but when I restart the server the NPCs are not being created...
__________________
yan1255 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 01-09-2015 , 12:24   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #6

"It creates an NPC but doesn't save it..."
You didn't said anything about changemap.

/* Save the NPC to the file */

if ( client > 0 )

It must be:
/* Save the NPC to the file */

if ( client == 0 )
__________________
Jhob94 is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-09-2015 , 12:32   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #7

Quote:
Originally Posted by Jhob94 View Post
"It creates an NPC but doesn't save it..."
You didn't said anything about changemap.

/* Save the NPC to the file */

if ( client > 0 )

It must be:
/* Save the NPC to the file */

if ( client == 0 )
if client equals zero it means the client is the server...
in other words, it doesn't works.
and more now it doesn't create the NPCs anymore
__________________

Last edited by yan1255; 01-09-2015 at 12:44.
yan1255 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 01-09-2015 , 12:49   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #8

My bad, the code looks a mess.

if ( szData[ 0 ] == ';' || strlen( szData ) < 10 )
continue;

I guess that's the problem, szData is higher than 10
__________________
Jhob94 is offline
yan1255
Senior Member
Join Date: Jul 2011
Old 01-09-2015 , 12:55   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #9

Quote:
Originally Posted by Jhob94 View Post
My bad, the code looks a mess.

if ( szData[ 0 ] == ';' || strlen( szData ) < 10 )
continue;

I guess that's the problem, szData is higher than 10
If szData is higher than 10 that mean the code will go through...
__________________
yan1255 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 01-09-2015 , 12:58   Re: [HELP] Why doesn't this NPC Code works ?
Reply With Quote #10

No. It seems that you are working with copy/paste stuff. Why do you think that you check if data[0] = ;? Cuz it will not read that line if has an ; at start
__________________

Last edited by Jhob94; 01-09-2015 at 12:59.
Jhob94 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 06:49.


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