When an item gets attached to a sticky area, it should become "static" anyway if you disable the detachable property. It may be worth considering the following approach:
Have 3 skulls - which the player can move; in this example named moveSkull_1 through moveSkull_3.
Next we create a sticky area, which will have the "attachable body name" feild set to "moveSkull_" - this means any of the skulls can be attached to this area. We also want to make the area call a function when a skull is added to the area - to do so we shall set the "attach function" feild to "cbSkullAttach" - which we shall create next.
Duplicate this sticky area until you have enough and position the new areas where you want 'em to go - make sure they are active. Feel free to play about with the other settings, though if you plan on making the skulls detachable you will also have to add a detatch callback for reasons that should become apparent.
Now it is time to do the scripting. In your hps file add the following function:
//Note: In your onStart() function, you will need to initialise
//The "skullsAttached" variable to 0 (or whatever).
void cbSkullAttach(string &in asArea, string &in asEntity) {
//Register that a skull was attached
int skulls = GetLocalVarInt("skullsAttached") +1;
SetLocalVarInt("skullsAttached", skulls);
//See if all the areas are occupied by a skull
if ( skulls >=3 )
{ <code> }
}
This will act as the callback for whenever any of the sticky areas are fired - we don't really care which are fired, or by what objects (as we know the only objects that will trigger the attaches are our skulls). We don't even really care about the order of attachment.
The beauty of this approach, is that you can have an arbitrarily high number of skulls or areas (just change the 3 to whatever). You can also have more skulls than areas and allow any of them to be used - which may be more realistic. You can also make specific skulls for specific areas by simply changing the what name of object the sticky area looks for. But what if you want to have a tonne of skulls and skull areas, or edit the puzzle lots and not really wan't to fuss about changing some numbers in a script?
Spoiler below!
As this isn't strictly necessary to your problem, i have placed it in spoiler tags. Let us assume you have named your sticky areas "skullArea_<x>" - where <x> is the number of that area, starting at 0, and ending at however many areas there are (Duplication of the area will auto-increment this number for you automatically!). If that is the case, our code can be improved:
//Returns however many entities matching a signature there are
int countEntities(string signature) {
int output=0;
for(;GetEntityExists(signature+output);output++){}
return output;
}
void cbSkullAttach(string &in asArea, string &in asEntity) {
//Register that a skull was attached
int skulls = GetLocalVarInt("skullsAttached") +1;
SetLocalVarInt("skullsAttached", skulls);
//See if all the areas are occupied by a skull
if ( skulls >= countEntities("skullArea_") )
{ <code> }
}
This allows you to add and remove areas, and skulls from the map without changing or touching the script. Provided you have enough skulls for the areas, and the naming matches what you are testing for, this will always work.
Edit: Improved the scripts a little, and added a few more notes.
Edit 2: Thanks, Acies
(This post was last modified: 05-06-2011, 03:23 AM by Apjjm.)