It doesn't work, I have another method that works fine, but I wanted to use spawn.
PHP Code:
new ent = -1
BreakableSpawn(ent);
And after that goes the code on BreakableSpawn and it works just fine, but I prefered to use Ham or Orpheu, but since Orpheu was already included it was good to use it rather than including more incs.
^^ You don't need Orpheu for this. If you look up the entity's spawn
code in the HL SDK first, it will give you clues as to what functions are called
when this entity is spawned. Ther are two simple ways (without orpheu):
1. Almost all entities in Half-Life call SetModel() from the spawn function.
Hook SetModel, look for the func_breakable classname, then get the
health of the object and set max health. OR
2. Hook KeyValue(), look for the func_breakable classname,
look for the health key and get it's value and set max health.
(the default health set for this entity in the FGD is 1 hp).
^^ You don't need Orpheu for this. If you look up the entity's spawn
code in the HL SDK first, it will give you clues as to what functions are called
when this entity is spawned. Ther are two simple ways (without orpheu):
1. Almost all entities in Half-Life call SetModel() from the spawn function.
Hook SetModel, look for the func_breakable classname, then get the
health of the object and set max health. OR
2. Hook KeyValue(), look for the func_breakable classname,
look for the health key and get it's value and set max health.
(the default health set for this entity in the FGD is 1 hp).
None of the above methods are working, but they do work on respawn. i beleive that the map entities are executed before any plug-in is loaded.
public pfn_keyvalue( id )
{
static szClassName[64], szKeyName[32], szValue[32];
copy_keyvalue( szClassName, charsmax(szClassName), szKeyName, charsmax(szKeyName), szValue, charsmax(szValue) );
if ( FClassnameIs( id, "func_breakable" ) || equal( szClassName, "func_breakable") )
{
if ( equal( szKeyName, "health") )
{
new Float:flHealth = str_to_float(szValue);
if ( flHealth > 0.0 )
{
entity_set_float( id, EV_FL_max_health, flHealth );
log_message( "[AMX] [SET BREAKABLE] pfn_keyvalue(): Setting max health for <func_breakable>, index: <%d>, Health: <%.2f>", id, flHealth );
}
// log_message( "[AMX] [SET BREAKABLE] pfn_keyvalue(): Got <func_breakable>, index: <%d>, Health: <%.2f>", id, flHealth );
}
}
return PLUGIN_CONTINUE;
}
stock bool:IsValidEnt( id )
{
if ( (id < 0) || (id > global_get( glb_maxEntities )) ) return false; // index out-of-bounds.
if ( id == 0 )
{ // Special handling for worldspawn entity:
if ( get_gametime() < 1.0 ) return false; // entity always valid after it has spawned.
return true;
}
if ( !pev_valid( id )) return false; // Do normal AMX validity checks after worldspawn check.
new iVal = entity_get_int( id, EV_INT_flags );
if ( iVal & FL_KILLME ) return false; // Flagged for death by engine.
return true;
}
stock FClassnameIs( id, const szClassName[] )
{
// Using this instead of fm_is_ent_classname( ), because that function uses pev_valid( )
// check which returns 0 (false) when worldspawn index ( 0 ) is input.
if ( !IsValidEnt( id ) ) return 0;
new szClass[64];
entity_get_string( id, EV_SZ_classname, szClass, charsmax(szClass) );
if ( equal( szClass, szClassName ) ) return 1;
return 0;
}
The SetModel() method (pre or post hooks), on the other hand, DOES NOT work
in AMX for map entities, only dynamically created in-game entities. This seems
to be yet another bug in AMX because I was able to hook this function easily
with a MetaMod plugin for all types of entities.
public pfn_keyvalue( id )
{
static szClassName[64], szKeyName[32], szValue[32];
copy_keyvalue( szClassName, charsmax(szClassName), szKeyName, charsmax(szKeyName), szValue, charsmax(szValue) );
if ( FClassnameIs( id, "func_breakable" ) || equal( szClassName, "func_breakable") )
{
if ( equal( szKeyName, "health") )
{
new Float:flHealth = str_to_float(szValue);
if ( flHealth > 0.0 )
{
entity_set_float( id, EV_FL_max_health, flHealth );
log_message( "[AMX] [SET BREAKABLE] pfn_keyvalue(): Setting max health for <func_breakable>, index: <%d>, Health: <%.2f>", id, flHealth );
}
// log_message( "[AMX] [SET BREAKABLE] pfn_keyvalue(): Got <func_breakable>, index: <%d>, Health: <%.2f>", id, flHealth );
}
}
return PLUGIN_CONTINUE;
}
stock bool:IsValidEnt( id )
{
if ( (id < 0) || (id > global_get( glb_maxEntities )) ) return false; // index out-of-bounds.
if ( id == 0 )
{ // Special handling for worldspawn entity:
if ( get_gametime() < 1.0 ) return false; // entity always valid after it has spawned.
return true;
}
if ( !pev_valid( id )) return false; // Do normal AMX validity checks after worldspawn check.
new iVal = entity_get_int( id, EV_INT_flags );
if ( iVal & FL_KILLME ) return false; // Flagged for death by engine.
return true;
}
stock FClassnameIs( id, const szClassName[] )
{
// Using this instead of fm_is_ent_classname( ), because that function uses pev_valid( )
// check which returns 0 (false) when worldspawn index ( 0 ) is input.
if ( !IsValidEnt( id ) ) return 0;
new szClass[64];
entity_get_string( id, EV_SZ_classname, szClass, charsmax(szClass) );
if ( equal( szClass, szClassName ) ) return 1;
return 0;
}
The SetModel() method (pre or post hooks), on the other hand, DOES NOT work
in AMX for map entities, only dynamically created in-game entities. This seems
to be yet another bug in AMX because I was able to hook this function easily
with a MetaMod plugin for all types of entities.
Ah, but you have used pfn_keyvalue, I tried it other way.
Anyways, I used Spawn on plugin_precache and that seemed to fix it.