AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Why doesn't this NPC Code works ? (https://forums.alliedmods.net/showthread.php?t=255013)

yan1255 01-09-2015 11:57

[SOLVED] Why doesn't this NPC Code works ?
 
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 );



Jhob94 01-09-2015 12:05

Re: [HELP] Why doesn't this NPC Code works ?
 
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) )

yan1255 01-09-2015 12:10

Re: [HELP] Why doesn't this NPC Code works ?
 
Quote:

Originally Posted by Jhob94 (Post 2246960)
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"


Jhob94 01-09-2015 12:14

Re: [HELP] Why doesn't this NPC Code works ?
 
And what's happening right now?

yan1255 01-09-2015 12:15

Re: [HELP] Why doesn't this NPC Code works ?
 
Quote:

Originally Posted by Jhob94 (Post 2246963)
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...

Jhob94 01-09-2015 12:24

Re: [HELP] Why doesn't this NPC Code works ?
 
"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 )

yan1255 01-09-2015 12:32

Re: [HELP] Why doesn't this NPC Code works ?
 
Quote:

Originally Posted by Jhob94 (Post 2246968)
"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

Jhob94 01-09-2015 12:49

Re: [HELP] Why doesn't this NPC Code works ?
 
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

yan1255 01-09-2015 12:55

Re: [HELP] Why doesn't this NPC Code works ?
 
Quote:

Originally Posted by Jhob94 (Post 2246989)
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...

Jhob94 01-09-2015 12:58

Re: [HELP] Why doesn't this NPC Code works ?
 
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


All times are GMT -4. The time now is 15:23.

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