View Single Post
101
Member
Join Date: Nov 2023
Old 01-26-2024 , 09:23   Re: [l4d2] how to keep specific entity id when chapter changing
Reply With Quote #4

Quote:
Originally Posted by zonbarbar View Post

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"weapon_"false) != -1)
        
CreateTimer0.1 Timer_entity EntIndexToEntRef(entity) );
}

public 
Action:Timer_entity(Handle:timerany:entity)
{
    
entity EntRefToEntIndex(entity);
    
    if (!
IsValidEntity(entity)) return;        //it had been removed somehow
    
    /* The entiy Now Is Valid And it's name contains "weapon_"
    You Can Then Modify Any Weapon . For Example :
    If You Want To Replace All Medkits By pill bottles In L4d , See The Example Below :
    */    

Replace Entities :

PHP Code:
#include <sdktools>
#include <sdkhooks>

float Angles[3],Location[3];

public 
void OnEntityCreated(int entity, const char[] classname)        //This Requires sdkhooks
{
    if(
StrContains(classname"first_aid_kit"false) != -1)
    {
        
CreateTimer0.1 Timer_Replace_entity EntIndexToEntRef(entity) );
    }
}

public 
Action:Timer_Replace_entity(Handle:timer any:entity)
{
    
entity EntRefToEntIndex(entity);
    if (!
IsValidEntity(entity)) return;
    
    new 
entCreated CreateEntityByName("weapon_pain_pills");    //This Requires sdktools
    
    
if(entCreated != -1)    // This Is To Insure That the Entity Created Is Valid 
    
{
        
GetEntPropVector(entity Prop_Send "m_vecOrigin" Location);
        
GetEntPropVector(entity Prop_Send "m_angRotation" Angles);
        
        
/* You Should Take Care Of Angles ,
        Especially Those Who Are Located On Tables Or Cabinet*/
        
        
Angles[0]=0.0;
        
Angles[2]=0.0;
        
        
DispatchSpawn(entCreated);
        
TeleportEntity(entCreated Location Angles NULL_VECTOR);
        
SetEntityMoveType(entCreatedMOVETYPE_PUSH);
    }
    
AcceptEntityInput(entity,"Kill");

Another Method Of Saving References (Instead of Timers) , Which Is RequestFrame Function ,
And Here Is A Simple Example :

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"_rifle"false) != -1)
    {
        
RequestFrame(NextFrameCallback_Entity_Created EntIndexToEntRef(entity) )
    }
}

public 
void NextFrameCallback_Entity_Created(int entity)
{
    
entity EntRefToEntIndex(entity);
    
    if (!
IsValidEntity(entity)) return;        //it had been removed somehow
    
    // The entiy Now Is Valid And it's name contains : "_rifle"    

Another Method Of Saving References Which Is SDKHook ,

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrContains(classname"_any"false) != -1)
    {
        
SDKHook(entitySDKHook_SpawnPostOnEntityContains_anySpawnedCallBack); // This Will Save The Reference 
    
}
}

public 
OnEntityContains_anySpawnedCallBack(entityx)
{
    
//The entityx Is Valid And its Name Contains "_any"


Last edited by 101; 01-26-2024 at 10:38.
101 is offline