Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: WMCoolmon on January 05, 2006, 05:40:59 am
-
Another unimaginatively named idea from the mind of WMCoolmon :D.
This is something I've had in the back of my mind for a few weeks...but only really fleshed it out while I was in the shower tonight (If you'll pardon the pun :p)
First the TBL (timescript.tbl?)
#Timescripts
$Name: Example
;;Immediately show "Example script" for 10 seconds
0: [
--A lua script, note my double-dash comment.
--We can do some stuff here with scripting. For example:
grpc.text("Example script",0,0)
]
+Duration: 15 ;;Show text for 15 seconds
;;After 10 seconds of script activation...
10: [grpc.line(0,0,640,480)]
+Duration: 4.5 ;;...draw a line for 4.5 seconds
;;After 20 seconds of script activation...
20: [grpc.text("Goodbye!", 0, 0)]
+Duration: 2 ;;Say goodbye for 2 seconds (Don't seem too desperate!)
$End ;;End this one, so we can begin another
Pretty self-explanatory. Would obviously require more scripting functions to be really useful, however, the fun thing is that you could call a Timescript from a SEXP or a script relatively easily.
+Duration makes it extremely useful, because you can actually do graduated movement, assuming I pass a "tse" variable for the current timescript entry progress. (And assuming a setshipposition thingamajigger gets implemented).
;;Moves a ship forward from starting position at 15 m/s, presumeably in global coords.
15: [ShipHandle.setPosition(ShipHandle.getPosition("X"),ShipHandle.getPosition("Y"),ShipHandle.getPosition("Z")+15*fs2.getFrameTime()]
Even more fun...after thinking about this a bit, I've realized that the Lua VM probably does store global variable values between frames. So if, say, you made an animation script for a ship to do a jig...you could in theory make the TimeScript apply for multiple ships by setting a global ship handle variable used in the TimeScript before calling the TimeScript.
Now some data structs that could be improved on to allow multiple executions of the same timescript at once:
class TimescriptLib
{
private:
std::vector<Timescript> scripts;
public:
scriptid AddScript(script);
void ActivateScript(scriptid);
void DoFrame();
};
typdef struct Timescript
{
float activation_time; //Mission time of activation
int current_entry;
//"Static"
char name[NAME_LENGTH];
std::vector<TimeEntry> entries;
};
typedef struct TimeEntry
{
//Reusable variables
float activation_time; //This is relative to script activation time (ie 10 s past, rather than mission 2:10
float remaining_time;
//"Static" variables
float duration;
script_hook action;
};
Hopefully I'll think up a better name before I implement it. :p
-
essentially this is like the little timer control in vb that got me through oh so many programming assignments back in highschool:D
-
Is there a good, comprehensive refrence for the LUA implementation in FS open?
-
What purpose would this serve? I see what it oes, but I don't see the use...
-
I was mostly thinking for movies. It's omewhat cleaner to do gradual movement over a number of frames, since you don't have to have global variables to keep track of when the series of actions started. You could also use something like this to do a looping animation with a complex series of steps, assuming you had the functions.
Is there a good, comprehensive refrence for the LUA implementation in FS open?
The command-line "-output_scripting" will make an HTML file with all classes and functions. Right now there's only one scripting hook, in scripting.tbl, using the field $Global:, this will be executed every time the screen is drawn to.
scripting.tbl
$Global: [
grpc.drawLine(0,0,639, 479)
]
This would draw a diagonal line across the whole screen in 640x480, or just the upper-left in 1024x768 or higher, coordinates are in pixels from the upper left.
Other than that, not rly, at least for modders.
-
you need to ba able to run timed functions to make hud gauges and complicated submoel animations i think.