Author Topic: Scripting Questions  (Read 1698 times)

0 Members and 1 Guest are viewing this topic.

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:
Code: [Select]

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 without having to have to make SEXP's and variables for each mission. 


           
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline Axem

  • 211
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).

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
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)

Quote
2. Can you create the explosions effects using scripts (same as the sexp version)?

Not directly.

Quote
3. Can you get the offset of origin of subsystems with it?

Yes. For example:

Code: [Select]
offset = ship['engine01'].Position - ship.Position
Quote
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)

Quote
5. Are arrays supported?

Yes

Quote
This is what I'm trying to do in pseudocode:
Code: [Select]

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 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.

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.
« Last Edit: December 22, 2006, 08:52:16 pm by WMCoolmon »
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
hey, would it be remotely posable to be able to define new variables for ships (ect)?
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
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
That's cool and ....disturbing at the same time o_o  - Vasudan Admiral

"Don't play games with me. You just killed someone I like, that is not a safe place to stand. I'm the Doctor. And you're in the biggest library in the universe. Look me up."

"Quick everyone out of the universe now!"

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
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.
-C

  

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
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 script for example (wont work with WMCs new scripting without modifications though).
Do not meddle in the affairs of coders for they are soggy and hard to light