Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Scooby_Doo on December 22, 2006, 06:25:15 pm
-
Ok I've got quite a few questions about scripting.
1. Can scripts be attached to individual ships (or at least individual classes)? and can those scripts be fired at specific times, like on ship death or hitpoints left?
2. Can you create the explosions effects using scripts (same as the sexp version)?
3. Can you get the offset of origin of subsystems with it?
4. Are variables in a script attached to specified ships (i.e. their members of the ships class)
5. Are arrays supported?
This is what I'm trying to do in pseudocode:
OnShipCreated:
// ExplodeSubSystem is a small untargettable subsystem that determines where explosion will occur
ExplosionPointX[0] = GetSubSystemXPos (ExplodeSubSystem0)
ExplosionPointY[0] = GetSubSystemYPos (ExplodeSubSystem0)
ExplosionPointZ[0] = GetSubSystemZPos (ExplodeSubSystem0)
// Repeat for any additional ExplodeSubSystem subsystems
end
OnShipDestroyed:
while (not (end of mission))
WhichOne = random (0, Number of ExplodeSubSystems -1)
DoExplosion (ExplosionPointX[WhichOne], ExplosionPointY[WhichOne], ExplosionPointZ[WhichOne])
Sleep For Random Time
end
end
I'm trying to implement this http://www.hard-light.net/forums/index.php/topic,43796.0.html (http://www.hard-light.net/forums/index.php/topic,43796.0.html) without having to have to make SEXP's and variables for each mission.
-
Pretty much everything you've said can be done, but the explosion part would be tricky. Making the explosion effect appear would be easy, but doing all the damage effects would be the tough part.
You could do it with the current scripting system (available in the 3.6.9s), but if you can hold out for a bit, I'd use the new system (due for the CVS soon), because that includes specific ship and status hooks (doing exactly what #1 asks).
-
Ok I've got quite a few questions about scripting.
1. Can scripts be attached to individual ships (or at least individual classes)? and can those scripts be fired at specific times, like on ship death or hitpoints left?
Yes, that's exactly what conditional hooks aim to do. Given a series of conditions (Mission, ship class, ship, etc) you can define a series of hooks that are triggered by actions (Collisions, warpout, and death so far)
2. Can you create the explosions effects using scripts (same as the sexp version)?
Not directly.
3. Can you get the offset of origin of subsystems with it?
Yes. For example:
offset = ship['engine01'].Position - ship.Position
4. Are variables in a script attached to specified ships (i.e. their members of the ships class)
Yes and no. The scripting system currently defines a set of variables for ships; however, you can only modify or use those variables, you cannot add news ones. (Although there is nothing stopping you from making an array to store the variables instead)
5. Are arrays supported?
Yes (http://lua-users.org/wiki/TablesTutorial)
This is what I'm trying to do in pseudocode:
OnShipCreated:
// ExplodeSubSystem is a small untargettable subsystem that determines where explosion will occur
ExplosionPointX[0] = GetSubSystemXPos (ExplodeSubSystem0)
ExplosionPointY[0] = GetSubSystemYPos (ExplodeSubSystem0)
ExplosionPointZ[0] = GetSubSystemZPos (ExplodeSubSystem0)
// Repeat for any additional ExplodeSubSystem subsystems
end
OnShipDestroyed:
while (not (end of mission))
WhichOne = random (0, Number of ExplodeSubSystems -1)
DoExplosion (ExplosionPointX[WhichOne], ExplosionPointY[WhichOne], ExplosionPointZ[WhichOne])
Sleep For Random Time
end
end
I'm trying to implement this http://www.hard-light.net/forums/index.php/topic,43796.0.html (http://www.hard-light.net/forums/index.php/topic,43796.0.html) without having to have to make SEXP's and variables for each mission.
Besides the lack of the explosion function, the other things stopping you from doing this would be that the On Ship Destroyed hook would trigger only once, as scripting is on the same thread as the rest of FS2_Open. So rather than having the explosions actually occur in that hook, you'd need to store the data in a variable that would be used to create the explosions in another hook, that would trigger regardless of the ship's status (eg dead or alive) and would depend solely on the variable.
The other thing is that the On Ship Destroyed hook doesn't provide a variable to the ship actually getting destroyed. You could of course get the variable yourself by simply indexing mn.Ships[] with the ship's name (eg mn.Ships['Alpha 1']).
All the new scripting stuff is parked in this build (http://www.hard-light.net/forums/index.php/topic,44021.0.html).
EDIT: Made a change to the On Death Hook so that it will provide a "Self" and "Killer" variables to the On Death hook. Asteroid and debris death will provide a "Self" variable to the On Death hook. This is not in the aforementioned build, but will be included in future builds.
-
hey, would it be remotely posable to be able to define new variables for ships (ect)?
-
Well everything sounds good except the variables and the looping. Don't worry Axem, this is more of a proof of concept for the moment.
Heres a simple mission that demonstates the effect i'm looking for, only using SEXP's
http://www.wcsaga.com/~team/Scooby/Custom_Mod/Explosions.fs2 (http://www.wcsaga.com/~team/Scooby/Custom_Mod/Explosions.fs2)
-
hey, would it be remotely posable to be able to define new variables for ships (ect)?
It's partly in...it uses a separate table of tables in the handle's metatable for each ship ID, if you add the object index to the Set() function. (Should also work for any other FS2-defined Lua object type)
However, the problem is that since ships use the indexer to access their subsystems, it's encountered before the user-defined function table gets referenced. I don't remember why I didn't simply bump that check in front of the indexer.
It also lacks a way to delete ship variables as ships die.
-
You can always create new 'table' files (that is simple text files) with additional data for the ships and read the info from there with lua. You would just have to make a 'parsing function' for it to be read properly.
Also you can quite easily make visible effects for the explosions.. That is lua doesnt (currently) allow for creating new explosions - except in perhaps some very hackish ways (like spawning a bogus ship and then killing it) - but it allows for creating in game particle effects (2d bitmaps, even animations) so you can get the graphical glory of explosions without the actual damage or anything. See my Death Flash (http://www.hard-light.net/wiki/index.php/Script_-_Death_Flash) script for example (wont work with WMCs new scripting without modifications though).