Raised This Month: $51 Target: $400
 12% 

[SNIPPET] Fire Entity Input (ent_fire alternative)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 04-11-2015 , 10:53   [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #1

Hello,

I've started on some of my own mapping projects for Source, some of the functionality of these maps require SourceMod to trigger map entities, all of which is already possible to an extent.
SourceMod cannot trigger any non-networkable entities, these would be: logic_relay, logic_timer, etc...

Previously I've been using this plugin to enable use of ent_fire. This works perfectly, but has a few complications. (Resetting cvars, rcon access)

So here I am, sharing two things: a snippet and an example plugin.

PHP Code:
FireEntityInput(const String:strTargetname[], const String:strInput[], const String:strParameter[]="", const Float:flDelay=0.0)
{
    
decl String:strBuffer[255];
    
Format(strBuffersizeof(strBuffer), "OnUser1 %s:%s:%s:%f:1"strTargetnamestrInputstrParameterflDelay);
    
    new 
entity CreateEntityByName("info_target"); // Dummy entity. (Pretty sure every Source game has this.)
    
if(IsValidEdict(entity))
    {
        
DispatchSpawn(entity);
        
ActivateEntity(entity);
    
        
SetVariantString(strBuffer);
        
AcceptEntityInput(entity"AddOutput");
        
AcceptEntityInput(entity"FireUser1");
        
        
CreateTimer(0.0DeleteEdictentity); // Remove on next frame.
        
return true;
    }
    return 
false;
}

public 
Action:DeleteEdict(Handle:timerany:entity)
{
    if(
IsValidEdict(entity)) RemoveEdict(entity);
    return 
Plugin_Stop;

This function works by creating a dummy entity, and making it fire any input specified. The dummy entity is quickly removed afterwards.
Specifying a classname would trigger all entities with that classname. Non-networkable entities work too!

As for the plugin:
Usage: sm_entfire - Same functionality as ent_fire.

Enjoy!
Attached Files
File Type: sp Get Plugin or Get Source (sm_entfire.sp - 1077 views - 1.3 KB)
__________________

SoulSharD is offline
DeathChaos25
Senior Member
Join Date: Jan 2014
Location: Puerto Rico
Old 04-13-2015 , 21:10   Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #2

Ok, so, in L4D2, music is a client sided only entity, meaning it is not networked, would this in theory mean that if we know when a music starts we can, for example, cancel it?
__________________
DeathChaos25 is offline
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 04-14-2015 , 11:37   Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #3

Quote:
Originally Posted by DeathChaos25 View Post
Ok, so, in L4D2, music is a client sided only entity, meaning it is not networked, would this in theory mean that if we know when a music starts we can, for example, cancel it?
Correct.
Although you'll need to know the name of the entity that's playing the music.
__________________

SoulSharD is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-14-2015 , 19:22   Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
Reply With Quote #4

Please use:
RequestFrame
EntRefs
Kill, instead of RemoveEdict

Since you're already using outputs, just add the kill input to that.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 04-14-2015 at 19:25.
Dr. Greg House is offline
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 #5

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 #6

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 #7

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 07:04.


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