CommandEvent

Search, find and discuss about Mutators!
User avatar
PrinceOfFunky
Godlike
Posts: 1204
Joined: Mon Aug 31, 2015 10:31 pm

CommandEvent

Post by PrinceOfFunky »

A SpecialEvent that, when triggered, executes a command.
set bInstigatorContext to true if you want to execute the command in the context of the instigator instead of the SpecialEvent itself. Which means, if bInstigatorContext is set to false you cannot execute commands like "summon", since they need a player to be executed, but commands like "set" will always work since server actors can execute these commands, differently from a player, who needs to be admin, so if a non-admin player will trigger it when it has bInstigatorContext set to true and the command is a "summon" command, nothing will be summoned.
You do not have the required permissions to view the files attached to this post.
Last edited by PrinceOfFunky on Sun Oct 29, 2017 4:01 am, edited 1 time in total.
User avatar
XaNKoNII
Skilled
Posts: 217
Joined: Wed Jun 09, 2010 12:29 pm
Personal rank: Phenix
Location: Portugal

Re: CommandEvent

Post by XaNKoNII »

I´m sorry, I´m probably missing something super obvious but the file that comes with the map is .uc? tried to put it in the system folder but when i try playing the test map i get the message "missing package Comand Event"
User avatar
PrinceOfFunky
Godlike
Posts: 1204
Joined: Mon Aug 31, 2015 10:31 pm

Re: CommandEvent

Post by PrinceOfFunky »

XaNKoNII wrote:I´m sorry, I´m probably missing something super obvious but the file that comes with the map is .uc? tried to put it in the system folder but when i try playing the test map i get the message "missing package Comand Event"
Damn, you're right! That's the source code. I'll update the 7z file with the .u file inside.
EDIT: Updated. I placed map/source/u all together in the 7z.
User avatar
XaNKoNII
Skilled
Posts: 217
Joined: Wed Jun 09, 2010 12:29 pm
Personal rank: Phenix
Location: Portugal

Re: CommandEvent

Post by XaNKoNII »

This does exactly what I was describing many thanks! :highfive:

2 Questions:

1st- Do you mind if I use it Myleved in my Dimentions map (full credits provided of course)?

2nd- As someone that´s beggining to be ready to accept learning about coding, could you run me a super simple explanation on what you did here?
I only took C# in a few classes back in High school so I have minimal knowledge.I did quick look at the Unreal script... I guess what I dont understand are the entities (for lack of a better name) here

var() String command; - I´m guess this is the actuall mechanism for the comand
var() bool bInstigatorContext; - My guess here would be that this creates the option in the actor propreties window, but how does it actually make it be the instigator to do the action? is Instigator Context some variable that Unreal already has in it´s code?
function Trigger Well this with Super if and else is the final gear and what makes everything spin right?

Like the trigger checks the Instigator option, if true it makes the command work through the pawn that triggers it. If False then some other entity makes the command?

Sorry if i´m being annoying :what: :ironic2: but i´m actually curious
User avatar
PrinceOfFunky
Godlike
Posts: 1204
Joined: Mon Aug 31, 2015 10:31 pm

Re: CommandEvent

Post by PrinceOfFunky »

XaNKoNII wrote:This does exactly what I was describing many thanks! :highfive:

2 Questions:

1st- Do you mind if I use it Myleved in my Dimentions map (full credits provided of course)?

2nd- As someone that´s beggining to be ready to accept learning about coding, could you run me a super simple explanation on what you did here?
I only took C# in a few classes back in High school so I have minimal knowledge.I did quick look at the Unreal script... I guess what I dont understand are the entities (for lack of a better name) here

var() String command; - I´m guess this is the actuall mechanism for the comand
var() bool bInstigatorContext; - My guess here would be that this creates the option in the actor propreties window, but how does it actually make it be the instigator to do the action? is Instigator Context some variable that Unreal already has in it´s code?
function Trigger Well this with Super if and else is the final gear and what makes everything spin right?

Like the trigger checks the Instigator option, if true it makes the command work through the pawn that triggers it. If False then some other entity makes the command?

Sorry if i´m being annoying :what: :ironic2: but i´m actually curious
1. Of course, you can avoid typing my name if it's boring lol.
2. Mhm, important is the willing for knowledge, the more you know and practice the more you'll be able to code .o.
Let's see the class lol:

Code: Select all

class CommandEvent extends SpecialEvent;

var() String command;
var() bool bInstigatorContext; //If true, use instigator context instead than this SpecialEvent context.
	
function Trigger(Actor other, Pawn eventInstigator) {
	super.Trigger(other, eventInstigator);
	
	if (!bInstigatorContext)
		ConsoleCommand(command);
	else if (eventInstigator != None)
		eventInstigator.ConsoleCommand(command);
}
Simplest class ever I guess.
The "var" means variable so you were correct, "()" makes the variable visible in the actor properties panel(if you type a name inside the parenthesys this variable will be visible in a subsection)
"command" and "bInstigatorContext" are just variables I declared there, they didn't exist in the Actor class, we cannot re-declare variables if they were already declared in the same class or a parent class.

Code: Select all

function Trigger(Actor other, Pawn eventInstigator)
Function "Trigger()" is declared in the Actor class(Actor.uc). The parameters are the variables/values you got from who called Trigger()(it can be called from native code but like all other events can be called from other uc classes too). This declaration overwrites the function already written in the parent class(which in this case is SpecialEvent.uc), but I add this instruction:

