I have some confuse about Engine vs Fakemeta on playing with origins on custom entity.
Here is the test code:
Spoiler
PHP Code:
#include < amxmodx >
#include < fakemeta >
#include < engine >
new Float:origin[ 3 ]
new const szClass[ ] = "custom"
new const szClass2[ ] = "custom2"
new const szModel[ ] = "models/w_m4a1.mdl"
new const szModel2[ ] = "models/w_ak47.mdl"
public plugin_precache()
{
precache_model( szModel )
precache_model( szModel2 )
}
public plugin_init()
{
register_clcmd( "cr_custom", "cr_custom" )
register_think( szClass, "custom_think" )
register_think( szClass2, "custom_think2" )
}
public cr_custom( id )
{
new iEnt = create_entity( "info_target" )
assert iEnt
entity_set_string( iEnt, EV_SZ_classname, szClass )
entity_get_vector( id, EV_VEC_origin, origin )
entity_set_origin( iEnt, origin )
entity_set_model( iEnt, szModel )
entity_set_float( iEnt, EV_FL_nextthink, get_gametime() + 0.1 )
iEnt = create_entity( "info_target" ) // create_entity best that EngFunc_CreateNamedEntity + AllocString
assert iEnt
set_pev( iEnt, pev_classname, szClass2 ) // Confuse for me: set_pev_string only for allocate string !?
pev( id, pev_origin, origin )
engfunc( EngFunc_SetOrigin, iEnt, origin )
engfunc( EngFunc_SetModel, iEnt, szModel2 )
set_pev( iEnt, pev_nextthink, get_gametime() + 0.1 )
}
public custom_think( iEnt )
{
if( is_valid_ent( iEnt ) )
{
entity_get_vector( iEnt, EV_VEC_origin, origin )
origin[ 2 ] += 5.0
entity_set_origin( iEnt, origin )
entity_set_float( iEnt, EV_FL_nextthink, get_gametime() + 0.1 )
}
}
public custom_think2( iEnt )
{
if( pev_valid( iEnt ) )
{
pev( iEnt, pev_origin, origin )
origin[ 2 ] += 5.0
engfunc( EngFunc_SetOrigin, iEnt, origin )
set_pev( iEnt, pev_nextthink, get_gametime() + 0.1 )
}
}
here is the profile test: (test during ~30 seconds)
not sure if test code is the best, but seem the fakemeta natives is a little fast that engine, like on natives:
pev_valid - is_valid_ent
EngFunc_SetOrigin - entity_set_origin
not sure if i have right, so wait to anybody clarify this confuse for me. What is best variant to use origins (get/set) on custom entity (who call very fast), engine or fakemeta ?