Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: WMCoolmon on August 30, 2008, 03:36:47 am

Title: Scripts for C08302008
Post by: WMCoolmon on August 30, 2008, 03:36:47 am
(http://fs2source.warpcore.org/temp/wmc/egmm_thumb.jpg) (http://fs2source.warpcore.org/temp/wmc/egmm.jpg)

tex_test-sct.tbm
Swaps the textures for the target ship. Now, you too can turn anything into a Shivan (mediaVPs) or some kind of bizarre glowstick thing (retail data).
Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Load the replacement texture
g_ReplaceTexture = gr.loadTexture("fighter2s-02-glow")

--Use interface texture for a backup, since these are usually around
if not g_ReplaceTexture then
g_ReplaceTexture = gr.loadTexture("2_BAB_050002")
end
]

$State: GS_STATE_GAME_PLAY
$Keypress: W
$On Key Released: [
--Signal that we want to do a texture switch
g_Switch = true
]

$State: GS_STATE_GAME_PLAY
$On Frame: [
local playerShip = hv.Player
local targetShip = nil

if playerShip and playerShip:isValid() then
targetShip = playerShip
local tgt = playerShip.Target
if tgt:isValid() then
targetShip = tgt
end
end

if targetShip and targetShip:isValid() then
local texs = targetShip.Textures

--Switch textures
if g_Switch then
texReplace = g_ReplaceTexture

--Textures were already replaced; reset them
if texs[1] ~= texReplace then
texReplace = nil
end

--Go through all the textures and replace them
for i=1,#texs do
texs[i] = texReplace
end

--Signal switch complete
g_Switch = false
end

--Show texture list
gr.setColor(255,255,255)
for i=1,#texs,1 do
local tx = texs[i]
if tx:isValid() then
gr.drawString("TEXTURE: " .. tx:getFilename())
else
gr.drawString("TEXTURE: <NONE>")
end
end
end
]
#End

shipviewer-sct.tbm
An updated version of the ship viewer in the wiki. Features keypresses, as well as visual help. You can now get to a specific ship much faster, as well.

Note that this script starts before anything else, so you can't get to the rest of the game when running the script.

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
g_Heading = 40
g_Pitch = 0
g_Bank = 0
g_ShipClassIndex = 1
g_Distance = 1.3

g_ShowHelp = true
g_ShowInfo = true

function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end

function string.ends(String,End)
   return End=='' or string.sub(String,-string.len(End))==End
end
]

$Application: Freespace 2
$State: GS_STATE_INITIAL_PLAYER_SELECT
$On Key Released: [
if hv.Key == "Esc" then
ba.postGameEvent(ba.GameEvents['GS_EVENT_QUIT_GAME'])
elseif hv.Key == "H" then
g_ShowHelp = (not g_ShowHelp)
elseif hv.Key == "I" then
g_ShowInfo = (not g_ShowInfo)
elseif hv.Key == "Pad +" or hv.Key == "Shift-=" then
g_Distance = g_Distance-0.1
elseif hv.Key == "Pad -" or hv.Key == "-" then
g_Distance = g_Distance+0.1
elseif hv.Key == "Left Arrow" then
g_ShipClassIndex = g_ShipClassIndex - 1
if g_ShipClassIndex < 1 then
g_ShipClassIndex = #tb.ShipClasses
end
elseif hv.Key == "Right Arrow" then
g_ShipClassIndex = g_ShipClassIndex + 1
if g_ShipClassIndex > #tb.ShipClasses then
g_ShipClassIndex = 1
end
elseif string.starts(hv.Key, "Alt-") then
num = tonumber(string.sub(hv.Key,-1))
if num >= 0 and num < 10 then
g_ShipClassIndex = math.floor(g_ShipClassIndex/100)*100+num*10
end
elseif string.starts(hv.Key, "Shift-") then
num = tonumber(string.sub(hv.Key,-1))
if num >= 0 and num < 10 then
g_ShipClassIndex = num*100
end
end

--Loop/sanity checking
if g_ShipClassIndex < 1 then
g_ShipClassIndex = 1
elseif g_ShipClassIndex > #tb.ShipClasses then
g_ShipClassIndex = #tb.ShipClasses
end
]
$On State Start: []
+Override: true
$On State End: []
+Override: true
$On Frame: [
if g_ShipClassIndex then
--If no triggers, do normal mouse stuff
--Left changes heading
--Middle changes g_Pitch
--Right changes g_Bank
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
g_Heading = (1-io.getMouseX()/gr.getScreenWidth())*100
end
if io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON) then
g_Pitch = (1-io.getMouseY()/gr.getScreenHeight())*100
end
if io.isMouseButtonDown(MOUSE_RIGHT_BUTTON) then
g_Bank = io.getMouseX()/gr.getScreenWidth()*100
end

