AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Fire Entity Input (ent_fire alternative) (https://forums.alliedmods.net/showthread.php?t=261376)

SoulSharD 04-11-2015 10:53

[SNIPPET] Fire Entity Input (ent_fire alternative)
 
1 Attachment(s)
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!

DeathChaos25 04-13-2015 21:10

Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
 
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?

SoulSharD 04-14-2015 11:37

Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
 
Quote:

Originally Posted by DeathChaos25 (Post 2285935)
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.

Dr. Greg House 04-14-2015 19:22

Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
 
Please use:
RequestFrame
EntRefs
Kill, instead of RemoveEdict

Since you're already using outputs, just add the kill input to that.

Chdata 04-19-2015 02:26

Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
 
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;



SoulSharD 04-19-2015 06:31

Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
 
Pfft, I'm still learning.

Drixevel 04-25-2015 10:51

Re: [SNIPPET] Fire Entity Input (ent_fire alternative)
 
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);
        }
}



All times are GMT -4. The time now is 18:28.

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