XaNKoNII wrote:This does exactly what I was describing many thanks!
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
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.