--Render setup
gr.setColor(255, 255, 255)

--Render help
if g_ShowHelp then
gr.drawString("h       - Toggle help", gr.getScreenWidth()-250, gr.getScreenHeight()-150)
gr.drawString("i       - Toggle info")
gr.drawString("+       - Zoom in")
gr.drawString("-       - Zoom out")
gr.drawString("-->     - Next ship")
gr.drawString("<--     - Previous ship")
gr.drawString("Alt-#   - Skip to x#0th ship")
gr.drawString("Shift-# - Skip to #00th ship")
gr.drawString("Esc     - Quit")
end

--Finally, render the ship
local renderShipClass = tb.ShipClasses[g_ShipClassIndex]
if renderShipClass:isValid() then
--Render info
if g_ShowInfo then
gr.drawString(renderShipClass.Name .. " (" .. g_ShipClassIndex .. "/" .. #tb.ShipClasses .. ")", 10, 10)
end
renderShipClass:renderTechModel(0, 0, gr.getScreenWidth()-1, gr.getScreenHeight()-1, g_Heading, g_Pitch, g_Bank, g_Distance)
end
end
]
+Override: true
#End

mainhall_test-sct.tbm
I saved the best for last...

This started out as a small test script of having a mission play in the main hall. Then I switched in "Endgame" instead of "Their Finest Hour" as the test mission and got an absolutely perfect mainhall. I used the buttons from chief's repost of the old main menu mission script. Play this with the MediaVPs and be amazed. Seriously, this looks absolutely incredible, especially considering this is just using the original :V: mission.

Did I mention that ships warp in and start fighting? The beam and flak fire? I guess I did now.

The downside: While the mission on the main menu works, the rest of the game behaves...unusually. Exiting a mission takes you out of the game. Much of the interface seems to work, though.

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Function to handle a section every frame
section = function(name, event, num)
--MENU COLOR
local xmargin = gr.getScreenWidth()/8
local ymargin = gr.getScreenHeight()/8

--Get corner coordinates for this box
local x1 = xmargin
local y1 = ymargin*num
local x2 = x1+159
local y2 = y1+35

--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
--Draw the inside box
gr.setColor(0, 255, 0)
gr.drawRectangle(x1+5, y1+5, x2-5, y2-5, false, false)

--Draw the little target lines now
local x = x1+(x2-x1)/2
local y = y1-20

--Top target line
gr.drawLine(x, y, x, y+15)

--Bottom target line
y = y2+10
gr.drawLine(x, y, x, y+15)

--Left target line
x = x1-20
y = y1+17
gr.drawLine(x, y, x+15, y)

--Right target line
x = x2+5
gr.drawLine(x, y, x+15, y)

--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
ba.postGameEvent(ba.GameEvents[event])
gr.drawRectangle(x1, y1, x2, y2, false, false)
end
end

--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)

--Draw the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, y1+15)
end
]
$On Mission Start: [
g_missionLoaded = nil
g_splashScreen = nil
]

$Application: Freespace 2
$State: GS_STATE_MAIN_MENU
$On State Start: []
+Override: true
$On State End: []
+Override: true
$On Frame: [
if not g_splashScreen then
--Don't need cursor
io.setCursorHidden(true)

--Draw splash image
local tex = gr.loadTexture("2_PreLoad.dds")
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end

--Draw "Loading..."
gr.setColor(255, 255, 255)
gr.CurrentFont = gr.Fonts['font02']
local loadString = "Loading..."
local x = (gr.getScreenWidth()-gr.getStringWidth(loadString))/2
local y = (gr.getScreenHeight()-gr.CurrentFont.Height)/2
gr.drawString(loadString, x, y)

--Done with splash
gr.CurrentFont = gr.Fonts['font01']
g_splashScreen = true
elseif not g_missionLoaded then
mn.loadMission("sm2-06.fs2")
io.setCursorHidden(false)
g_missionLoaded = true
end

if g_missionLoaded then
mn.simulateFrame()
mn.renderFrame()

section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 1)
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 2)
section("Tech Room", "GS_EVENT_TECH_MENU", 3)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 4)
section("Options", "GS_EVENT_OPTIONS_MENU", 5)
section("Exit", "GS_EVENT_QUIT_GAME", 6)
end
]
+Override: true
#End
Title: Re: Scripts for C08302008
Post by: shiv on August 30, 2008, 05:06:48 am
Awesome. I'm the most intrested in having mission based mainhall. What should I do if I want to put my own mission as mainhall?
Title: Re: Scripts for C08302008
Post by: WMCoolmon on August 30, 2008, 05:24:41 am
Code: [Select]
mn.loadMission("sm2-06.fs2")
Change that line to refer to your mission instead of one from the campaign. It's near the bottom. :)
Title: Re: Scripts for C08302008
Post by: shiv on August 30, 2008, 05:38:28 am
Oh, I see. Thanks. There're also fields to change "loading" text string and it's colour, yeah? And are there any to change buttons/button highlight colour?
Title: Re: Scripts for C08302008
Post by: WMCoolmon on August 30, 2008, 06:25:13 am
Code: [Select]
local loadString = "Loading..."
For the loading string. It'll auto-compensate to center itself.