Code: Select all

super.Trigger(other, eventInstigator);
"super.Trigger()" calls the same function from the parent class. Notice how SpecialEvent doesn't do it, since its parent is "Triggers.uc" which didn't need to do any action into Trigger() function and so it doesn't even have it in the class, same with Triggers.uc itself, since its parent class(Actor.uc) does no action in the Trigger function.
Of course I'm talking about .uc files, but events, like Trigger() declared in Actor.uc, are actually called by native code.
This is the Trigger() function in SpecialEvent.uc:

Code: Select all

function Trigger( actor Other, pawn EventInstigator )
{
	local pawn P;
	if( bBroadcast )
		BroadcastMessage(Message, true, 'CriticalEvent'); // Broadcast message to all players.
	else if( EventInstigator!=None && len(Message)!=0 )
	{
		// Send message to instigator only.
		EventInstigator.ClientMessage( Message );
	}
}
which sends the Message variable's value to the player. So in the end, all that super.Trigger() does in my class is that, allowing you to be able to keep using Trigger() functionality from SpecialEvent.uc.

About the body of Trigger():

Code: Select all

if (!bInstigatorContext)
		ConsoleCommand(command);
	else if (eventInstigator != None)
		eventInstigator.ConsoleCommand(command);
Some pieces are almost self-explanatory:

Code: Select all

if (bInstigatorContext is set to false)
	call ConsoleCommand() (which is a function declared in Actor.uc and written in native code) directly in the context of this actor(CommandEvent) using "command" variable's value as parameter;
else, if (EventInstigator (which is the pawn who triggered) is not None (since you can call this function giving None instead of a pawn, since there are some Trigger() functions which don't handle with the EventInstigator so it's ok if you use None instead, but this is not the case so we don't want it to be None))
	call ConsoleCommand() function in the context of EventInstigator using "command" variable's value as parameter;
That's it I guess, another thing is that in SpecialEvent.uc, as you can see above, there's this line:

Code: Select all

else if( EventInstigator!=None && len(Message)!=0 )
You can find the "EventInstigator != None" check even in my class, but I didn't put something like "Len(command) != 0" which means if there are more than 0 characters in the command string then it's ok, so I probably should have put it, Idk what happens if you try calling ConsoleCommand() giving it a string of 0 characters or just giving None instead of a string.
User avatar
XaNKoNII
Skilled
Posts: 217
Joined: Wed Jun 09, 2010 12:29 pm
Personal rank: Phenix
Location: Portugal

Re: CommandEvent

Post by XaNKoNII »

Thanks a lot, coding is something hard because at first glance is complicated, but if one doesn´t start to learn when he as little oportunities then he will never learn.
Before ending this post I want to ask you something more, the original file you mentioned it was the "compile"? like you uused an external language coding program and then you brought it to the unreal Script? (wich I assume is a slitghly modified coding language)
User avatar
PrinceOfFunky
Godlike
Posts: 1204
Joined: Mon Aug 31, 2015 10:31 pm

Re: CommandEvent

Post by PrinceOfFunky »

XaNKoNII wrote:Thanks a lot, coding is something hard because at first glance is complicated, but if one doesn´t start to learn when he as little oportunities then he will never learn.
Before ending this post I want to ask you something more, the original file you mentioned it was the "compile"? like you uused an external language coding program and then you brought it to the unreal Script? (wich I assume is a slitghly modified coding language)
Nothing is hard if you know you can do it.
I don't remember having talking about compiling, but well yes, you need a compiler for certain languages, every language needs to be understood by the machine using binary code, since it's not human readable we needed a language which would let us write logic in a human readable way, also we humans are able to synthesize, that's why we created compilers which converts your new language symbols etc into the "old" language, of course you need the "old" language to write a compiler which will convert the new one. These are called levels of abstraction of languages, UnrealScript(level 4/high level) is written in C(level3), which is written in Assembly(level 2), which is written in binary code(level 0/low level), the more you increase the abstraction, the more limited will be the new language(but it will be easier for us to write more complex logic, so limit is relative). NOTE that when you compile a new language, it will be convert into the lowest level, logically, if Assembly is converted in binary, then even C which is written in Assembly will be converted in binary and so on, UnrealScript is converted in binary when you compile it, not in C.
You could actually create a new compiler using UnrealScript which will compile a new language so that in the end you wouldn't need to use UnrealScript anymore, but UnrealScript was made very limited on purpose, its not worth to do it since the new language would be even more limited.
(Compilers as opposite to interpreters, which don't compile but convert in binary in real time. An example is Java, java code is initially compiled in bytecode(a language made on purpose for this) then when you run a jar(bytecode), Java will interpret it and covert it in binary in real time. Of course interpreters are slower than compilers, but they both have different pros and cos, just look them up on the internet)

You can use UCC to compile your unrealscript code, UCC.exe is usually located in the System folder, if you open it from command line using "ucc make" it will compile whatever you told it to compile in UnrealTournament.ini using "EditPackages=...", there must be a folder in the root directory tho, for example the folder CommandEvent, and in the ini you have to add "EditPackages=CommandEvent" under this section [Editor.EditorEngine]. Also the folder has to contain another folder called "Classes" which will contain your uc files. But read it all in the wiki if you're interested.