Exec Functions are functions that a player or user can execute by typing its name in the console. Basically, they provide a way to define new console commands in UnrealScript code.
exec function God() { if ( bGodMode ) { bGodMode = false; ClientMessage("God mode off"); return; } bGodMode = true; ClientMessage("God Mode on"); }
Eliot:theres a much easyer way to do this like this example.
exec function God() { bGodMode = !bGodMode; ClientMessage("GodMode:"@bGodMode); }
Passing Parameters
You can allow parameters for your console command by simply adding those parameters to the exec function's definition:
exec function Slap(string Player, int Strength) { Level.Game.Broadcast(None, Player @ "was slapped with strength" @ Strength); }
When entering this console command, separate the parameters with blanks (not commas). If the last function parameter is a string, it gobbles up everything that's remaining on the console command line.
(> Slap Mychaeel 1337 Mychaeel was slapped with strength 1337
You can make exec function parameters optional if you want.
Valid Places for Exec Functions
Exec functions can be declared anywhere, but they only actually work in the following objects:
(Note: this is only for UT2003/4, not UT or Unreal 1)
- the Console interaction
- the GameInfo actor (keep in mind that the GameInfo only exists on the server, though)
- the local player's HUD actor
- the local player's CheatManager (only offline)
- the local player's AdminManager (an AdminBase subclass, only when logged in as admin and only available on the serverside)
- the local PlayerController
- the local player's PlayerInput
- the local player's Pawn
- that Pawn's selected Weapon and SelectedItem (Inventory)
- in UT2004 also any local Interaction
You can not declare a working exec function in a mutator. You *can*, however, define the function Mutate(), which gets called from the console (see Mutator or Mutator (UT)).
Note that an exec function must be simulated to work client-side.
Related Topics
- GUIUserKeyBinding – adding your custom console commands to the game's Controls setup menu.
Discussion
unknown: I put a file in UT2004/System/ called 'mysummon.ini', and put:
exec function myGod() { bGodMode = !bGodMode; ClientMessage("GodMode:"@bGodMode); }
I startup UT2004 and type: > myGod
into the console...but it says "Command not found", or something like that :(
EntropicLqd: That's because an ini file is not a valid place for an exec function. Ini files cannot contain code. You would need to create your own class (see "valid places for an exec function" above).
orathaic Also note, bGodMode is a variable of the class controller, (and it's subclasses) This is the only variable which prevents death. So presumably you should access it with something like
MyController.bGodMode = !MyController.bGodMode
or access it from the controller itself.
XxDangerxX: In what classes must you declare an exec function in UT? Also, how do you 'activate' the actor that has the exec function so that you can type it in the console?
VerteX well, i subclassed CheatManager, hooked it up so it modifies PlayerController and sets the game's cheat manager to MyCheatManager, then i tried my cheat (a custom allweapons). No go.
XxDangerxX: I've put an exec function in an Inventory item I'm making. It works! Yay! One problem though - it will only work in the console, not the quick console. What might be the cause for this? This is for UT '99.