For color, there's a few places where it happens. gr.setColor() sets the current text or shape/line color. The first number is red (out of 255), and the next two numbers are green and blue, respectively. There's also an optional alpha value.

Once setColor is called, all of the text or shapes after it will be that color, until another call to setColor is made.
Title: Re: Scripts for C08302008
Post by: shiv on August 30, 2008, 07:11:50 am
Oh. I have idea for mainhall. When you something's selected (green border appear) this border can flash. I mean one second is visible, then next one it dissapear and appear next second... I can't explain it better with my poor english ;)
Title: Re: Scripts for C08302008
Post by: pecenipicek on August 30, 2008, 09:04:00 am
how do you set the viewpoint for the mission? or does it just use player ship's viewpoint? yep, players ship spawn location is the viewpoint.

i'm gonna play with some stuff now :D

i've tested the scripts with the c08302008 build, no problems with either retail, mvp or our files (tap files)

didnt try to go into missions tho, just tested how it displays the missions...
Title: Re: Scripts for C08302008
Post by: Solatar on August 30, 2008, 05:33:14 pm
Mainhall thing is awesome...I always liked that aspect of Command and Conquer Generals, and now MODs can have even MORE flexibility over their appearances.
Title: Re: Scripts for C08302008
Post by: WMCoolmon on August 30, 2008, 07:17:24 pm
Updated script:
Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Function to handle a section every frame
section = function(name, event, num)
--MENU COLOR
local xmargin = gr.getScreenWidth()/8
local ymargin = gr.getScreenHeight()/8

--Get corner coordinates for this box
local x1 = xmargin
local y1 = ymargin*num
local x2 = x1+159
local y2 = y1+35

--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
--Draw the inside box
gr.setColor(0, 255, 0)
gr.drawRectangle(x1+5, y1+5, x2-5, y2-5, false, false)

--Draw the little target lines now
local x = x1+(x2-x1)/2
local y = y1-20

--Top target line
gr.drawLine(x, y, x, y+15)

--Bottom target line
y = y2+10
gr.drawLine(x, y, x, y+15)

--Left target line
x = x1-20
y = y1+17
gr.drawLine(x, y, x+15, y)

--Right target line
x = x2+5
gr.drawLine(x, y, x+15, y)

--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
gr.drawRectangle(x1, y1, x2, y2, false, false)
if event == "GS_EVENT_NEW_CAMPAIGN" then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
ba.postGameEvent(ba.GameEvents[event])
end
end

--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)

--Draw the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, y1+15)
end
]

$Application: Freespace 2
$State: GS_STATE_MAIN_MENU
$On State Start: []
+Override: true
$On State End: [
if g_missionLoaded then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
]
+Override: true
$On Frame: [
if not g_splashScreen then
--Don't need cursor
io.setCursorHidden(true)

--Draw splash image
local tex = gr.loadTexture("2_PreLoad.dds")
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end

--Draw "Loading..."
gr.setColor(255, 255, 255)
gr.CurrentFont = gr.Fonts['font02']
local loadString = "Loading..."
local x = (gr.getScreenWidth()-gr.getStringWidth(loadString))/2
local y = (gr.getScreenHeight()-gr.CurrentFont.Height)/2
gr.drawString(loadString, x, y)

--Done with splash
gr.CurrentFont = gr.Fonts['font01']
g_splashScreen = true
elseif not g_missionLoaded then
mn.loadMission("sm2-06.fs2")
io.setCursorHidden(false)
g_missionLoaded = true
end

if g_missionLoaded then
mn.simulateFrame()
mn.renderFrame()

section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 1)
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 2)
section("Tech Room", "GS_EVENT_TECH_MENU", 3)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 4)
section("Options", "GS_EVENT_OPTIONS_MENU", 5)
section("Exit", "GS_EVENT_QUIT_GAME", 6)
end
]
+Override: true
#End

This script seems to be much more reliable. It has two major changes:

