Triggering Console Commands

Discussions about Coding and Scripting
Post Reply
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

Triggering Console Commands

Post by Peamole »

Does anyone know where I can find a custom-coded trigger that triggers the entering of console commands?

If not, can somebody please show me what the code for such an actor looks like. Maybe a ConsoleTrigger Actor that allows one to enter a console command in Actor Properties or change it in-game before it's triggered. Think of what can be made with this.

For example, in the Actor Properties for ConsoleTrigger there will be a category called ConsoleTrigger. In that category, there is a field called "Command". In that field you can type something like: KillAll Weapon—then you set the TriggerProperties stuff and it's done.

In-game you can type something like: Set ConsoleTrigger.ConsoleTrigger Command Exit :twisted:

For a single player game or MonsterHunt, a map maker can make the player say stuff using the triggerable Say command; while also setting off a TriggeredAmbientSound of a character voice (like an in-game-talking NaPali character).
Buggie
Godlike
Posts: 2751
Joined: Sat Mar 21, 2020 5:32 am

Re: Triggering Console Commands

Post by Buggie »

Look at ConsoleCommand call for each actor. Pay attention where command run (server or client). Also avoid run client input as command on server side. it is lead to exec vulnerability.
Also docs say ConsoleCommand fine work on any actor. It is not true.
Better run it on PlayerPawn object, or it able not work.
User avatar
Aspide
Skilled
Posts: 191
Joined: Wed Jun 09, 2021 12:13 am

Re: Triggering Console Commands

Post by Aspide »

ONP has an actor like this (however the only campaign that use it was Seven Bullets if I'm not mistaken), here is the code:

Code: Select all

// ============================================================
// This package is for use with the Partial Conversion, Operation: Na Pali, by Team Vortex.
// ConsoleCommandTrigger : I am very apprehensive about this, but nonetheless, here it is.
// Do NOT do something stupid!
// ============================================================

class ConsoleCommandTrigger expands Triggers;

var () string Command;  //the actual console command
var () bool MessageResult; //if the command returns something, should it be shown to client.  Note: only applies to native commands.

function Trigger( actor Other, pawn EventInstigator ){
  local string result;
  if (Command~="exit"||Command~="quit"||Command~="debug gpf"){
    result="Warning: map author is a moron!";
    MessageResult=true;
  }
  else
    result=EventInstigator.ConsoleCommand(Command);
  if (result==""||!MessageResult)
    return;
  if (Playerpawn(EventInstigator)!=none)
    EventInstigator.Clientmessage(result);
  else
    Broadcastmessage(result);
}
However I'm not sure if it works online.
Somewhere in Nevada...
User avatar
SteadZ
Average
Posts: 67
Joined: Mon Mar 10, 2014 11:19 pm
Personal rank: 1337
Location: Scotland
Contact:

Re: Triggering Console Commands

Post by SteadZ »

Legend Entertainment's Wheel of Time also contains such an actor, albeit in simpler form (and prettier - sorry UsAar33 :P )

Code: Select all

//=============================================================================
// CommandTrigger.uc
// $Author: Mfox $
// $Date: 1/06/00 2:42p $
// $Revision: 1 $
//=============================================================================
class CommandTrigger expands Trigger;

var() string CommandStr;

//=============================================================================

function Trigger( Actor Other, Pawn EventInstigator )
{
	if( PlayerPawn(EventInstigator) != None )
	{
		PlayerPawn(EventInstigator).ConsoleCommand( CommandStr );
	}
}

//=============================================================================

defaultproperties
{
     CommandStr="SHOWUBROWSER"
}
"The problem with dreams is... you never know when you're gonna wake up"

Image
User avatar
sektor2111
Godlike
Posts: 6413
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Triggering Console Commands

Post by sektor2111 »

Peamole wrote: Sun Feb 20, 2022 2:19 pm In that field you can type something like: KillAll Weapon—then you set the TriggerProperties stuff and it's done.
For this thing you don't need any console. You can check what command does and rewrite the thing elsewhere in a custom actor, it's not a Rocket Science. It's how I used RememberSpot and ShowPath. I wrote around 3+ mutators, using them as base for extra features (DM enemy tracker, CTFFlag tracker, MonsterHunt tester for Bot Objectives which I updated 2-3 times if I well recall). Command "Loaded" was already implemented elsewhere not as command, but codes from command. A console command for me is useful when UScript cannot do actions directly, and they aim native C++ functions from Engine/Core which cannot be recreated in UScript stage, such as "Exit" "Quit", etc.
See what KillAll does...

Code: Select all

exec function KillAll(class<actor> aClass)
{
	local Actor A;

	if( !bAdmin && (Level.Netmode != NM_Standalone) )
		return;
	ForEach AllActors(class 'Actor', A)
		if ( ClassIsChildOf(A.class, aClass) )
			A.Destroy();
}
Last three lines can be part of a trigger configurable with desired class for destruction. "KillAll" is a PlayerPawn command, if you want it elsewhere you need to Inject it in a new thing or else you can forget it.

Edit: PS - I wasn't really inspired too much in the past. I totally forgot to implement this sort of code for destroying Items and Monsters (and even paths) if game has been ended - TeamCannons are already doing this by themselves. I don't see any reason to run things after ending game. Perhaps it worth some testing in a generic ServerActor...
User avatar
Peamole
Average
Posts: 76
Joined: Tue Jan 05, 2021 5:12 pm
Personal rank: Dinghy-O-Death Cap'n
Location: Lost at Sea

Re: Triggering Console Commands

Post by Peamole »

Thanks a million, everyone! I'll play around with this now.
Post Reply