Help needed with setting up Puzzle (lua based)

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Help needed with setting up Puzzle (lua based)

Post by Sky_216 »

Well, once again I need help with lua stuff for campaign.
Here's what I'm trying to achieve:

For the 'commando' part of my campaign, I'm trying to set up a 'puzzle with four high intensity scanners. They can't be passed unless you hack the corresponding terminal.
There are four scanner arrays. Each one consisits of prop objects, a damageregion (eg 'scanner1'), a bunch of effect objects (1 for each beam, eg called 's1_b1', 's1_b2', 's1_b3' , 's1_b4', 's1_b5').

Each scanner has a terminal that when 'hacked' (actually destroyed with a fusion cutter), disables it - removes the s1_b1-5 effect objects and the damageregion.

The tricky bit is getting the 'puzzle' part to work - only one scanner can be disabled at any one time. So hacking a terminal not only disables the scanner connected to it, but also respawns (if possible) all the other scanner's effect objects and regions.

Anywy, any help on the lua coding I should use (and even how to 'nest' it properly, I'm not very good at that) would be appreciated.
Grev
Hoth Battle Chief
Hoth Battle Chief
Posts: 3132
Joined: Sun Dec 09, 2007 11:45 pm
Projects :: No Mod project currently.
Games I'm Playing :: Minecraft
Location: A Certain Box Canyon

Re: Help needed with setting up Puzzle (lua based)

Post by Grev »

I'm using a similar type of code for a gamemode I'm making, and while I don't have the script on hand, look at the space assault scripts, they will have the code for disabling something when an object it destroyed: (like the ngines inside and outside a capital ship).
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Help needed with setting up Puzzle (lua based)

Post by Maveritchell »

Rather than write it out for you, I'll suggest that you download my Spira script. It's got a lot of examples for different types of puzzle setups (and I refer to it regularly, too). I uploaded it with a lot of other assets from Spira, and it can be found in the Assets forum; if you prefer to just download the script (I know you're on a download budget), use this link:
http://files.filefront.com/FFXg+elilua/ ... einfo.html
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Help needed with setting up Puzzle (lua based)

Post by [RDH]Zerted »

Maveritchell wrote:...my Spira script...
Wow, 5820 lines. Programming Tip: When you find yourself copying and pasting code, you can generally change your design slightly (like by using tables) and remove all the copied code.

The best way to design your puzzle is to use tables of all things that change and functions that do one type of action for a given table. However without knowing exactly how you want everything, that is hard to correctly describe over a few forum posts.

Instead, create functions for everything you want to do. You would have a function to disable scanner 1, enable scanner 1, disable scanner 2, etc... The disable/enable scanner functions would change all of that scanner's effects. (that table method would be like having only one function to disable a scanner and only one to enable a scanner. Then you would pass the table of scanner 2 into the enable scanner function to enable scanner 2. But i'm not telling you to do it that way.)

At the next 'higher level', create a function that takes the 'name' of a scanner. When you call this function, it should call the functions to enable all the other scanners and the function to disable the named scanner.

At the next 'higher/top level', you have your event call-back. When a scanner object is destroyed, call the 'lower function' with the name of the scanner that was destroyed.

Note: The 'higher level' and 'lower level' are just ideas and have no effect on code placement within the script file itself.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Help needed with setting up Puzzle (lua based)

Post by Maveritchell »

[RDH]Zerted wrote:
Maveritchell wrote:...my Spira script...
Wow, 5820 lines. Programming Tip: When you find yourself copying and pasting code, you can generally change your design slightly (like by using tables) and remove all the copied code.
I know it's inefficient code - at the time, though, it was easier. You'd know better than I, but as far as learning goes, I feel that it was easier to learn how to actually make happen what I wanted to happen first, and then learn how to make my code less bulky second.

However, I like to use that fat script as a demonstration because all the code is written out - I think it makes reading single sections at a time easier (if perhaps more difficult to find).
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Help needed with setting up Puzzle (lua based)

Post by Sky_216 »

Thanks Mav, didn't realise you released the script. And you're right, it'll help more than you spelling out what I should do (help's me learn + saves you time). Thanks again.
Post Reply