One, it unloads the mission whenever you leave the main hall - this happens when you go to the barracks, campaign room, and techroom. Those rooms tend to access the campaign file (At least, the techroom and campaign room do, I didn't check the barracks). This reinitializes the SEXPs, which doesn't do good things for the main menu mission, which is already using them. By unloading the mission and then reloading it when you return to the mainhall, it gets around the SEXP issue.

The options screen works simply as an overlay over the mainhall and essentially pauses the mission underneath, so it doesn't have to reload the mission.

Two, the ready room requires something special. Since making the call to postGameEvent actually loads up the current mission name before it changes the state (switches out of the main hall), unloading the mission also clears that data. So instead I added a special condition to the section() function to handle that case, and unload the main menu mission before the call to postGameEvent. This also seems to fix the problem of exiting out of the game instead of to the main menu.

Result:
With the changes in the new script, the mission mainhall is at the point where I'd consider it a viable option for a release. The downside is that you need to watch what you put in the main menu mission, since it'll have to reload it often. Definitely include ibx files for any models used in it, and if you can remove weapons from ships that you don't care about, disable the support ship, and things like that, that would help too. It'll keep less media from being loaded. FS2 does seem to store things in memory properly with main hall missions, so once the main hall is loaded the first time, it'll take less time the next few times you load it.

Alternatives:
Moving the place that mission names are loaded would make the above script simpler but would require reloading the mission.

Rewriting the SEXP system to be more object-oriented and outside functions to take that into account, so you could have more than one SEXP system operational at the same time, would be one option. Another option would be to save the state of the SEXP system when loading a campaign, and then restore it after you're finished with the campaign SEXPs. Either way, you'd need to be pretty careful and I'm reluctant to do either one for 3.6.10 unless it's proven impossible to load main menu missions in a reasonable amount of time.
Title: Re: Scripts for C08302008
Post by: pecenipicek on August 30, 2008, 09:30:36 pm
from what this basically tells me...

In short, to any mod team planning to use this, you should make a special mission for the main hall, especially with the camera code (read cutscene...), with the least possible different ships. (i'm not talking total, i'm talking less different classes of ships so it doesnt have to load all that usually goes in a normal mission.
Title: Re: Scripts for C08302008
Post by: Solatar on August 30, 2008, 11:20:06 pm
Enabling it and giving it a good test run.

EDIT: I've given it a bit of a run. It can be customized even further by changing the color of the "select" form of the buttons, easily done. I like it a lot, I really do.  :)
Title: Re: Scripts for C08302008
Post by: WMCoolmon on August 30, 2008, 11:41:03 pm
from what this basically tells me...

In short, to any mod team planning to use this, you should make a special mission for the main hall, especially with the camera code (read cutscene...), with the least possible different ships. (i'm not talking total, i'm talking less different classes of ships so it doesnt have to load all that usually goes in a normal mission.

Yeah. And if you aren't planning on having ships shooting at each other, strip them of their guns so the game doesn't try and load the media for those.
Title: Re: Scripts for C08302008
Post by: ShadowGorrath on August 31, 2008, 05:10:53 am
The mainhall script is awesome. Though I have found some annoying bits. Like that you can't change the difficulty level in the options.
Title: Re: Scripts for C08302008
Post by: chief1983 on September 01, 2008, 01:37:57 am
Fixed the options thing, along with making the ready room button work for multiplayer.  However, for some reason the mission doesn't start playing when you have a multiplayer pilot loaded.  The mission loads, you see the ships, but nothing happens.  But at least all the menus work as they should now, as far as I can tell.

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Function to handle a section every frame
section = function(name, event, num)
--MENU COLOR
local xmargin = gr.getScreenWidth()/8
local ymargin = gr.getScreenHeight()/8

--Get corner coordinates for this box
local x1 = xmargin
local y1 = ymargin*num
local x2 = x1+159
local y2 = y1+35

--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
--Draw the inside box
gr.setColor(0, 255, 0)
gr.drawRectangle(x1+5, y1+5, x2-5, y2-5, false, false)

--Draw the little target lines now
local x = x1+(x2-x1)/2
local y = y1-20

--Top target line
gr.drawLine(x, y, x, y+15)

--Bottom target line
y = y2+10
gr.drawLine(x, y, x, y+15)

--Left target line
x = x1-20
y = y1+17
gr.drawLine(x, y, x+15, y)

--Right target line
x = x2+5
gr.drawLine(x, y, x+15, y)

--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
gr.drawRectangle(x1, y1, x2, y2, false, false)
if event == "GS_EVENT_NEW_CAMPAIGN" or event == "GS_EVENT_OPTIONS_MENU" then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
ba.postGameEvent(ba.GameEvents[event])
end
end

--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)

--Draw the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, y1+15)
end
]

