Skip to content

Commit

Permalink
Added new LUA command to get HUD screen name and updated HUD interfac…
Browse files Browse the repository at this point in the history
…e script

* Added new LUA command to get HUD screen name and updated HUD interface script
  • Loading branch information
LeeBamberTGC committed Dec 24, 2024
1 parent f97dbf1 commit deb84a5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7070,6 +7070,17 @@ int GetCurrentScreen(lua_State* L)
lua_pushnumber(L, t.game.activeStoryboardScreen);
return 1;
}
int GetCurrentScreenName(lua_State* L)
{
std::string check_lua_title = "";
if (t.game.activeStoryboardScreen >= 0)
{
check_lua_title = Storyboard.Nodes[t.game.activeStoryboardScreen].title;
}
lua_pushstring(L, check_lua_title.c_str());
return 1;
}

int GetScreenWidgetValue(lua_State *L)
{
float fRet = -99999.0;
Expand Down Expand Up @@ -12798,6 +12809,7 @@ void addFunctions()
lua_register(lua, "DisplayScreen", DisplayScreen);
lua_register(lua, "DisplayCurrentScreen", DisplayCurrentScreen);
lua_register(lua, "GetCurrentScreen", GetCurrentScreen);
lua_register(lua, "GetCurrentScreenName", GetCurrentScreenName);
lua_register(lua, "CheckScreenToggles", CheckScreenToggles);
lua_register(lua, "ScreenToggle", ScreenToggle);
lua_register(lua, "ScreenToggleByKey", ScreenToggleByKey);
Expand Down
1 change: 1 addition & 0 deletions Scripts/scriptbank/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,7 @@ GetTerrainCollisionDetails( objectId, num )
-- DisplayScreen : DisplayScreen
-- DisplayCurrentScreen : buttonid = DisplayCurrentScreen() -- returns the ID of any HUD button pressed that has the 'return button ID to LUA' set
-- GetCurrentScreen : GetCurrentScreen
-- GetCurrentScreenName : GetCurrentScreenName
-- CheckScreenToggles : CheckScreenToggles
-- ScreenToggle : ScreenToggle ( HUD Screen Name ) -- switch to the specified HUD screen
-- ScreenToggleByKey : ScreenToggleByKey ( HUD Screen Toggle Key ) -- switch to the specified HUD screen
Expand Down
141 changes: 85 additions & 56 deletions Scripts/scriptbank/huds/hud_interface.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Hud_Interface v6 by Necrym59
-- Hud_Interface v8 by Necrym59
-- DESCRIPTION: Will this will enable to use a hud screen as an interface for the attached object.
-- DESCRIPTION: Ensure your Hud Button names match the ones you put in here and are set to "return id to lua".
-- DESCRIPTION: Optionally reduce use range to 1 to allow HUD control anytime the specified HUD is visible.
-- DESCRIPTION: [USE_RANGE=80(1,100)]
-- DESCRIPTION: [USE_TEXT$="E to Use"]
-- DESCRIPTION: [HUD_SCREEN$="HUD Screen 9"]
-- DESCRIPTION: [HUD_BUTTON1$="Activate Links"]
-- DESCRIPTION: [@HUD_ACTION1=1(1=Activate Links,2=Play Audio,3=Destroy Object,4=Activate IfUsed,5=Exit Hud)]
-- DESCRIPTION: [HUD_ACTION1_TEXT$="Links Activated"]
-- DESCRIPTION: [HUD_BUTTON1$="Activate Link"]
-- DESCRIPTION: [@HUD_ACTION1=0(0=Link 0,1=Link 1,2=Link 2,3=Link 3,4=Link 4,5=Link 5,6=Link 6,7=Link 7,8=Link 8,9=Link 9,10=Play Audio,11=Destroy Object,12=Activate IfUsed,13=Exit Hud)]
-- DESCRIPTION: [HUD_ACTION1_TEXT$="Link Activated"]
-- DESCRIPTION: [HUD_BUTTON2$="Play Audio"]
-- DESCRIPTION: [@HUD_ACTION2=2(1=Activate Links,2=Play Audio,3=Destroy Object,4=Activate IfUsed,5=Exit Hud)]
-- DESCRIPTION: [@HUD_ACTION2=10(0=Link 0,1=Link 1,2=Link 2,3=Link 3,4=Link 4,5=Link 5,6=Link 6,7=Link 7,8=Link 8,9=Link 9,10=Play Audio,11=Destroy Object,12=Activate IfUsed,13=Exit Hud)]
-- DESCRIPTION: [HUD_ACTION2_TEXT$="Playing Audio"]
-- DESCRIPTION: [HUD_BUTTON3$="Destroy"]
-- DESCRIPTION: [@HUD_ACTION3=3(1=Activate Links,2=Play Audio,3=Destroy Object,4=Activate IfUsed,5=Exit Hud)]
-- DESCRIPTION: [@HUD_ACTION3=11(0=Link 0,1=Link 1,2=Link 2,3=Link 3,4=Link 4,5=Link 5,6=Link 6,7=Link 7,8=Link 8,9=Link 9,10=Play Audio,11=Destroy Object,12=Activate IfUsed,13=Exit Hud)]
-- DESCRIPTION: [HUD_ACTION3_TEXT$="Object Destroyed"]
-- DESCRIPTION: [HUD_BUTTON4$="Activate IfUsed"]
-- DESCRIPTION: [@HUD_ACTION4=4(1=Activate Links,2=Play Audio,3=Destroy Object,4=Activate IfUsed,5=Exit Hud)]
-- DESCRIPTION: [@HUD_ACTION4=12(0=Link 0,1=Link 1,2=Link 2,3=Link 3,4=Link 4,5=Link 5,6=Link 6,7=Link 7,8=Link 8,9=Link 9,10=Play Audio,11=Destroy Object,12=Activate IfUsed,13=Exit Hud)]
-- DESCRIPTION: [HUD_ACTION4_TEXT$="Activating"]
-- DESCRIPTION: [HUD_BUTTON5$="Exit"]
-- DESCRIPTION: [@HUD_ACTION5=5(1=Activate Links,2=Play Audio,3=Destroy Object,4=Activate IfUsed,5=Exit Hud)]
-- DESCRIPTION: [@HUD_ACTION5=13(0=Link 0,1=Link 1,2=Link 2,3=Link 3,4=Link 4,5=Link 5,6=Link 6,7=Link 7,8=Link 8,9=Link 9,10=Play Audio,11=Destroy Object,12=Activate IfUsed,13=Exit Hud)]
-- DESCRIPTION: [HUD_ACTION5_TEXT$="Exiting"]
-- DESCRIPTION: <Sound0> Interface activation
-- DESCRIPTION: <Sound1> Audiofile sound
Expand All @@ -42,10 +43,10 @@ local hud_action4_text = {}
local hud_button5 = {}
local hud_action5 = {}
local hud_action5_text = {}

local status = {}
local pressed = {}
local actioned = {}
local current_link = {}
local playonce = {}

function hud_interface_properties(e, use_range, use_text, hud_screen, hud_button1, hud_action1, hud_action1_text, hud_button2, hud_action2, hud_action2_text, hud_button3, hud_action3, hud_action3_text, hud_button4, hud_action4, hud_action4_text, hud_button5, hud_action5, hud_action5_text)
Expand All @@ -54,7 +55,7 @@ function hud_interface_properties(e, use_range, use_text, hud_screen, hud_button
hud_interface[e].hud_screen = hud_screen
hud_interface[e].hud_button1 = hud_button1
hud_interface[e].hud_action1 = hud_action1
hud_interface[e].hud_action1_text = hud_action1_text
hud_interface[e].hud_action1_text = hud_action1_text
hud_interface[e].hud_button2 = hud_button2
hud_interface[e].hud_action2 = hud_action2
hud_interface[e].hud_action2_text = hud_action2_text
Expand All @@ -76,7 +77,7 @@ function hud_interface_init(e)
hud_interface[e].hud_screen = "HUD Screen 9"
hud_interface[e].hud_button1 = "Activate Links"
hud_interface[e].hud_action1 = 1
hud_interface[e].hud_action1_text = "Activate Links"
hud_interface[e].hud_action1_text = "Link Activated"
hud_interface[e].hud_button2 = "Play"
hud_interface[e].hud_action2 = 2
hud_interface[e].hud_action2_text = "Playing Audio"
Expand All @@ -88,11 +89,12 @@ function hud_interface_init(e)
hud_interface[e].hud_action4_text = "Activate IfUsed"
hud_interface[e].hud_button5 = "Exit"
hud_interface[e].hud_action5 = 5
hud_interface[e].hud_action5_text = "Exiting"
hud_interface[e].hud_action5_text = "Exiting"

status[e] = "init"
pressed[e] = 0
actioned[e] = 0
current_link[e] = 0
playonce[e] = 0
end

Expand All @@ -102,86 +104,113 @@ function hud_interface_main(e)
pressed[e] = 0
playonce[e] = 0
actioned[e] = 0
current_link[e] = 0
status[e] = "start"
end

if status[e] == "start" then
local PlayerDist = GetPlayerDistance(e)
if PlayerDist < hud_interface[e].use_range then
local LookingAt = GetPlrLookingAtEx(e,1)
if LookingAt == 1 then
PromptLocal(e,hud_interface[e].use_text)
if g_KeyPressE == 1 and pressed[e] == 0 then
if playonce[e] == 0 then
PlaySound(e,0)
playonce[e] = 1
end
pressed[e] = 1
PromptLocal(e,"")
-- OPEN HUD
ScreenToggle(hud_interface[e].hud_screen)
if hud_interface[e].use_range == 1 then
-- responds instead whenever the HUD screen is visible (i.e opened by a hotkey)
if GetCurrentScreen() > 0 then
if GetCurrentScreenName() == hud_interface[e].hud_screen then
status[e] = "interface"
end
end
end
end
else
local PlayerDist = GetPlayerDistance(e)
if PlayerDist < hud_interface[e].use_range then
local LookingAt = GetPlrLookingAtEx(e,1)
if LookingAt == 1 then
PromptLocal(e,hud_interface[e].use_text)
if g_KeyPressE == 1 and pressed[e] == 0 then
if playonce[e] == 0 then
PlaySound(e,0)
playonce[e] = 1
end
pressed[e] = 1
PromptLocal(e,"")
-- OPEN HUD
ScreenToggle(hud_interface[e].hud_screen)
status[e] = "interface"
end
end
end
end
end

if status[e] == "interface" then
current_link[e] = 0
local buttonElementID = DisplayCurrentScreen()
if buttonElementID >= 0 then
local buttonElementName = GetScreenElementName(1+buttonElementID)
if string.len(buttonElementName) > 0 then
if buttonElementName == hud_interface[e].hud_button1 then
PromptLocal(e,hud_interface[e].hud_action1_text)
if hud_interface[e].hud_action1 == 1 then actioned[e] = 1 end
if hud_interface[e].hud_action1 == 2 then actioned[e] = 2 end
if hud_interface[e].hud_action1 == 3 then actioned[e] = 3 end
if hud_interface[e].hud_action1 == 4 then actioned[e] = 4 end
if hud_interface[e].hud_action1 == 5 then actioned[e] = 5 end
if hud_interface[e].hud_action1 < 10 then
current_link[e] = hud_interface[e].hud_action1
actioned[e] = 1
end
if hud_interface[e].hud_action1 == 10 then actioned[e] = 2 end
if hud_interface[e].hud_action1 == 11 then actioned[e] = 3 end
if hud_interface[e].hud_action1 == 12 then actioned[e] = 4 end
if hud_interface[e].hud_action1 == 13 then actioned[e] = 5 end
status[e] = "action"
end
if buttonElementName == hud_interface[e].hud_button2 then
PromptLocal(e,hud_interface[e].hud_action2_text)
if hud_interface[e].hud_action2 == 1 then actioned[e] = 1 end
if hud_interface[e].hud_action2 == 2 then actioned[e] = 2 end
if hud_interface[e].hud_action2 == 3 then actioned[e] = 3 end
if hud_interface[e].hud_action2 == 4 then actioned[e] = 4 end
if hud_interface[e].hud_action2 == 5 then actioned[e] = 5 end
if hud_interface[e].hud_action1 < 10 then
current_link[e] = hud_interface[e].hud_action2
actioned[e] = 1
end
if hud_interface[e].hud_action2 == 10 then actioned[e] = 2 end
if hud_interface[e].hud_action2 == 11 then actioned[e] = 3 end
if hud_interface[e].hud_action2 == 12 then actioned[e] = 4 end
if hud_interface[e].hud_action2 == 13 then actioned[e] = 5 end
status[e] = "action"
end
end
if buttonElementName == hud_interface[e].hud_button3 then
PromptLocal(e,hud_interface[e].hud_action3_text)
if hud_interface[e].hud_action3 == 1 then actioned[e] = 1 end
if hud_interface[e].hud_action3 == 2 then actioned[e] = 2 end
if hud_interface[e].hud_action3 == 3 then actioned[e] = 3 end
if hud_interface[e].hud_action3 == 4 then actioned[e] = 4 end
if hud_interface[e].hud_action3 == 5 then actioned[e] = 5 end
if hud_interface[e].hud_action3 < 10 then
current_link[e] = hud_interface[e].hud_action3
actioned[e] = 1
end
if hud_interface[e].hud_action3 == 10 then actioned[e] = 2 end
if hud_interface[e].hud_action3 == 11 then actioned[e] = 3 end
if hud_interface[e].hud_action3 == 12 then actioned[e] = 4 end
if hud_interface[e].hud_action3 == 13 then actioned[e] = 5 end
status[e] = "action"
end
if buttonElementName == hud_interface[e].hud_button4 then
PromptLocal(e,hud_interface[e].hud_action4_text)
if hud_interface[e].hud_action4 == 1 then actioned[e] = 1 end
if hud_interface[e].hud_action4 == 2 then actioned[e] = 2 end
if hud_interface[e].hud_action4 == 3 then actioned[e] = 3 end
if hud_interface[e].hud_action4 == 4 then actioned[e] = 4 end
if hud_interface[e].hud_action4 == 5 then actioned[e] = 5 end
if hud_interface[e].hud_action4 < 10 then
current_link[e] = hud_interface[e].hud_action4
actioned[e] = 1
end
if hud_interface[e].hud_action4 == 10 then actioned[e] = 2 end
if hud_interface[e].hud_action4 == 11 then actioned[e] = 3 end
if hud_interface[e].hud_action4 == 12 then actioned[e] = 4 end
if hud_interface[e].hud_action4 == 13 then actioned[e] = 5 end
status[e] = "action"
end
if buttonElementName == hud_interface[e].hud_button5 then
PromptLocal(e,hud_interface[e].hud_action5_text)
if hud_interface[e].hud_action5 == 1 then actioned[e] = 1 end
if hud_interface[e].hud_action5 == 2 then actioned[e] = 2 end
if hud_interface[e].hud_action5 == 3 then actioned[e] = 3 end
if hud_interface[e].hud_action5 == 4 then actioned[e] = 4 end
if hud_interface[e].hud_action5 == 5 then actioned[e] = 5 end
if hud_interface[e].hud_action5 < 10 then
current_link[e] = hud_interface[e].hud_action5
actioned[e] = 1
end
if hud_interface[e].hud_action5 == 10 then actioned[e] = 2 end
if hud_interface[e].hud_action5 == 11 then actioned[e] = 3 end
if hud_interface[e].hud_action5 == 12 then actioned[e] = 4 end
if hud_interface[e].hud_action5 == 13 then actioned[e] = 5 end
status[e] = "action"
end
end
end
end

if status[e] == "action" then
if actioned[e] == 1 then
PerformLogicConnections(e)
PerformLogicConnectionNumber(e,current_link[e])
actioned[e] = 0
status[e] = "interface"
end
Expand Down

0 comments on commit deb84a5

Please sign in to comment.