FOnline Development > Share Your Work

[Script] Multihex Items


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:

How to add it to your server:

Add multihex.fos to scripts.cfg:

--- Code: ---@ server module multihex # Multihex items
--- End code ---

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: ---#define PID_VAULT_CITY_GATE                 (3337)
#define PID_CORRUGATED_GATE                 (3818)
--- End code ---

And probably these 2238 defines from _time.fos:

--- Code: ---#define ELAPSED_TIME              (__FullSecond)
#define AFTER #(x)                (ELAPSED_TIME+(x))
--- End code ---

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: ---if (IsMultihex(item)) MultihexClose(item);
--- End code ---

--- Code: ---if (IsMultihex(item)) MultihexOpen(item);
--- End code ---
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: ---#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);

--- End code ---

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

Nice job, Jovanka. Thanks for sharing.

awesome!   that's very helpful!!  :-* :-* :-* :-*


[0] Message Index

Go to full version