$Application: Freespace 2
$State: GS_STATE_MAIN_MENU
$On State Start: []
+Override: true
$On State End: [
if g_missionLoaded then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
]
+Override: true
$On Frame: [
if not g_splashScreen then
--Don't need cursor
io.setCursorHidden(true)

--Draw splash image
local tex = gr.loadTexture("2_PreLoad.dds")
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end

--Draw "Loading..."
gr.setColor(255, 255, 255)
gr.CurrentFont = gr.Fonts['font02']
local loadString = "Loading..."
local x = (gr.getScreenWidth()-gr.getStringWidth(loadString))/2
local y = (gr.getScreenHeight()-gr.CurrentFont.Height)/2
gr.drawString(loadString, x, y)

--Done with splash
gr.CurrentFont = gr.Fonts['font01']
g_splashScreen = true
elseif not g_missionLoaded then
mn.loadMission("sm2-06.fs2")
io.setCursorHidden(false)
g_missionLoaded = true
end

if g_missionLoaded then
mn.simulateFrame()
mn.renderFrame()

if ts.isCurrentPlayerMulti()==true then
if ts.isPXOEnabled()==true then
section("Multiplayer", "GS_EVENT_PXO", 1)
else
section("Multiplayer", "GS_EVENT_MULTI_JOIN_GAME", 1)
end
else
section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 1)
end
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 2)
section("Tech Room", "GS_EVENT_TECH_MENU", 3)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 4)
section("Options", "GS_EVENT_OPTIONS_MENU", 5)
section("Exit", "GS_EVENT_QUIT_GAME", 6)
end
]
+Override: true
#End
Title: Re: Scripts for C08302008
Post by: shiv on September 29, 2008, 02:01:06 pm
Is possible to change automatically mainhall mission with campaign progress?
Title: Re: Scripts for C08302008
Post by: WMCoolmon on October 02, 2008, 05:00:32 am
You'd have two options - one, have a SEXP variable that's campaign-persistent which defines campaign progress (or just which mainhall to use), and have a default mission loaded for when it's no longer defined.

Two, define a scripting function which writes a file, that's then checked by the mainhall script. I'd strongly discourage this option, though, as the first one is far more elegant and doesn't require writing the extra file.
Title: Re: Scripts for C08302008
Post by: chief1983 on January 09, 2009, 12:46:33 am
I know this is necro, but I've found an issue with this mainhall script and didn't feel a need to start a new thread for it since it directly relates to the changes I posted here.  Originally now, this did not function for multiplayer, and I added in the support to check for which button to show based on the results of a couple of Lua functions.  Ok, that all seems to work fine.  Except, when I get logged into PXO and go to look at the games, nothing shows up.  I disable this script and I see games.  I've also tried it with the older script that shows a tech model, it seems to not work with it too.  Either it's related to the presence of a scripting table at all, or something about how I set it to change the state to multiplayer (or the way I check if a pilot is multiplayer, that never did get much testing :/ ).  Anyone have any clues on this?  It's about the only problem I have with this menu at this point.  Oh and the usual mainhall hotkeys don't work anymore, not sure if there's any way to pass those through or whatnot, but it is a bit crippling.  That means no escape to quit, no F3 lab, probably no cheat code (isn't there one you have to type in the mainhall?).
Title: Re: Scripts for C08302008
Post by: Mobius on March 08, 2009, 05:07:27 am
How did I miss those scripts? :(

The only problem is that they're not standard FSO builds-compatible. I wonder if one day all builds will be compatible with Scripting. ;7
Title: Re: Scripts for C08302008
Post by: pecenipicek on March 08, 2009, 07:11:13 am
when will this stuff get merged anyhow?
Title: Re: Scripts for C08302008
Post by: chief1983 on March 08, 2009, 05:52:39 pm
What are you talking about?  I've been using the latest version of this script with nightly builds and Wanderer branch builds (which have nothing to do with this script) for months.
Title: Re: Scripts for C08302008
Post by: pecenipicek on March 08, 2009, 07:09:02 pm
k. forgots :p
Title: Re: Scripts for C08302008
Post by: chief1983 on March 08, 2009, 09:41:37 pm
k. forgots :p

I was more asking Mobius than you.  Cause I'm pretty sure they are compatible right now with nightly builds, unless he just meant 3.6.9 by 'standard'.
Title: Re: Scripts for C08302008
Post by: Mobius on March 09, 2009, 11:49:20 am
What are you talking about?  I've been using the latest version of this script with nightly builds and Wanderer branch builds (which have nothing to do with this script) for months.

How about INF builds? Will it work?
Title: Re: Scripts for C08302008
Post by: chief1983 on March 09, 2009, 12:30:28 pm
If they've been made with a recent sync with trunk (which as I've stated elsewhere, Karajorma's recent INF-multiplayer builds have been), then yes.
Title: Re: Scripts for C08302008
Post by: Mobius on March 09, 2009, 12:47:43 pm
Thanks for the info, chief. :)
Title: Re: Scripts for C08302008
Post by: The E on June 20, 2009, 10:51:32 am
During an IRC conversation with Flaming_Sword today, we decided to update this script a little. Actually, most of the work was done by Flaming_Sword, I just sat on the sidelines cheering....
The major upgrade here was to enable access to the F3 room. You can get there by clicking on the little box in the top-left corner of the screen.

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Function to handle a section every frame
section = function(name, event, num)
--MENU COLOR
local xmargin = gr.getScreenWidth()/8
local ymargin = gr.getScreenHeight()/8

