Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: WMCoolmon on January 12, 2006, 12:58:25 pm

Title: New Main hall (Big pic)
Post by: WMCoolmon on January 12, 2006, 12:58:25 pm
(http://fs2source.warpcore.org/temp/mainhall.png)

There's just one funny thing about this main hall.

It's not done with the code. It doesn't require any extra media other than a table. (Although MediaVPs are definitely recommended.

It's done entirely via scripting. :nod: The basic concept is based on a title screen idea I had for Ferrium; the only big difference is that I replaced a planet in the lower-left with the ship model, because I could only get the drawMonochromeImage() function working in a way that would let me use the upper-right portion of a planet in the lower-left of the screen. (FYI, the aabitmap function is what the HUD uses to draw its graphics.)

If you take a closer look at the table you'll see this:
Code: [Select]
#State Hooks
$State: GS_STATE_MAIN_MENU
...
#End

What I've done is I've enabled you to link into any Freespace state (Read: room, like the techroom, or the ready room) and have it execute whatever's in the $Hook: variable rather than what's on the room.

You can also use the setEvent() command to change to a different room/state. This is how I made the buttons work for the Mainhall. Using getEventTypeName() and getNumEventTypes() you can with a for loop, you can get a list of all events you can switch to. For states, look up code/gamesequence/gamesequence.h in CVS.

The ship model is done with an easy-to-use render function that's part of the shipclass object. So, all you need to render a 640x480 GTF Hercules in the upper-left corner is add the following lines to any hook
Code: [Select]
ship = tb.getShipClass("GTF Hercules")
ship:renderTechModel(0, 0, 640, 480, false)

I've provided three extra arguments that let you turn the ship any which way you choose; you have to rotate it manually using the bs.getFrametime() function (See my scripting.tbl).

Variables by default are persistent between frames. So if you set a variable called "my_dog", the value will still be there the next time that a hook is run. It will also be available to any other hook.

There are a number of functions that I didn't use in the mainhall example; use output_scripting to get the scripting reference, or get the version I just uploaded (http://fs2source.warpcore.org/temp/scripting.html).

If you're totally new to Lua, I recommend you check out this page on their wiki (http://lua-users.org/wiki/LuaTutorial), it has a number of tutorials to get you started.

Right now I'm a little concerned that this may be a little user-unfriendly. So if you have any suggestions/comments/questions, now would be the time to air them. As I add more functions it gets progressively harder to change the way things are set up.

Requests for functions that you're going to use is also good. Nothing motivates me (or most of the other coders, I suppose :p) more than seeing stuff get used. :nod:

The Build and Table (http://fs2source.warpcore.org/exes/latest/scriptdemo.zip)
Title: Re: New Main hall (Big pic)
Post by: kasperl on January 12, 2006, 01:21:08 pm
Could you post the tbl file as well? Or am I missing something?
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 12, 2006, 01:23:03 pm
Actually, it was something that I was missing (http://fs2source.warpcore.org/exes/latest/scriptdemo.zip).  :nervous:
Title: Re: New Main hall (Big pic)
Post by: Gast9991 on January 12, 2006, 02:44:34 pm
hi

nice idea :)

my first question is what i all possible can i rebuild the old Mainhall from Freespace 1
or is this to difficuld in few time i think i will test if i can redone the mainhall
i have an little question does it go to CVS or official build ?
Title: Re: New Main hall (Big pic)
Post by: Mr_Maniac on January 12, 2006, 03:40:26 pm
Well... The biggest problem in remaking the FS1 Mainhalls is the resolution..

The FS1 Mainhalls were 640x480 only...
There are High-Res renderers from the Mainhalls, but you would still have to resize the animated areas...
And if you do this, they look very blurry...

OR you would have to build the Mainhalls in a 3D-Program and render them... But that would take its time if you can even do it...

I think someone in this forum already tried to "convert" the mainhalls...
He succseeded, but like said, the animated parts are looking bad...
Title: Re: New Main hall (Big pic)
Post by: starfox on January 12, 2006, 03:47:59 pm
That looks fantastic !
There are few things I'd like to know.
First of all, is this new mainhall permanent addition to the SCP Arsenal or just an experiment ? *Hope it's going to stay*
Also, if this a permanent addition, it would be worthwile to get Shiblab working again...

Is it possible to prevent some ships (etc. escape pod) from showing up in the mainhall ?
Are there plans to recreate barracks and techroom etc, similar way the Mainhall is ?

Once again, magnifient work !  :yes:

Title: Re: New Main hall (Big pic)
Post by: WeatherOp on January 12, 2006, 04:00:59 pm
Hmmm, Hey Coolmon, maybe you need to inform Omni on this great piece of work. ;7 :yes:
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 12, 2006, 10:56:54 pm
Hmm...well, right now the limitations of this one are that keystrokes aren't working, I didn't put sounds in (though I just added some scripting sound support to CVS) animations aren't really supported. You can get away with animations by doing them manually (Drawing a bunch of images in sequence, using a variable to increment them over time).

So at this point an FS1 mainhall would be kind of difficult...

If you want to have the button click sound play, add the sd.playInterfaceSound into scripting.tbl in the next CVS build:
Code: [Select]
if ms.isButtonDown("Left") then
bs.setEvent(event)
gr.drawRectangle(x1, y1, x2, y2, false, false)
sd.playInterfaceSound("user_c.wav")
end

This mainhall is mostly a demo/test of the scripting of the scripting system at this point. I 'spose I could add it to the mediaVPs. ;) What's the "shiblab", btw? Did I break something? :nervous:

It's pretty easy to keep certain ships from showing up. I just added a getType() function to CVS for ship classes, so you could do this to keep escape pods from showing up:
Code: [Select]
if maybe_ship:isInTechroom() thento
Code: [Select]
if maybe_ship:isInTechroom() and not maybe_ship:getType()=="Escape pod" then
Barracks and techroom can probably be reworked with the proper scripting functions, if anyone wants to...for barracks, you'd just make a table entry like
Code: [Select]
$State: GS_STATE_BARRACKS_MENU
$Hook: [
--Put your barracks stuff here...just write "Barracks" for now
gr.drawString("Barracks", 5, 5)
]
and obviously fill it with data.
Title: Re: New Main hall (Big pic)
Post by: MetalDestroyer on January 13, 2006, 03:53:48 am
Hum interesting, we could put some animation into it.
As an exemple, you could put some ships moving in formation (escort cargo, fighter formation, etc..) and put some moving camera like X2 The Threat or X3.
Title: Re: New Main hall (Big pic)
Post by: starfox on January 13, 2006, 03:55:44 am
"Shiplab" is that screen, where you can examine weapons/Ship, their LOD:s and pretty much everything about the game models. This Feature was accessed via F1 in the mainhall.

Title: Re: New Main hall (Big pic)
Post by: knn on January 13, 2006, 04:19:07 am
Hum interesting, we could put some animation into it.
As an exemple, you could put some ships moving in formation (escort cargo, fighter formation, etc..) and put some moving camera like X2 The Threat or X3.

How about flybys of the Aquitane or the Psamtik or the Memphis, depending on which ship you're stationed on. Add a nice background, a few fighter escorts, a little camera movement and it'll look great.
Title: Re: New Main hall (Big pic)
Post by: Gast9991 on January 13, 2006, 04:24:24 am
hi WMCoolmon

yes rebuild in 3d and rerender it would be the perfect but it takes very much time
were can i get mainhalls in highres i only found bastion mainhall at descent network
but i cant find the galatea or aquitene (hope i write it true)
were can i get mainhalls from the others
the animation is not the bigest problem if it is in same format as the original mainhall background
the descent network pic isent it it have all doors open and they should be closed

thx for help
Title: Re: New Main hall (Big pic)
Post by: knn on January 13, 2006, 04:28:56 am
The Bastion is the only high res available, and this was used in FSPort. Aquitane and Psamtik already are 1024*768, but there is no higher res version. Galatea is unfortunately unavailable in high res, only 640*480
Title: Re: New Main hall (Big pic)
Post by: Mr_Maniac on January 13, 2006, 05:58:09 am
hi WMCoolmon

yes rebuild in 3d and rerender it would be the perfect but it takes very much time
were can i get mainhalls in highres i only found bastion mainhall at descent network
but i cant find the galatea or aquitene (hope i write it true)
were can i get mainhalls from the others
the animation is not the bigest problem if it is in same format as the original mainhall background
the descent network pic isent it it have all doors open and they should be closed

thx for help

Uhm... Like I said... You will ONLY find "static" High-Res-Renderers...
You WONT find High-Res-Animations!

Oh... And for the shiplab:
It still works... For me it never stopped working!
Just press F3 in th Mainhall...
Title: Re: New Main hall (Big pic)
Post by: starfox on January 13, 2006, 06:48:17 am
Strange...While using the new Mainhall, the Shiplab does not work me.
Title: Re: New Main hall (Big pic)
Post by: Admiral Nelson on January 13, 2006, 09:50:12 am
Thanks, WMCoolman, for the cool stuff.

I'm not sure how to determine what functions are available for use with this script. For instance, is there an available function to return a ship class by name, and not by index?  I guess it isn't clear to me what is being stored in the render_ship variable.  What would be interesting is to display a set ship based on the active mission in a campaign.  Thus one would need to be able to assign a ship class to be rendered based on the string name of the ship,  and also one would need a function to return the active mission within the active campaign.  Is this possible?

FWIW,  I can't choose the accept button in the campaign room in this build.
Title: Re: New Main hall (Big pic)
Post by: TrashMan on January 13, 2006, 04:27:56 pm
A animated 3D mainhall would be uber cool..

It could be done like in Freelancer. You basicly have a file that tells you where the camera is and which objects/background is htere and when they are doing.. Allso what special effects and similar are you using.

Similar to FREDing a mission, only far simpler and smaller.

If this could be implemented it would be more then cool.
Than one could make a model of a hangarbay and use it in there :D
Title: Re: New Main hall (Big pic)
Post by: aldo_14 on January 13, 2006, 06:07:54 pm
hi WMCoolmon

yes rebuild in 3d and rerender it would be the perfect but it takes very much time
were can i get mainhalls in highres i only found bastion mainhall at descent network
but i cant find the galatea or aquitene (hope i write it true)
were can i get mainhalls from the others
the animation is not the bigest problem if it is in same format as the original mainhall background
the descent network pic isent it it have all doors open and they should be closed

thx for help

The animation is the biggest problem as we don't have the anis at the correct resolution for 1024x768, only the lower res.  And - I think someone already mentioned this - we can't just simply resize those, as there will be a very clear difference in qualify between the animation and the higher res background behind it.  The descent network pic probably has all the doors open simply to show the complexity of the model, behind-door bits and all.
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 13, 2006, 07:26:14 pm
Ahh, the Lab isn't working because (like I said) when you put in a state hook right now, it totally overrides the state. So the usual code to process keystrokes in the mainhall is being ignored.

tb.getShipClass() gets a ship class by name, tb.getShipClassByIndex() is there mostly so that you can iterate through them (ie techroom list). render_ship is of type shipclass (http://fs2source.warpcore.org/temp/scripting.html#shipclass).

I've added massive numbers of Campaign scripting functions to CVS. Not only will you be able to get the next mission name, but the previous mission, or any mission in the campaign for that matter, the status of all of the events, goals, and any SEXP variables in that mission (assuming you played it).

See the Campaign Library (http://fs2source.warpcore.org/temp/scripting.html#cn) and Cmission object type (http://fs2source.warpcore.org/temp/scripting.html#cmission) for details. :pimp: It is much easier and faster to add stuff in scripting than in SEXPs. These are untested, but they were pretty simple to add.

Edit: By the way, I think you guys are underestimating the potential of this...you can change _any_ room using scripting. If you set $State: to "GS_STATE_BARRACKS_MENU", the normal main hall will return while the barracks will become the example.

You could almost make a techroom with the given functions; the only thing missing is a function to get the ship's description.

Incidentally, does anyone have a good name for a combined "Get/set" function? Right now I'd have "getName()" and "setName(new name)", but I could combine those into a "getsetName(new name)" where the function would always return the current name, but wouldn't change the name if it wasn't given.
Title: Re: New Main hall (Big pic)
Post by: Admiral Nelson on January 13, 2006, 08:13:57 pm
I'm guess the campaign stuff isn;t in the build you posted already?

Trying:

"Welcome to " .. cn.getDescription()

Blows up with:

LUA ERROR: [string "GS_STATE_MAIN_MENU"]:6: attempt to index global `cn' (a nil value)
------------------------------------------------------------------

LUA Stack:
------------------------------------------------------------------
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 13, 2006, 09:20:54 pm
Nope, it's in CVS so it should be in the next build.
Title: Re: New Main hall (Big pic)
Post by: kasperl on January 14, 2006, 04:31:47 am
For the getset, I'd say fetch or something like that, or just call it gs-ship-name(); or something like that.
Title: Re: New Main hall (Big pic)
Post by: Galemp on January 14, 2006, 11:25:24 pm
PSA: Don't worry about the FS1 main halls, they're done using the traditional mainhall codes and are currently being tested in the Freespace Port. There's a thread on it, in fact.
Title: Re: New Main hall (Big pic)
Post by: Nuke on January 15, 2006, 01:49:29 am
im still waiting for the most important feature of the scripting system to be implemented, a comprehensive manual.
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 15, 2006, 07:45:22 am
http://lua-users.org/wiki/LuaTutorial

http://fs2source.warpcore.org/temp/scripting.html

If you take a closer look at the table you'll see this:
Code: [Select]
#State Hooks
$State: GS_STATE_MAIN_MENU
...
#End

What I've done is I've enabled you to link into any Freespace state (Read: room, like the techroom, or the ready room) and have it execute whatever's in the $Hook: variable rather than what's on the room.

Granted in that example I was a little unclear. In that example, I've just hooked into the Mainhall.

Code: [Select]
"GS_STATE_MAIN_MENU", // 1
"GS_STATE_GAME_PLAY",
"GS_STATE_GAME_PAUSED",
"GS_STATE_QUIT_GAME",
"GS_STATE_OPTIONS_MENU", // 5
"GS_STATE_BARRACKS_MENU",
"GS_STATE_TECH_MENU",
"GS_STATE_TRAINING_MENU",
"GS_STATE_LOAD_MISSION_MENU", // 10
"GS_STATE_BRIEFING",
"GS_STATE_SHIP_SELECT",
"GS_STATE_DEBUG_PAUSED",
"GS_STATE_HUD_CONFIG",
"GS_STATE_MULTI_JOIN_GAME", // 15
"GS_STATE_CONTROL_CONFIG",
"GS_STATE_WEAPON_SELECT",
"GS_STATE_MISSION_LOG_SCROLLBACK",
"GS_STATE_DEATH_DIED",
"GS_STATE_DEATH_BLEW_UP", // 20
"GS_STATE_SIMULATOR_ROOM",
"GS_STATE_CREDITS",
"GS_STATE_SHOW_GOALS",
"GS_STATE_HOTKEY_SCREEN",
"GS_STATE_VIEW_MEDALS", // 25
"GS_STATE_MULTI_HOST_SETUP",
"GS_STATE_MULTI_CLIENT_SETUP",
"GS_STATE_DEBRIEF",
"GS_STATE_VIEW_CUTSCENES",
"GS_STATE_MULTI_STD_WAIT", // 30
"GS_STATE_STANDALONE_MAIN",
"GS_STATE_MULTI_PAUSED",
"GS_STATE_TEAM_SELECT",
"GS_STATE_TRAINING_PAUSED",
"GS_STATE_INGAME_PRE_JOIN", // 35
"GS_STATE_EVENT_DEBUG",
"GS_STATE_STANDALONE_POSTGAME",
"GS_STATE_INITIAL_PLAYER_SELECT",
"GS_STATE_MULTI_MISSION_SYNC",
"GS_STATE_MULTI_START_GAME", // 40
"GS_STATE_MULTI_HOST_OPTIONS",
"GS_STATE_MULTI_DOGFIGHT_DEBRIEF",
"GS_STATE_CAMPAIGN_ROOM",
"GS_STATE_CMD_BRIEF",
"GS_STATE_RED_ALERT", // 45
"GS_STATE_END_OF_CAMPAIGN",
"GS_STATE_GAMEPLAY_HELP",
"GS_STATE_END_DEMO",
"GS_STATE_LOOP_BRIEF",
"GS_STATE_NET_CHAT", // 50
"GS_STATE_LAB",
"GS_STATE_STORYBOOK"


You can also use the setEvent() command to change to a different room/state.

Code: [Select]
"GS_EVENT_MAIN_MENU",
"GS_EVENT_START_GAME",
"GS_EVENT_ENTER_GAME",
"GS_EVENT_START_GAME_QUICK",
"GS_EVENT_END_GAME",
"GS_EVENT_QUIT_GAME", // 5
"GS_EVENT_PAUSE_GAME",
"GS_EVENT_PREVIOUS_STATE",
"GS_EVENT_OPTIONS_MENU",
"GS_EVENT_BARRACKS_MENU",
"GS_EVENT_TRAINING_MENU", // 10
"GS_EVENT_TECH_MENU",
"GS_EVENT_LOAD_MISSION_MENU",
"GS_EVENT_SHIP_SELECTION",
"GS_EVENT_TOGGLE_FULLSCREEN",
"GS_EVENT_START_BRIEFING", // 15
"GS_EVENT_DEBUG_PAUSE_GAME",
"GS_EVENT_HUD_CONFIG",
"GS_EVENT_MULTI_JOIN_GAME",
"GS_EVENT_CONTROL_CONFIG",
"GS_EVENT_EVENT_DEBUG", // 20
"GS_EVENT_WEAPON_SELECTION",
"GS_EVENT_MISSION_LOG_SCROLLBACK",
"GS_EVENT_GAMEPLAY_HELP",
"GS_EVENT_DEATH_DIED",
"GS_EVENT_DEATH_BLEW_UP", // 25
"GS_EVENT_NEW_CAMPAIGN",
"GS_EVENT_CREDITS",
"GS_EVENT_SHOW_GOALS",
"GS_EVENT_HOTKEY_SCREEN",
"GS_EVENT_VIEW_MEDALS", // 30
"GS_EVENT_MULTI_HOST_SETUP",
"GS_EVENT_MULTI_CLIENT_SETUP",
"GS_EVENT_DEBRIEF",
"GS_EVENT_GOTO_VIEW_CUTSCENES_SCREEN",
"GS_EVENT_MULTI_STD_WAIT", // 35
"GS_EVENT_STANDALONE_MAIN",
"GS_EVENT_MULTI_PAUSE",
"GS_EVENT_TEAM_SELECT",
"GS_EVENT_TRAINING_PAUSE",
"GS_EVENT_INGAME_PRE_JOIN", // 40
"GS_EVENT_PLAYER_WARPOUT_START",
"GS_EVENT_PLAYER_WARPOUT_START_FORCED",
"GS_EVENT_PLAYER_WARPOUT_STOP",
"GS_EVENT_PLAYER_WARPOUT_DONE_STAGE1",
"GS_EVENT_PLAYER_WARPOUT_DONE_STAGE2", // 45
"GS_EVENT_PLAYER_WARPOUT_DONE",
"GS_EVENT_STANDALONE_POSTGAME",
"GS_EVENT_INITIAL_PLAYER_SELECT",
"GS_EVENT_GAME_INIT",
"GS_EVENT_MULTI_MISSION_SYNC", // 50
"GS_EVENT_MULTI_START_GAME",
"GS_EVENT_MULTI_HOST_OPTIONS",
"GS_EVENT_MULTI_DOGFIGHT_DEBRIEF",
"GS_EVENT_CAMPAIGN_ROOM",
"GS_EVENT_CMD_BRIEF", // 55
"GS_EVENT_TOGGLE_GLIDE",
"GS_EVENT_RED_ALERT",
"GS_EVENT_SIMULATOR_ROOM",
"GS_EVENT_EMD_CAMPAIGN",
"GS_EVENT_END_DEMO", // 60
"GS_EVENT_LOOP_BRIEF",
"GS_EVENT_CAMPAIGN_CHEAT",
"GS_EVENT_NET_CHAT",
"GS_EVENT_LAB",
"GS_EVENT_STORYBOOK" // 65
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 05:18:31 am
(http://fs2source.warpcore.org/temp/nevermind.jpg)

Replace:
Code: [Select]
--Draw stars background
gr.drawImage("starfield0001", 0, 0)

with

Code: [Select]
--Load the mission
if not load_mission then
load_mission_success = mn.loadMission("sm2-04.fs2")
load_mission = 1
end

--Make sure we actually loaded the mission
if load_mission_success then
mn.simulateFrame()
mn.renderFrame()
end

This build supports the mission loading stuff, but I've changed a few function names I used in the original example to clarify what they do, so you will probably get errors if you copy-paste:
http://fs2source.warpcore.org/exes/latest/C01142005.zip

I also updated this with the stuff I just put in CVS - http://fs2source.warpcore.org/temp/scripting.html
Title: Re: New Main hall (Big pic)
Post by: MetalDestroyer on January 16, 2006, 06:15:19 am
SO if I use the script for mod, I suppose it will work to ? Example, I load "battle_of_endor_mission" then I have the mission at screen right ?
Title: Re: New Main hall (Big pic)
Post by: TrashMan on January 16, 2006, 08:15:54 am
All fine and dand,y but how do you control the camera view in the into screen?
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 10:37:00 am
You should be able to use SEXPs as you would normally, so set-camera-position is your best bet. :nod:
Title: Re: New Main hall (Big pic)
Post by: MetalDestroyer on January 16, 2006, 01:11:17 pm
It didn't work. I have an error message about attempt to call method 'getCampaign' (a nil value).
And if I use the table for my Star Wars mod, Fs2 crash immediatly without proposing me to choose a pilot.

Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 02:15:52 pm
Quote
This build supports the mission loading stuff, but I've changed a few function names I used in the original example to clarify what they do, so you will probably get errors if you copy-paste:

"getCampaign" is now "getCampaignName"  :)
Title: Re: New Main hall (Big pic)
Post by: karajorma on January 16, 2006, 02:29:49 pm
Basically getting exactly the same problem. I got the same error the first times I ran it when I did the cut and paste replace from the top of this page it wouldn't even let me choose a pilot.

The older build you posted appears to work just fine though.
Title: Re: New Main hall (Big pic)
Post by: MetalDestroyer on January 16, 2006, 03:31:46 pm
I love it ^^. I'm wondering if it's possible in the current state to add a fix camera to one ship take randomly ?
Oh, I made a little demo (http://sam.sothi77.free.fr/videos/StarWars_MainHall.avi)

Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 03:58:55 pm
Kara: "getCampaign" needs to be "getCampaignName", I made the change because the function gives the name, rather than a campaign handle.
Title: Re: New Main hall (Big pic)
Post by: karajorma on January 16, 2006, 04:41:31 pm
Well it works now. It's hideously crippled by the amount of time it takes to load and parse the mission unfortunately though.

It also crashes whenever I go back to the main screen from the techroom.

Does look pretty cool though :)
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 05:46:47 pm
I finally sat down and wrote a guide (http://www.hard-light.net/wiki/index.php/FS2_Open_Lua_Scripting) in the wiki. I'm not nearly as happy with it as I am with my C article, but I figured I might as well post it anyways as a rough draft.

Problem: The article is based on what is in CVS, so almost none of the examples will work. Actually, since the stuff in CVS is broken atm, the examples won't work anyway. :p

I'm also still debating how to do some things - like switching the default stuff on and off - so the article doesn't mention it. Plus, I've never really sat down and gone through and learned Lua. The syntax has been incredibly easy and I've been able to understand stuff almost as soon as I see it, so there hasn't been any real need. OF course the Lua interface to embed stuff in programs is absolutely wreteched :ick: It's been a constant battle to keep things simple, and yet still working.

So, read through, offer comments/complaints/questions etc and I'll try to revise what's in there to fit what comes up.
Title: Re: New Main hall (Big pic)
Post by: karajorma on January 16, 2006, 06:21:17 pm
Seems fairly clear.

What I don't see in there is any form of SEXP/Scripting integration. How can I call a script from a SEXP? Conversely how can I get a return value from a script and use it in a SEXP/store it in a mission variable?

Couple of other things.

a) Why is the scripting.tbl so called? Surely it's a script not a table and should be named to reflect that.
b) Can we have a seperate folder for scripts rather than cluttering up the tables folder?
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 08:26:28 pm
a) It actually is a table, just with special variables. As it is, I've got a basic 'hook' thing set up, meaning that it's a matter of two C++ function calls to add in a hook. Hooks can be added anywhere one wants, be it ships.tbl or scripting.tbl. I just have everything in scripting.tbl because it's faster & easier to test stuff on the main screen than to load a mission and wait for a ship to warp in or out.

b) Done, this was something half-bugging me during documentation anyways. Next CVS build (scripting is fixed in it, btw) you'll be able to do something like this:
Code: [Select]
#State Hooks
$State: GS_STATE_MAIN_MENU
$Hook: [[mainhall.lua]]
+Override: YES
#End

Where mainhall.lua is a scripting file with the luascript. If you feel inclined you can compile it by running luac on it (http://luaforge.net/frs/download.php/788/lua5_0r2_Win32_bin.tar.gz), this should help load times for extremely long scripts.



SEXP/Scripting integration is an interesting situation. The easiest way is probably making two SEXPs, script-eval-number and script-eval-string, which return a number and string respectively. This probably won't be so bad, since I can hide the "return" part so you'd just have to write in "Ship.Species.Name" or whatnot.

It's easy enough to deal with variables from scripting, but what I'd like to do is have it be possible with an array. IE:
Code: [Select]
mn.Variables["High scorer"] = high_scorer_ship.Namewould set the SEXP variable "High scorer". Unfortunately I'm having some problems with Lua behaving properly when I try to do something like that.

gr.drawText will be gr.drawString in the next CVS build
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 08:34:42 pm
How are people with library names being only two letters, by the way? I've been doing it that way to reduce clutter, but if it makes the learning curve too steep I can easily change them to "Graphics" "Mouse" and so on relatively easily.
Title: Re: New Main hall (Big pic)
Post by: karajorma on January 16, 2006, 08:37:25 pm
While I'm at it a post on Game Warden raised an interesting question. Can we use this to finally get rid of the need to bundle the engine with the (copywrited) :v: interface art?
Title: Re: New Main hall (Big pic)
Post by: taylor on January 16, 2006, 10:18:34 pm
If you feel inclined you can compile it by running luac on it (http://luaforge.net/frs/download.php/788/lua5_0r2_Win32_bin.tar.gz), this should help load times for extremely long scripts.
Just remember to never distribute the compiled scripts unless you also distribute uncompiled versions.  Compiled scripts are platform specific (on a 32-bit vs. 64-bit basis, but not Linux/Windows/OSX specific).
Title: Re: New Main hall (Big pic)
Post by: Goober5000 on January 16, 2006, 10:54:17 pm
How are people with library names being only two letters, by the way? I've been doing it that way to reduce clutter, but if it makes the learning curve too steep I can easily change them to "Graphics" "Mouse" and so on relatively easily.

Verbosity FTW.

On the same subject, is there any reason why modular tables can't do the same thing?  For example, checking for -ships.tbm at the same time as -shp.tbm.
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 16, 2006, 11:14:21 pm
No particular reason, mostly I did it that way so it was less likely for filelength problems to come up.
Title: Re: New Main hall (Big pic)
Post by: TrashMan on January 17, 2006, 07:44:55 am
Wouldn't it be better if insted of campaign mission it loads a default intro mission?

The one where ships just follow specific waypoint and fly in circles...so that there's allways things happening on hte screen.

If you load a mission (for instance the blockade misison as above) then you'll see some beam cannon ownage and after the ships is destroyed nothing would happen. Besides, a defaultintro mission would be smaller, load faster and should be less ofa resource hog.
Title: Re: New Main hall (Big pic)
Post by: Nuke on January 17, 2006, 08:11:50 am
http://lua-users.org/wiki/LuaTutorial

http://fs2source.warpcore.org/temp/scripting.html

well its a start. first thing i want to do when i figure it out is swap out some hud gauges with new ones. you seem to have all the rendering functions nessicary to make my own gauges but i need get functions for hud gauge data as well as a means to override the drawing of a built in hud gauge with my own use of rendering functions.
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 17, 2006, 10:08:36 am
Well, as of now you can probably swap out the player shield gauge, weapons gauge, escort gauge, wingmen gauge (If you're clever and do some string concatenation), and mission time gauge (Inaccurately).

OTOH I'm thinking of seeing if I can't turn some of those into arrays.

Note that in 1/17 CVS, "slf" will give you the data for the object currently being viewed from, and "plr" will give you the player object.
Title: Re: New Main hall (Big pic)
Post by: Nuke on January 17, 2006, 02:55:05 pm
of course the big one i want, lead indicator position.
Title: Re: New Main hall (Big pic)
Post by: Bobboau on January 17, 2006, 07:39:02 pm
so with this could we currently set up a animated 3d interface screen?
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 17, 2006, 08:14:25 pm
Currently, no. I've only exposed a very small part of the graphics API; you'd have to expose the commands to set up lights, render models, and so on to really have a 3D interface.
Title: Re: New Main hall (Big pic)
Post by: Nuke on January 18, 2006, 12:41:58 am
heres another idea for you

turret control override :D
Title: Re: New Main hall (Big pic)
Post by: neoflame on January 18, 2006, 07:15:05 pm
Startup time is a bit slow, and newer CVS builds seem to lag a bit, and I'm a FRED nub. But it's still quite purdy:
(http://img37.imageshack.us/img37/6214/fs2omenu9av.th.png) (http://img37.imageshack.us/my.php?image=fs2omenu9av.png)
Title: Re: New Main hall (Big pic)
Post by: starfox on January 19, 2006, 04:09:25 am
More ideas/suggestions...
Is it possible to use your own music tracks on the new mainhall ?
(IE, having a hefty battlescene would certainly use a good musical score...)

Title: Re: New Main hall (Big pic)
Post by: MetalDestroyer on January 19, 2006, 06:09:05 am
I think, it's better if the scene (mission) could play all the sound (beams, guns, engines, explosion, etc..) + the dynamic music instead of using the default mainhall music.

Or at least, make a way to change view in real time at any moment.
Title: Re: New Main hall (Big pic)
Post by: starfox on January 19, 2006, 07:30:44 am
Some kind of "spectator mode" would also be cool, you know the, ability to move around freely...
Though, something similar can achieved trough FREDding, though the movement would not be completely free.....
Title: Re: New Main hall (Big pic)
Post by: Grug on January 19, 2006, 07:53:38 am
Nice WMCoolmon. Very nice. :D ^_^

*Awaits next main cvs build* :)
Title: Re: New Main hall (Big pic)
Post by: Cobra on January 19, 2006, 01:54:39 pm
actually, it works with the current CVS builds. :D

but, i'm a little confused with the scripting. i was able to change the incompatible lines, but i can't make custom screens like neoflame's. (i have absolutely no experience in scripting of any kind. :p)
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 19, 2006, 02:18:25 pm
Code: [Select]
mn.loadMission("sm2-04.fs2")
Look for a line like that, and change the mission filename to whatever mission you want to use.

Just in CVS: A vector object, along with operators and some functions for DotProd() and CrossProd(). Also, you can now use library names ("Graphics") as well as shortnames ("gr").
Title: Re: New Main hall (Big pic)
Post by: Cobra on January 19, 2006, 02:51:32 pm
i don't see that line anywhere. :wtf:
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 19, 2006, 04:15:58 pm
Do a little searching in this thread.
Title: Re: New Main hall (Big pic)
Post by: Cobra on January 19, 2006, 04:55:03 pm
it was right under my nose the whole time. thanks. :D
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 19, 2006, 04:58:29 pm
Current hooks:
Current scripting hooks are:
Code: [Select]
#Global Hooks
$Global: ;;Executes every single time a frame is displayed
$Splash: ;;Executes once, when the splash screen is displayed (Override disables default splash). Override disables default splash.
$GameInit: ;;Executes after everything has been loaded, but the splash screen is still displayed. An ideal spot to put mn.loadMission(). Override does nothing.
$HUD: ;;Executes every frame that the HUD is displayed. Override disables Game HUD
#End

#State Hooks
$State: ;;Can be any state. Look up GS_state_text in gamesequence.cpp for the full list. Override disables normal FS2 state.
#End

gamesequence.cpp (http://fs2source.warpcore.org/cgi-bin/cvsweb/cvsweb.cgi/fs2_open/code/gamesequence/gamesequence.cpp?rev=2.9&content-type=text/x-cvsweb-markup)

I've added some functions to CVS as well, here's the list: http://fs2source.warpcore.org/temp/scripting.html
Operator support is also in, so vectors can be modified (ie object.Position + object.Velocity will get a ship's position next frame, assuming its velocity doesn't change).

drawImage is broken right now, it's in the process of being updated by taylor to support the extra arguments. :nod:
Title: Re: New Main hall (Big pic)
Post by: Cobra on January 19, 2006, 05:21:24 pm
just when i thought of something cool for the draw-image. :lol:
Title: Re: New Main hall (Big pic)
Post by: Cobra on January 19, 2006, 07:11:34 pm
ooookay, i pressed the middle mouse button 3 times and i got this

LUA ERROR: [string "GS_STATE_MAIN_MENU"]:50: attempt to index global `maybe_ship' (a nil value)
------------------------------------------------------------------

LUA Stack:
------------------------------------------------------------------
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 19, 2006, 10:04:31 pm
That's probably a bug on my part.

Find the section of code like this:
Code: [Select]
if (not render_ship) or force_random then
render_ship = tb.getShipClassByIndex(1)
num_ship_classes = tb.getNumShipClasses()
for count=1,num_ship_classes do
maybe_ship = tb.getShipClassByIndex(ma.getRandomNumber(1, num_ship_classes))
if maybe_ship:isInTechroom() then
render_ship = maybe_ship
break
end
end
end

You'll notice that the 0s are now 1s...this is because Lua expects everything to start at 1, rather than fs2, which generally expects it to start at 0.
Title: Re: New Main hall (Big pic)
Post by: Cobra on January 19, 2006, 11:26:12 pm
pressed it ten times and no problems. :D
Title: Re: New Main hall (Big pic)
Post by: neoflame on January 21, 2006, 02:05:47 pm
mn.unloadMission doesn't seem to work. Pertinent Lua code is:
Code: [Select]
--Load the mission
if not load_mission then
mn.unloadMission()
load_mission_success = mn.loadMission("MenuScene-01.fs2")
load_mission = 1
end
--Make sure we actually loaded the mission
if load_mission_success then
mn.simulateFrame()
mn.renderFrame()
end

--Function to handle a section every frame
section = function(name, event, num)
--Setup color and margin for this resolution
margin = gr.getScreenHeight()/6
gr.setColor(0, 255, 0)

--Get corner coordinates for this box
x1 = gr.getScreenWidth()-180
y1 = margin*num+20
x2 = gr.getScreenWidth()-21
y2 = margin*num+55

--When the mouse is OVER this section...
if ms.getX() > x1 and ms.getX() < x2 and ms.getY() > y1 and ms.getY() < y2 then
--Draw the dark green insides
gr.setColor(0, 96, 0)
gr.drawRectangle(x1, y1, x2, y2, true, false)

--Draw the little target lines now
gr.setColor(0, 255, 0)
x = x1+(x2-x1)/2
y = margin*num

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

--Bottom target line
y = margin*num+65
gr.drawLine(x, y, x, y+15)

--Left target line
x = gr.getScreenWidth()-200
y = margin*num+40
gr.drawLine(x, y, x+15, y)

--Right target line
x = gr.getScreenWidth()-16
gr.drawLine(x, y, x+15, y)

--Handle the button click
if ms.isButtonDown("Left") then
bs.setEvent(event)
gr.drawRectangle(x1, y1, x2, y2, false, false)
sd.playInterfaceSound("user_c.wav")
load_mission = 0
end
end

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

--Color should always be pure green, so I'll skip setting the color for the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getTextWidth(name) ) / 2, margin*num+35, false)
end

section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 0)
section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 1)
section("Tech Room", "GS_EVENT_TECH_MENU", 2)
section("Barracks", "GS_EVENT_BARRACKS_MENU", 3)
section("Options", "GS_EVENT_OPTIONS_MENU", 4)
section("Exit", "GS_EVENT_QUIT_GAME", 5)
If you play a mission and then leave it somehow, going back to the main menu, you will still be "in that mission". I tried to fix this by making the intro level reload upon leaving the main menu. Setting load_mission=0 upon entering a different section (e.g. Techroom) caused FS2 to crash upon returning; therefore, I then tried to add an unloadMission before the loadMission thinking that the problem was that I had a loadMission statement with a mission already loaded. Then I got the error:
Code: [Select]
LUA ERROR: [string "GS_STATE_MAIN_MENU"]:3: attempt to call field `unloadMission' (a nil value)
------------------------------------------------------------------

LUA Stack:
------------------------------------------------------------------
Using a new reload_mission flag to cause unloadMission to fire only on returning to the main hall, and not on first startup (before the mission's loaded), did not resolve the problem.
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 21, 2006, 02:08:09 pm
You might not have a build that supports it. Use -output_scripting and see if there's an unloadMission() in your build.

If not grab this one: http://fs2source.warpcore.org/temp/particled.zip
Title: Re: New Main hall (Big pic)
Post by: neoflame on January 21, 2006, 02:21:09 pm
-output_scripting dumped nothing about scripting into fs2.log. :confused: Right now I'm using redmenace's optimized CVS (01/16); the link you gave me crashes upon trying to into the main menu:
Code: [Select]
Assert: be->handle == handle
File: c:\documents and settings\administrator\my documents\my source code\fs2_open\code\bmpman\bmpman.cpp
Line: 2552
[This filename points to the location of a file on the computer that built this executable]

Call stack:
------------------------------------------------------------------
    fs2_open_d-opt-cvs.exe 0048cdc5()
    fs2_open_d-opt-cvs.exe 00401da0()
    fs2_open_d-opt-cvs.exe 00613d53()
    fs2_open_d-opt-cvs.exe 00770ffd()
    fs2_open_d-opt-cvs.exe 00774ec2()
    fs2_open_d-opt-cvs.exe 00771660()
    fs2_open_d-opt-cvs.exe 006ff17a()
    fs2_open_d-opt-cvs.exe 00770986()
    fs2_open_d-opt-cvs.exe 00771cc4()
    fs2_open_d-opt-cvs.exe 006ff0ef()
    fs2_open_d-opt-cvs.exe 0058c06e()
    fs2_open_d-opt-cvs.exe 004291e7()
    fs2_open_d-opt-cvs.exe 006d36c8()
    fs2_open_d-opt-cvs.exe 00426cd4()
    fs2_open_d-opt-cvs.exe 007b512a()
------------------------------------------------------------------
Incidentally, that was the fastest response I've ever seen. :p
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 21, 2006, 03:00:35 pm
Well, I wouldn't try unloading a mission before it's loaded...try removing that, so that it only unloads the mission if it was loaded successfully.

Edit: I ran your script, minus the mission, and it seemed to work fine except that I changed 'bs' to 'ba' in the more recent builds, for obvious reasons. :p
Title: Re: New Main hall (Big pic)
Post by: neoflame on January 21, 2006, 04:32:05 pm
I changed the first bit to:
Code: [Select]
--Load the mission
if not load_mission then
if reload_mission then
mn.unloadMission()
reload_mission = 0
end
load_mission_success = mn.loadMission("MenuScene-01.fs2")
load_mission = 1
end
and the part in section() that handles clicking to:
Code: [Select]
--Handle the button click
if ms.isButtonDown("Left") then
mn.unloadMission()
ba.setEvent(event)
gr.drawRectangle(x1, y1, x2, y2, false, false)
sd.playInterfaceSound("user_c.wav")
reload_mission = 1
load_mission = 0
end
Still no luck; now when I click a section the game crashes with the same error. Moving the mn.unloadMission() in section() around doesn't help.
Title: Re: New Main hall (Big pic)
Post by: WMCoolmon on January 21, 2006, 07:21:47 pm
You shouldn't call unload_mission twice, which is what will end up happening...first the mission will be unloaded and reload_mission will be set to 1, you'll enter the section, then come back to the mainhall. Reload_mission will be 1, so the second unloadMission call will execute, and reload_mission will be set to 0.