Author Topic: [Script] Multihex Items  (Read 6289 times)

JovankaB

  • Guest
[Script] Multihex Items
« on: January 19, 2013, 12:15:18 am »
As everyone knows, large doors are a bit strange because they open and close only one hex. So I wrote a module implementing multihex items to solve that. Here is an example (on the screenshots you can notice how FOV line changes when the gate is closed and opened):



I decided to dedicate it to public domain, maybe someone will use it. Here are all the files you need:
https://dl.dropbox.com/u/3880395/2238/multihex.fos
https://dl.dropbox.com/u/3880395/2238/multihex_h.fos
https://dl.dropbox.com/u/3880395/2238/multihex_data.fos

How to add it to your server:

Add multihex.fos to scripts.cfg:
Code: [Select]
@ server module multihex # Multihex items
You also have to make new item proto, without any flags and with blank.frm graphics and define it as PID_MHEX. PID_MHEX items, later called mHexes, are used to mark additional hexes of the multihex items which are lying on the ground.

To define position and behavior (item flags) of the mHexes for a proto you should make an array in multihex_data.fos and array pointer as a return value in MHexData function in the same file. There are some examples (for VC and BH gates), also further explanation of the array format is inside the file.

You might need this too, these door PIDs are not defined in SDK but used in the examples:
Code: [Select]
#define PID_VAULT_CITY_GATE                 (3337)
#define PID_CORRUGATED_GATE                 (3818)

And probably these 2238 defines from _time.fos:
Code: [Select]
#define ELAPSED_TIME              (__FullSecond)
#define AFTER #(x)                (ELAPSED_TIME+(x))

To make items actually spawn mHexes you have to call MultihexSpawned when the item is created and MultihexDeleted when the item is deleted (you can use multihex@_Init for this) and that's all. Well, almost.

Of course if you have items like door, blocking won't change magically. Fortunately mHexes have two possible states (flags) which you can switch with MultihexOpen and MultihexClose. So if you want to use this for door items you need to add:
Code: [Select]
if (IsMultihex(item)) MultihexClose(item);and
Code: [Select]
if (IsMultihex(item)) MultihexOpen(item);in a proper place, for SDK that probably would be somewhere in SwitchState function in lockers.fos. You can also call IsMultihexBlocked to check if whole doorway isn't blocked and prevent closing it (but watch out for hex blocking objects near door - maps may require update).

Because multihex items are in fact multiple items (parent item and the mHexes) there is also a function which protects them to some extent from accidental GM/admin abuse (for example GMs might be able to pick up items which can't be picked up by players). To enable this protection, call GuardMultihexMove function inside critter_move_item, in SDK that would be:

Code: [Select]
#ifdef __SERVER
import void GuardMultihexMove(Item& item, uint8 fromSlot, uint8 toSlot) from "multihex";
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Call on critter item moved.
void critter_move_item( Critter& cr, Item& item, uint8 fromSlot )
{
    uint8 toSlot = item.CritSlot;
    GuardMultihexMove(item, fromSlot, toSlot);

One last note - mHexes call ITEM_EVENT_WALK of the parent item when you walk on them. Which is pretty cool, you can for example have radioactive goo item (larger than one hex) which hurts players when they walk over it.

I think that's almost all. The module is released as public domain, do with it whatever you want. Comments are welcome but don't ask me how to use it, the description and comments inside the scripts should be enough. There are some glitches, it's not finished, maybe I will be updating the public version, maybe not. I didn't really test it on SDK, it may require some small adjustments. Do it yourself.

Edit: Forgot about one thing - you need a new VAR named mhex_id. Local item VAR, No borders, Start/Max/Min values: 0
« Last Edit: June 30, 2013, 01:18:13 pm by b__B »

Offline Gob

  • The Good
Re: [script] Multihex Items
« Reply #1 on: January 19, 2013, 12:24:50 pm »
Nice job, Jovanka. Thanks for sharing.

Offline shenbei8

  • Science: 300%
Re: [script] Multihex Items
« Reply #2 on: January 20, 2013, 05:32:34 am »
awesome!   that's very helpful!!  :-* :-* :-* :-*
-------------辐射2的发烧友.骨灰级玩家--------------



-----------------生化危机忠实粉丝----------------



--------------- 产品设计师 室内设计师-------------