--Get corner coordinates for this box
local x1 = xmargin
local y1 = ymargin*num
local x2 = x1+159
local y2 = y1+35

--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
--Draw the inside box
gr.setColor(0, 255, 0)
gr.drawRectangle(x1+5, y1+5, x2-5, y2-5, false, false)

--Draw the little target lines now
local x = x1+(x2-x1)/2
local y = y1-20

--Top target line
gr.drawLine(x, y, x, y+15)

--Bottom target line
y = y2+10
gr.drawLine(x, y, x, y+15)

--Left target line
x = x1-20
y = y1+17
gr.drawLine(x, y, x+15, y)

--Right target line
x = x2+5
gr.drawLine(x, y, x+15, y)

--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
gr.drawRectangle(x1, y1, x2, y2, false, false)
if event == "GS_EVENT_NEW_CAMPAIGN" or event == "GS_EVENT_OPTIONS_MENU" then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
ba.postGameEvent(ba.GameEvents[event])
end
end

--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)

--Draw the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, y1+15)
end
--Function to handle a section every frame
section2 = function(name, event, num)
--MENU COLOR
local xmargin = gr.getScreenWidth()/256
local ymargin = gr.getScreenHeight()/256

--Get corner coordinates for this box
local x1 = xmargin
local y1 = ymargin*num
local x2 = x1+10
local y2 = y1+10

--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
gr.drawRectangle(x1, y1, x2, y2, false, false)
if event == "GS_EVENT_NEW_CAMPAIGN" or event == "GS_EVENT_OPTIONS_MENU" then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
ba.postGameEvent(ba.GameEvents[event])
end
end

--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)

--Draw the name
--gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, y1+15)
end
]

$Application: Freespace 2
$State: GS_STATE_MAIN_MENU
$On State Start: []
+Override: true
$On State End: [
if g_missionLoaded then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
]
+Override: true
$On Frame: [
if not g_splashScreen then
--Don't need cursor
io.setCursorHidden(true)

--Draw splash image
local tex = gr.loadTexture("2_PreLoad.dds")
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end

--Draw "Loading..."
gr.setColor(255, 255, 255)
gr.CurrentFont = gr.Fonts['font02']
local loadString = "Loading..."
local x = (gr.getScreenWidth()-gr.getStringWidth(loadString))/2
local y = (gr.getScreenHeight()-gr.CurrentFont.Height)/2
gr.drawString(loadString, x, y)

--Done with splash
gr.CurrentFont = gr.Fonts['font01']
g_splashScreen = true
elseif not g_missionLoaded then
mn.loadMission("mainhall.fs2")
io.setCursorHidden(false)
g_missionLoaded = true
end

if g_missionLoaded then
mn.simulateFrame()
mn.renderFrame()

if ts.isCurrentPlayerMulti()==true then
if ts.isPXOEnabled()==true then
section("Multiplayer", "GS_EVENT_PXO", 1)
else
section("Multiplayer", "GS_EVENT_MULTI_JOIN_GAME", 1)
end
else
section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 1)
end
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 2)
section("Tech Room", "GS_EVENT_TECH_MENU", 3)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 4)
section("Options", "GS_EVENT_OPTIONS_MENU", 5)
section("Exit", "GS_EVENT_QUIT_GAME", 6)
section2("F3", "GS_EVENT_LAB", 1)
end
]
+Override: true
#End
Title: Re: Scripts for C08302008
Post by: chief1983 on June 20, 2009, 12:58:50 pm
You started with my updated version of the script right?  It fixed a few issues in the original post.  Also, this script still has an unresolved issue of breaking multiplayer for some reason.  Somehow, when it's in use, you cannot see any games in the game viewer, nor can your games be seen by others I believe.  That alone has caused me to stop using it for the time being.  Still, cool addition.  Are there any other menus that can only be accessed via a keyboard shortcut?
Title: Re: Scripts for C08302008
Post by: The E on June 20, 2009, 01:24:44 pm
Yes, we started with your revision. Unfortunately, it still breaks Multi.
Title: Re: Scripts for C08302008
Post by: Aardwolf on June 21, 2009, 01:42:16 am
I would imagine the multi-breaking is somehow being caused by the game 'thinking it's in a multi-game' when in the menu. Because the game works differently in multiplayer, maybe this script is duping the game into thinking it's in server mode (and thus preventing other multiplayer functionality from working)?
Title: Re: Scripts for C08302008
Post by: chief1983 on June 21, 2009, 12:49:23 pm
I added the multiplayer functionality to the script in the first place, and one way that worked was to adjust the state change calls.  I've compared the state changes when using the script to when not using it and can't find much of a difference, other than the order some resources seem to be getting loaded.
Title: Re: Scripts for C08302008
Post by: The E on June 22, 2009, 10:42:29 am
So, here are the results of my first foray into the FS2 code. I've changed the postGameEvent function so that the game is properly informed about what net protocol to use, which was missing before. Diff against 5367 is attached.

