Autoexec.lua and Player_IsAlive function

I have started to utilize the autoexec.lua to monitor newly modded races (in this particular case the races’ resourcing) in realtime and the script that I am using (below) is working fine except that it also accounts for the CPU players that are not alive (have not been selected to play and are thus killed off at game start).

I have attempted to use:

if (Player_IsAlive(iPlayerIndex) == 1) then – (Don’t bother with dead players)

but I receive an error in hw2.log discounting the Player_IsAlive function as an unknown global.

Current working script:

function updateTimer()
    dr_clear("timer")
    dr_setautoclear("timer",0)
    local time = Universe_GameTime()
    local h = floor(time / 3600)
    local m = floor(time / 60 - h * 60)
    local s = floor(time - m * 60 - h * 3600)
    local str = format(" GameTime: %2.0f:%2.0f:%2.0f", h, m, s)
    dr_text2d("timer",0,0.98,str,255,255,255) -- 0.478,0.17,str,255,255,255)
    local rdy = 0
    local playerCount = Universe_PlayerCount()
    local playerIndex = 0
    local PlayerRUs = 0
    local me = FE_GetCurrentPlayerIndex()
    while (playerIndex < playerCount) do
        if (me>playerIndex or me<playerIndex) then  
            PlayerRUs = Player_GetRU(playerIndex)
            str = format(" CPU %1.0f: %2.0f", playerIndex, PlayerRUs)
            if (AreAllied(me, playerIndex)==1) then
                dr_text2d("timer", 0, 0.96 - (playerIndex/100), str, 255, 255, 150)
            end
            if (AreAllied(me, playerIndex)==0) then
                dr_text2d("timer", 0, 0.96 - (playerIndex/100), str, 255, 100, 50)
            end
        end
        playerIndex = playerIndex+1
    end
end

Rule_AddInterval("updateTimer", 9)

Can anyone tell me how I might declare the Player_IsAlive function as global for use in this fashion?

[edit]
The Player_IsAlive function is available only within the GameRule Scope.

Thank you shadowwinterknight for directing me toward this knowledge.
[/edit]

As well: I am interested in anyone’s input regarding the use of the autoexec.lua to monitor (in realtime) other functions and behaviors (i.e. building, research, etc.) of new races for mod testing/development.

Hello, anyone there?

Gosh, perhaps this forum is no longer active?

Haven’t modded hw for a long time now, so i could be wrong.
Not all globals work in all areas, for example, you arent able to read game options while a map is loading. This could be another case of that, where Player_IsAlive isnt available in the autoexec scripts.
There was a way to ‘dump’ all available globals, will try and find it…

1 Like

Are you referring to ThoughtDump.lua? Although I had read of its use, I have never taken the time to use it. Good suggestion! Thank you!

As an aside: I remember you. Was it from… RelicNews Forums?

Globals table of Autoexec.lua parsed:

