| Home Page | Recent Changes

Exec Function

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

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).


The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In