(What this means is that the script will not break multiplayer anymore.)

[attachment has decomposed]
Title: Re: Scripts for C08302008
Post by: Aardwolf on June 23, 2009, 07:18:41 pm
Have you tested it?

Edit: it looks like it's been committed anyway...
Title: Re: Scripts for C08302008
Post by: The E on June 23, 2009, 07:20:23 pm
Yes, it was tested, using both TBP (Inferno) and FS2. Nothing seemed to be obviously broken.

EDIT: Here's my latest version of the script:

Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Function to handle a section every frame
section = function(name, event, num, hidden)
if hidden == false then
divsize = 8
xadd = 159
yadd = 35
else
divsize = 256
xadd = 10
yadd = 10
end

--MENU COLOR
local xmargin = gr.getScreenWidth()/divsize
local ymargin = gr.getScreenHeight()/divsize

--Get corner coordinates for this box
local x1 = xmargin
local y1 = ymargin*num
local x2 = x1+xadd
local y2 = y1+yadd

--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
if hidden == false then
--Draw the inside box
gr.setColor(0, 255, 0)
gr.drawRectangle(x1+5, y1+5, x2-5, y2-5, false, false)

--Draw the little target lines now
local x = x1+(x2-x1)/2
local y = y1-20

--Top target line
gr.drawLine(x, y, x, y+15)

--Bottom target line
y = y2+10
gr.drawLine(x, y, x, y+15)

--Left target line
x = x1-20
y = y1+17
gr.drawLine(x, y, x+15, y)

--Right target line
x = x2+5
gr.drawLine(x, y, x+15, y)
end

--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
gr.drawRectangle(x1, y1, x2, y2, false, false)
if event == "GS_EVENT_NEW_CAMPAIGN" or event == "GS_EVENT_OPTIONS_MENU" then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
ba.postGameEvent(ba.GameEvents[event])
end
end

--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)

if hidden == false then
--Draw the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, y1+15)
end
end
]