globals = {
	function Camera_AltFocus(),
	function movieOutputDirectory(),
	function settagmethod(),
	_LuaConfig = "unknown type: userdata",
	SHIFTKEY = 16,
	INSERTKEY = 45,
	function ShowEngines(),
	Race_Vaygr = 2,
	MUI_TempWaypointCommand = 41,
	function random(),
	_LIBReg_luaappmisc = 1,
	function tremove(),
	eSubtitleOk = 18,
	_LIBReg_luagamesettings = 1,
	function Rule_AddInterval(),
	MINUSKEY = 189,
	function rawget(),
	function MainUI_PopEnabledCommandState(),
	INKE_KeyDown = 0,
	function ssSetMode(),
	function copytagmethods(),
	CONTROLKEY = 17,
	function _ALERT(),
	MUI_CaptureCommand = 37,
	F1KEY = 112,
	function setglobal(),
	function math_shl(),
	function Sound_Reload(),
	BACKSLASHKEY = 220,
	NINEKEY = 57,
	function math_shr(),
	NUMPLUSKEY = 107,
	function FE_NextTutorial(),
	eCameraDump = 75,
	function ShowUnitCaps(),
	function RenderShips(),
	function strlower(),
	ENDKEY = 35,
	function Camera_AltFocusWithVolume(),
	function AreAllied(),
	FIVEKEY = 53,
	function UI_DialogAccept(),
	function MainUI_PopAllEnabledCommandStates(),
	MUI_AttackCommand = 7,
	function tostring(),
	LKEY = 76,
	function Wait_Start(),
	function abs(),
	TO_RallyPointsSelected = 1024,
	eControlModifier = 25,
	NUMPADSLASH = 111,
	function maxActiveLights(),
	MUI_NextFocusCommand = 5,
	function SendCancelShipOrder(),
	function FE_SaveGameScreen_Campaign(),
	eResearchManager = 12,
	function showNISDebug(),
	function Wireframe(),
	function Profile_SetSingleMissionComplete(),
	function dr_text2d(),
	function FE_FocusOnLastEvent(),
	function SaveGame(),
	function Camera_ResetPanned(),
	PS_Left = 2,
	eSelectGroup = 23,
	ARRUP = 38,
	MUI_RepairCommand = 27,
	function Camera_ZoomClose(),
	eFocus = 13,
	F7KEY = 118,
	eSensorPing = 47,
	function settag(),
	function EventPointer_Remove(),
	MUI_FocusHomeCommand = 25,
	GR_CAMPAIGN = 1,
	function Camera_ResetFocused(),
	MUI_SensorsManagerToggleCommand = 22,
	PKEY = 80,
	function Enable_Pebble_Distribution(),
	BKEY = 66,
	function Profile_UnlockAll(),
	function ShowBackground(),
	function Sound_ToggleMusic(),
	function log10(),
	function rawsettable(),
	function max(),
	function Camera_FocusRestore(),
	function ClearSelectedFromControlGroups(),
	function UI_PlaySound(),
	eShiftModifier = 24,
	SEVENKEY = 55,
	function Universe_CurrentPlayer(),
	function Camera_FocusCancel(),
	function Profile_SetMissionsComplete(),
	function tan(),
	function GetShipId(),
	function ldexp(),
	LESSTHAN = 188,
	eRepair = 48,
	function FE_GetCurrentPlayerIndex(),
	function Rule_Exists(),
	TO_SphereModifiers = 1,
	function EventPointer_AddVolume(),
	MMOUSE_BUTTON = 4,
	function tinsert(),
	function setGoblinTol(),
	eWeaponLeft = 60,
	function FE_RestartGame(),
	PS_Down = 1,
	MUI_RetireCommand = 31,
	SPACEKEY = 32,
	function FE_TaskbarIgnoreProfilePhase(),
	function UI_SetElementPosition(),
	eFocusModifier = 26,
	PAUSEKEY = 19,
	function Volume_AddCube(),
	XKEY = 88,
	function _ERRORMESSAGE(),
	function UI_SetPreviousScreen(),
	APOSTROPHEKEY = 222,
	function print(),
	function UI_SetInterfaceVisible(),
	_LIBReg_LuaMenuSupport = 1,
	function gcinfo(),
	eNextTactic = 8,
	NUMSLASHKEY = 111,
	function exp(),
	function rad(),
	TILDEKEY = 192,
	function movieFileType(),
	TABKEY = 9,
	function GetVersionInfo(),
	SLASHKEY = 191,
	function RandomIntMax(),
	function rawsetglobal(),
	function GetReactiveFleetExtraRU(),
	function GetMultiplierForExtraShips(),
	function assert(),
	function UI_ReloadCurrentScreen(),
	function strbyte(),
	_LIBReg_debugrender = 1,
	gr_multiplayer = 4,
	function LoadRecordedGame(),
	F5KEY = 116,
	function UI_DialogAcceptID(),
	function dofilepath(),
	function GetResearchId(),
	MUI_CloakCommand = 36,
	function UI_ExitApp(),
	function deg(),
	_LIBReg_luauniverse = 1,
	gr_campaign = 2,
	function UI_PreviousScreen(),
	function strrep(),
	function leaveStrikeGroup(),
	PS_Up = 0,
	MUI_MoveAttackCommand = 33,
	function Universe_GetCurrentMoveHeight(),
	eNISTest = 57,
	function GetActualPlayerFleetExtraRU(),
	function GetReactiveFleetSizeInRU(),
	function SendBuildOrder(),
	function strchar(),
	F4KEY = 115,
	F12KEY = 123,
	function UI_FlashButton(),
	function UI_SetNextScreen(),
	eCapture = 70,
	function Universe_NebulaDelete(),
	_tagTable = {
		wchar_t = 6,
	},
	ESCKEY = 27,
	PAGEUPKEY = 33,
	function UI_DialogCancel(),
	function Universe_SlowDown(),
	IKEY = 73,
	YKEY = 89,
	function globals(),
	_LIBReg_luaplayer_console = 1,
	eQuickSave = 37,
	MUI_SelectGroupCommand = 11,
	function PixelWidth(),
	ePause = 44,
	eWaypoint = 27,
	MUI_FocusCommand = 4,
	F10KEY = 121,
	eLaunchManager = 20,
	eExit = 74,
	function Universe_EnableSkip(),
	eDropMinesInstant = 53,
	F9KEY = 120,
	MUI_MilitaryCommand = 34,
	_LIBReg_luagameio = 1,
	TO_DistantTOs = 4,
	function gettagmethod(),
	MUI_SetSelectionCommand = 12,
	function Profile_UnlockMovies(),
	function gamemisc_dumprules(),
	_LIBReg_luagamemisc = 1,
	THREEKEY = 51,
	function RandomRange(),
	function ssSetCompression(),
	function MainUI_PushEnabledCommandState(),
	ZKEY = 90,
	NUMDOTKEY = 110,
	_LIBReg_luaappmainui = 1,
	eCancelOrders = 2,
	function sharedVision(),
	function dofile(),
	TO_RallyPointsAll = 2048,
	PS_ModDown = 5,
	function FE_Retire(),
	MUI_HarvestCommand = 17,
	eHyperspace = 46,
	eWeaponNext = 59,
	function Rule_Add(),
	RBRACK = 221,
	function UI_SetElementSize(),
	MUI_TacticalOverlayToggleCommand = 13,
	function setMinLOD(),
	function UI_GetCurrentScreenID(),
	MUI_SpecialAttackCommand = 28,
	eGuard = 11,
	MUI_CreateGroupCommand = 10,
	function UI_PushState(),
	function foreachvar(),
	MUI_ParadeCommand = 16,
	function UI_HideScreen(),
	function LoadGame(),
	eCloak = 69,
	QKEY = 81,
	TO_OrderFeedbackMouseOver = 128,
	function GetActualPlayerFleetSizeInRU(),
	SCROLLKEY = 145,
	FLYWHEEL_UP = 3,
	eTactics = 45,
	function Pebble_Distribute(),
	gr_skirmish = 1,
	COMMA = 46,
	eRestartLevel = 41,
	function SelectBuildFacility(),
	BACKSPACEKEY = 8,
	function FE_SaveGameScreen(),
	eTurboEnable = 56,
	function ssTGA(),
	function mod(),
	function EventPointer_AddSubSystemFromSobGroup(),
	function setForcedLODLevel(),
	function SetStartFleetSuffix(),
	function Camera_AllowControl(),
	function Camera_FocusSobGroup(),
	function atan(),
	eDefenseField = 68,
	function cos(),
	function Universe_ClipToWorldBounds(),
	PI = 3.141592653589793,
	FLYWHEEL_DOWN = 5,
	function toggleGoblins(),
	MUI_DockCommand = 14,
	TO_Friendly = 8,
	function Universe_Pause(),
	eRetire = 52,
	PS_Right = 3,
	function breakAlliance(),
	function gsub(),
	function Camera_SetLetterboxStateNoUI(),
	function dostring(),
	function Scar_ReloadFile(),
	function format(),
	ePreviousFocus = 17,
	TO_NoATIAtAll = 64,
	function Camera_PlayerHasPanned(),
	FKEY = 70,
	eSuperTurbo = 67,
	TO_Enemy = 16,
	function foreachi(),
	function newtag(),
	LMOUSE_DOUBLE = 6,
	FOURKEY = 52,
	ePreviousTactic = 7,
	function GetMultiplierForExtraRU(),
	HOMEKEY = 36,
	function FE_LoadGameScreen_Campaign(),
	function Wait_End(),
	ENTERKEY = 13,
	function nextvar(),
	function goblinAlphaInterp(),
	GREATERTHAN = 190,
	function ShowInfo(),
	PAGEDOWNKEY = 34,
	function Universe_Fade(),
	TO_OrderFeedbackAlwaysOn = 512,
	function bind2(),
	function bind3(),
	eCancel = 1,
	function Universe_EnableCmd(),
	function UI_ShowDialog(),
	function ShowAIPaths(),
	function PixelHeight(),
	eSensorsManager = 31,
	function tonumber(),
	eFiltersToggle = 72,
	NUMPAD3 = 99,
	INKE_KeyRepeat = 2,
	NUMPAD5 = 101,
	NUMPAD0 = 96,
	NUMPAD2 = 98,
	NUMPAD1 = 97,
	function UI_IsScreenActive(),
	function formStrikeGroup(),
	NUMPAD8 = 104,
	NUMPAD7 = 103,
	NUMPAD9 = 105,
	MUI_PreviousFocusCommand = 6,
	function GetGameSettingAsString(),
	MUI_DropMinesCommand = 32,
	function type(),
	function proposeAlliance(),
	function getn(),
	function SaveRecordedGame(),
	function ShowShipDebug(),
	function MainUI_UserEventData2(),
	eScriptReload = 33,
	_LIBReg_luarender = 1,
	function UI_SubtitleWide(),
	GR_MULTIPLAYER = 3,
	function UI_GiveFocus(),
	function FE_ExitToWindows(),
	eWeaponCentre = 65,
	function log(),
	function error(),
	OKEY = 79,
	ARRDOWN = 40,
	MUI_ScuttleCommand = 40,
	function pause(),
	function Rule_Remove(),
	function ReloadBattleScarTextures(),
	ePopup = 0,
	function sin(),
	EKEY = 69,
	MUI_FocusModifierCommand = 20,
	function UI_ToggleScreenGameRubrick(),
	eGroup = 22,
	function Camera_GetLastZoomAmount(),
	function __Parse(),
	Race_Hiigaran = 1,
	function __Comma(),
	_LIBReg_luacamera = 1,
	eBuildManager = 19,
	function EnableBuildInBadges(),
	function SendPauseSubSystemOrder(),
	eQuickSaveDeterministic = 39,
	function GetGameRubric(),
	function ShowResourceDebug(),
	NUMPAD6 = 102,
	function RecordGame(),
	eShipScriptReload = 34,
	function UI_SubtitleNarrow(),
	function Universe_PlayerCount(),
	function UI_DialogCancelID(),
	function MainUI_UserEventData(),
	function MainUI_UserEvent(),
	function __Prefix(),
	H_KEY = 72,
	function Camera_FocusVolumeKeepingEyePosition(),
	eZoom = 29,
	function Camera_Interpolate(),
	MUI_ControlModifierCommand = 19,
	function Camera_GetDistanceToSobGroup(),
	MUI_DeployMinesCommand = 39,
	function UI_StopFlashButton(),
	eSwitchPlayer = 32,
	function Camera_UsePanning(),
	function sort(),
	function Camera_PlayerHasRotated(),
	gr_all = 7,
	function SendPauseShipOrder(),
	function Camera_UseCameraPoint(),
	TKEY = 84,
	function Camera_SetLetterboxState(),
	function Camera_FocusSave(),
	function UI_ClearEventScreen(),
	function Camera_FocusVolume(),
	eChat = 43,
	function Camera_FocusSobGroupWithBuffer(),
	eRallyPoint = 50,
	function ClearAllControlGroups(),
	function SelectNextIdleHarvester(),
	function Camera_PanCmd(),
	function LODFX_ForceFull(),
	function LOD_SetAllowGoblins(),
	function LOD_SetDesiredFPS(),
	TO_SelectionIcons = 2,
	function LOD_SetEnabled(),
	DKEY = 68,
	ALTKEY = 18,
	function ShowLevelVolumes(),
	function FE_ExitToMainMenu(),
	function RecorderFastForwardToggle(),
	function RecorderPauseUniverse(),
	VKEY = 86,
	ONEKEY = 49,
	function RecorderSwitchPlayer(),
	function Camera_ResetRotated(),
	eScreenShot = 42,
	function ssSetSuperSample(),
	function SendCancelSubSystemOrder(),
	function strsub(),
	function ClearTOSettings(),
	function SetTOSettings(),
	MUI_ZoomCommand = 21,
	function setAlliance(),
	CAPSLOCKKEY = 20,
	function debugRegionMode(),
	function EventPointer_AddSobGroup(),
	function ShowPathTolerance(),
	TWOKEY = 50,
	function statMonLog(),
	function statMon(),
	function getSyncCheckingLevel(),
	eRallyObject = 51,
	function Universe_AllowClicks(),
	MUI_DefenseFieldCommand = 35,
	function toggleEngineBurns(),
	function cameraCollision(),
	F2KEY = 113,
	function toggleNavLights(),
	function GetSubSystemId(),
	MUI_HyperspaceCommand = 26,
	function Scar_Reload(),
	PS_ModUp = 4,
	eWeaponUp = 63,
	function ShowWeaponDebug(),
	function typeid(),
	INKE_KeyUp = 1,
	function FOW_ForceUpdate(),
	eMoveAttack = 54,
	function call(),
	function Universe_IsPiePlateActive(),
	function ssJPG(),
	function Universe_AllowPlayerOrders(),
	eQuickLoad = 38,
	function ceil(),
	UKEY = 85,
	_LIBReg_luagamemainui = 1,
	function acos(),
	function Camera_PlayerHasFocused(),
	ARRRIGHT = 39,
	F3KEY = 114,
	eTempWaypoint = 73,
	function function_set_error(),
	eNextFocus = 16,
	function Universe_MoveRestrictToVolume(),
	eParade = 35,
	DELETEKEY = 46,
	function movieRecorderStart(),
	MUI_GuardCommand = 15,
	function next(),
	MUI_WaypointModeCommand = 2,
	TO_Resources = 32,
	ARRLEFT = 37,
	function UI_ReloadScreen(),
	ZEROKEY = 48,
	eFocusHome = 4,
	function FE_LoadGameScreen_RecordedGame(),
	function Player_GetRU(),
	eMenu = 21,
	function tag(),
	function screenshot(),
	WKEY = 87,
	function dr_clear(),
	eRenderToggle = 66,
	function GetFOWVis(),
	function UI_ToggleScreen(),
	LBRACK = 219,
	function Universe_AllowSelect(),
	function MainUI_DisableAllCommands(),
	function setOutOfSync(),
	eDock = 15,
	LMOUSE_BUTTON = 1,
	function UI_PopState(),
	function math_and(),
	eWaypointMode = 30,
	NUMMINUSKEY = 109,
	function UI_ToggleScreenElement(),
	function ascii(),
	function rawgettable(),
	function sqrt(),
	function UI_SetLabelTextHotkey(),
	function Volume_Delete(),
	function getglobal(),
	function UI_SetScreenVisible(),
	function strlen(),
	F8KEY = 119,
	function UI_SetElementEnabled(),
	eSpecialAttack = 49,
	TO_OrderFeedbackSelection = 256,
	eScuttle = 6,
	function frexp(),
	function rawset(),
	eDeployMines = 71,
	eHUD = 36,
	RMOUSE_DOUBLE = 7,
	function UI_NextScreen(),
	function foreach(),
	function movieRecorderStop(),
	function BreakAlliance(),
	eCancelGroup = 3,
	function movieOverExpose(),
	JKEY = 74,
	_LuaConfigName = "bin:autoexec.lua",
	NUMPAD4 = 100,
	function ssUI(),
	function FE_LoadGameScreen(),
	MKEY = 77,
	NUMSTARKEY = 106,
	function collectgarbage(),
	RETURNKEY = 13,
	eTransition = 1,
	eWeaponDown = 62,
	eMove = 9,
	SKEY = 83,
	eDelete = 28,
	function setForceLOD(),
	F11KEY = 122,
	function math_or(),
	NKEY = 78,
	_VERSION = "Lua 4.0",
	function UI_AddToEventScreen(),
	RMOUSE_BUTTON = 2,
	function MainUI_DisableCommand(),
	function bindup(),
	eFlightManeuverTest = 58,
	NUMLOCKKEY = 144,
	function Universe_GameTime(),
	function UI_SetButtonTextHotkey(),
	MUI_ShiftModifierCommand = 18,
	function UI_SetTextLabelText(),
	eWeaponsFire = 64,
	function GetGameSettingAsNumber(),
	function FOWVis(),
	function UI_StartGameWithSelectedLevel(),
	function strupper(),
	function UI_SetScreenEnabled(),
	function UI_SetInterfaceEnabled(),
	function asin(),
	function min(),
	function RenderEffects(),
	MUI_SetRallyPoint = 29,
	eSelectAllVisible = 14,
	function UI_ReloadAllScreens(),
	function dr_setdisplay(),
	function UI_GetScreenID(),
	RKEY = 82,
	F6KEY = 117,
	function UI_IsNamedElementVisible(),
	function Camera_FocusVolumeWithBuffer(),
	eWeaponRight = 61,
	DefensiveTactics = 1,
	PassiveTactics = 2,
	function UI_ShowScreen(),
	function strfind(),
	_LIBReg_luauserinterface = 1,
	MUI_CancelCommand = 0,
	GKEY = 71,
	MUI_DeleteCommand = 3,
	MUI_StopCommand = 9,
	function dr_setautoclear(),
	function persistentFeedback(),
	function floor(),
	GR_SKIRMISH = 2,
	MUI_OrderFeedbackCommand = 23,
	eMilitary = 55,
	CKEY = 67,
	function SaveDetGame(),
	function Sound_ToggleSpeech(),
	MUI_SelectAllVisibleCommand = 24,
	PLUSKEY = 187,
	EIGHTKEY = 56,
	MUI_MoveCommand = 8,
	MUI_SetRallyObject = 30,
	function UI_ScreenIsActive(),
	PRINTKEY = 42,
	MUI_SensorPingCommand = 38,
	MUI_WaypointCommand = 1,
	eQuickLoadDeterministic = 40,
	function atan2(),
	function Universe_SetAvoidance(),
	MMOUSE_DOUBLE = 248,
	SIXKEY = 54,
	function UI_SetButtonPressed(),
	function randomseed(),
	function EnableATIDisplay(),
	function setDetailLevel(),
	AggressiveTactics = 0,
	HKEY = 72,
	function SetAlliance(),
	function bind1(),
	function Preload_Ship(),
	KKEY = 75,
	AKEY = 65,
	function ssSetPosterRes(),
	function Volume_AddSphere(),
	function Universe_GetWorldBounds(),
	function rawgetglobal(),
	function UI_SetElementVisible(),
	function ShowBattleScar(),
	eTacticalOverlay = 5,
	function Camera_IsFocused(),
	eHarvest = 10,
}

Player_IsAlive does not exist here… but only in GameRule.

So I guess my question is answered.

Thank you Shadowwinterknight.

Yeah, ThoughtDump.lua is what I was thinking of.
I used to post a lot here a few years ago. Don’t think I ever posted on RelicNews Forums though.

Ah. It must have been here then. I do remember you being quite active. I have been modding HW2 since 2003, but have only just become active upon this (GBX) forum in the last few weeks.