Raised This Month: $ Target: $400
 0% 

[SNIPPET] Fire Entity Input (ent_fire alternative)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 04-19-2015 , 02:26   Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #1

PHP Code:
/**
 * Activates an entity (CBaseAnimating::Activate)
 *
 * @param entity        Entity index.
 * @noreturn
 * @error                Invalid entity or lack of mod support.
 */
native ActivateEntity(entity); 
Why do we need the info_target to animate?

Here's 2 old stocks I have and a rewrite of your thing.

PHP Code:
stock KillEntityIn(iEntFloat:flSeconds)
{
    
decl String:szAddOutput[32];
    
Format(szAddOutputsizeof(szAddOutput), "OnUser1 !self,Kill,,%0.2f,1"flSeconds);
    
SetVariantString(szAddOutput);
    
AcceptEntityInput(iEnt"AddOutput");
    
AcceptEntityInput(iEnt"FireUser1");
}

/*
    Fire entity input on an entity after a certain delay
*/
stock DelayEntityInput(iEnt, const String:szInput[], const Float:flSeconds, const String:szVariant[] = "")
{
    
decl String:szAddOutput[128];
    
Format(szAddOutputsizeof(szAddOutput), "OnUser1 !self,%s,%s,%0.2f,1"szInputszVariantflSeconds);
    
SetVariantString(szAddOutput);
    
AcceptEntityInput(iEnt"AddOutput");
    
AcceptEntityInput(iEnt"FireUser1");
}

stock FireEntityInput(const String:szTargetname[], const String:szInput[], const String:szParam[]="", const Float:flDelay=0.0)
{
    
decl String:szBuffer[255];
    
Format(szBuffersizeof(szBuffer), "OnUser1 %s:%s:%s:%0.2f:1"szTargetnameszInputszParamflDelay);

    static 
iSaveEnt EntIndexToEntRef(SpawnEntityByName("info_target"));
    
    new 
iEnt EntRefToEntIndex(iSaveEnt); // Dummy entity. (Pretty sure every Source game has this.)
    
if (iEnt == -|| !IsValidEntity(iEnt))
    {
        
iSaveEnt EntIndexToEntRef(SpawnEntityByName("info_target"));

        
iEnt EntRefToEntIndex(iSaveEnt);
        if (
iEnt == -|| !IsValidEntity(iEnt))
        {
            return 
false// Failed to recreate dummy entity
        
}
    }
    
    
SetVariantString(szBuffer);
    
AcceptEntityInput(iEnt"AddOutput");
    
AcceptEntityInput(iEnt"FireUser1");

    
//AcceptEntityInput(iEnt, "Kill");
    
    
return true;
}

stock SpawnEntityByName(const String:szClassname[], iForceEdictIndex = -1)
{
    new 
iEnt CreateEntityByName(szClassnameiForceEdictIndex);
    if (
iEnt != -1)
    {
        
DispatchSpawn(iEnt);
        
// ActivateEntity(iEnt);
    
}
    return 
iEnt;

__________________

Last edited by Chdata; 04-19-2015 at 02:30.
Chdata is offline
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 04-19-2015 , 06:31   Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #2

Pfft, I'm still learning.
__________________

SoulSharD is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 04-25-2015 , 10:51   Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #3

Code:
FireEntityInput(char[] strTargetname, char[] strInput, char[] strParameter = "", float flDelay = 0.0)
{
	char[256] strBuffer;
	Format(strBuffer, sizeof(strBuffer), "OnUser1 %s:%s:%s:%f:1", strTargetname, strInput, strParameter, flDelay);
	
	int entity = CreateEntityByName("info_target"); // Dummy entity. (Pretty sure every Source game has this.)

	if (IsValidEntity(entity))
	{
		DispatchSpawn(entity);
		ActivateEntity(entity);
		
		SetVariantString(strBuffer);
		AcceptEntityInput(entity, "AddOutput");
		AcceptEntityInput(entity, "FireUser1");
		
		RequestFrame(DeleteEntity, EntIndexToEntRef(entity)); // Remove on next frame.
		return true;
	}
	
	return false;
}

public void DeleteEntity(any data)
{
	int entity = EntRefToEntIndex(data);
	
	if (IsValidEntity(entity))
	{
		RemoveEdict(entity);
	}
}

Last edited by Drixevel; 04-25-2015 at 10:54.
Drixevel 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 18:28.


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