$Application: Freespace 2
$State: GS_STATE_MAIN_MENU
$On State Start: [
logolist = {"43_logo","1610_logo"}                --This is a list of logos. Basically the same Logo, only adapted for 4:3 aspect ratio displays and 16:10 ones
shiplist = {"EA Thunderbolt","EA Aurora","EA Badger","EA Tiger","PSI Command Ship","EA Hyperion","EA Omega","EA Warlock","EA Omega-X","Babylon 5 (S1)","MF Sharlin","NR G'Quan","CR Primus"} --Put your ship classes in quotes here
missionlist = {"Mainhall.fs2"}                    --List of missions to be used
backgroundlist = {"43_mainhall", "1610_mainhall"} --List of backgrounds. Again, divided into 4:3 and 16:10 ones
splashscreen = "2_PreLoad"                        --Splashscreen displayed while the mission loads
usemission = false                               --If false, the single- and multiplayer UI will use the same layout. If true, one of the missions defined in the missionlist will play in the background of the single player UI
rotConst = 7                                      --Modify this to make the ship turn faster to slower

screenWidth = gr.getScreenWidth()
screenHeight = gr.getScreenHeight()
aspectRatio = screenWidth/screenHeight

if aspectRatio == 1.6 then
logo = logolist[2]
background = backgroundlist[2]
else
logo = logolist[1]
background = backgroundlist[1]
end

imgWidth = gr.getImageWidth(logo)
imgHeight = gr.getImageHeight(logo)
renderX1 = 0 --screenWidth * 0.2
renderX2 = screenWidth --* 0.99
renderY1 = 0 --screenHeight * 0.1
renderY2 = screenHeight --* 0.9
rendermidX = (renderX1+renderX2)/2
imageX = 0 --(screenWidth*0.5)-imgWidth/2
imageY = screenHeight - imgHeight

if ts.isCurrentPlayerMulti()==true or usemission==false then
numChoices = table.getn(shiplist)
randomShip = tb.ShipClasses[shiplist[math.random(1,numChoices)]]
shipName = randomShip.Name
init = 42
end
]
+Override: true
$On State End: [
if g_missionLoaded then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
]
+Override: true
$On Frame: [
if ts.isCurrentPlayerMulti()==true or usemission==false then

--Draw background image
local tex = gr.loadTexture(background)
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end

if rotate_pct then
rotate_pct = rotate_pct + rotConst*ba.getFrametime()
if rotate_pct > 100 then
rotate_pct = rotate_pct - 100
end
else
rotate_pct = 40
end

randomShip:renderTechModel(renderX1, renderY1, renderX2, renderY2, rotate_pct)

gr.setColor(255,255,255)
gr.drawString(shipName,rendermidX-gr.getStringWidth(shipName)/2,renderY2)
else
if not g_splashScreen then
--Don't need cursor
io.setCursorHidden(true)

--Draw splash image
local tex = gr.loadTexture(splashscreen)
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end

--Draw "Loading..."
gr.setColor(255, 255, 255)
gr.CurrentFont = gr.Fonts['font02']
local loadString = "Loading..."
local x = (gr.getScreenWidth()-gr.getStringWidth(loadString))/2
local y = (gr.getScreenHeight()-gr.CurrentFont.Height)/2
gr.drawString(loadString, x, y)

--Done with splash
gr.CurrentFont = gr.Fonts['font01']
g_splashScreen = true
elseif not g_missionLoaded then
if init2 == nil then
missionName = missionlist[math.random(1,table.getn(missionlist))]
init2 = 42
end
mn.loadMission(missionName)
io.setCursorHidden(false)
g_missionLoaded = true
end
end

if g_missionLoaded then
mn.simulateFrame()
mn.renderFrame()
end

if g_missionLoaded or ts.isCurrentPlayerMulti()==true or usemission==false then
if ts.isCurrentPlayerMulti()==true then
if ts.isPXOEnabled()==true then
section("Multiplayer", "GS_EVENT_PXO", 1, false)
else
section("Multiplayer", "GS_EVENT_MULTI_JOIN_GAME", 1, false)
end
else
section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 1, false)
end
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 2, false)
section("Tech Room", "GS_EVENT_TECH_MENU", 3, false)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 4, false)
section("Options", "GS_EVENT_OPTIONS_MENU", 5, false)
section("Exit", "GS_EVENT_QUIT_GAME", 6, false)
section("F3", "GS_EVENT_LAB", 1, true)
end

gr.drawImage(logo, imageX, imageY, gr.getScreenWidth(), gr.getScreenHeight())
]
+Override: true
#End
Title: Re: Scripts for C08302008
Post by: shiv on July 23, 2009, 01:07:56 pm
Question, is it possible to set music for this? (that will keep playing in barracks for example?)
Title: Re: Scripts for C08302008
Post by: The E on July 23, 2009, 01:12:25 pm
In principle, yes. If you have TBP installed, you can check it out here: http://www.hard-light.net/forums/index.php/topic,63941.0.html

The music thing, however, depends on code that currently is only present in my builds (Will post that later tonight). There is a command to play music, but none to stop it playing again in trunk which is a bit silly.
Title: Re: Scripts for C08302008
Post by: shiv on July 23, 2009, 01:31:19 pm
I don't have TBP now :(
Title: Re: Scripts for C08302008
Post by: Krackers87 on October 08, 2009, 10:29:51 am
Tried the mainhall script and i got attacked and killed by an offscreen enemy, then i lost the mission... >.>

I lost the mainhall :'(


I loled so hard.
Title: Re: Scripts for C08302008
Post by: origin on November 09, 2009, 09:35:58 pm
I tried out the script and it is very cool.  I loaded up my own screen and tried to load some music but the play back was terrible.  I used  - mh_audiohandle = ad.playMusic(" ").  I tried a .wav and an .ogg file they both sounded the same - very distorted.  Is there a certain form the the file needs to be or am I just completely off base here?  My experience in scripting is very limited.
Title: Re: Scripts for C08302008
Post by: origin on November 12, 2009, 08:32:03 pm
Well I got the music to play perfectly with playMusic().  But I cannot stop the music; it plays continuously - and if I try to use StopMusic() I get an error because I suppose that function is not in the 3.6.10.  So any ideas on what I can do from here.  I think I am talking to myself here but at least I haven't started answering myself.....
Title: Re: Scripts for C08302008
Post by: Reprobator on November 22, 2009, 03:37:06 pm
maybe, i did not tryed the script yet, i'm gonne try in few minutes but, can't you load the music via de the mission itself (with fred) ?