1-- OPENTOMB HELPER TRIGGER FUNCTION SCRIPT
2-- by Lwmte, May 2015
3
4--------------------------------------------------------------------------------
5-- This script contains various helper functions which are used in entity
6-- script.
7--------------------------------------------------------------------------------
8
9-- Template which is called for specific entity types at level start-up.
10
11function prepareEntity(object_id)
12    local object_mask = getEntityMask(object_id);
13    if(object_mask == 0x1F) then
14        activateEntity(object_id, 0, 0, 0, 0, 0);
15        setEntityTriggerLayout(object_id, 0x00, 0, 0); -- Reset activation mask and event.
16    end;
17end;
18
19function swapEntityState(object_id, state_1, state_2)
20    local current_state = getEntityAnimState(object_id, ANIM_TYPE_BASE);
21    local a, f, c, na, nf, ns = getEntityAnim(object_id, ANIM_TYPE_BASE);
22    if(c == 1) then
23        if(current_state == state_1) then
24            setEntityAnimState(object_id, ANIM_TYPE_BASE, state_2);
25            return ENTITY_TRIGGERING_ACTIVATED;
26        elseif(current_state == state_2) then
27            setEntityAnimState(object_id, ANIM_TYPE_BASE, state_1);
28            return ENTITY_TRIGGERING_DEACTIVATED;
29        end;
30    else
31        if(ns == state_1) then
32            setEntityAnimStateHeavy(object_id, ANIM_TYPE_BASE, state_2);
33            return ENTITY_TRIGGERING_ACTIVATED;
34        elseif(ns == state_2) then
35            setEntityAnimStateHeavy(object_id, ANIM_TYPE_BASE, state_1);
36            return ENTITY_TRIGGERING_DEACTIVATED;
37        end;
38        return ENTITY_TRIGGERING_NOT_READY;
39    end;
40end;
41
42function swapEntityActivity(object_id)
43    local current_activity = getEntityActivity(object_id);
44    if(current_activity) then
45        setEntityActivity(object_id, false);
46        return ENTITY_TRIGGERING_DEACTIVATED;
47    else
48        setEntityActivity(object_id, true);
49        return ENTITY_TRIGGERING_ACTIVATED;
50    end;
51end;
52
53function swapEntityEnability(object_id)
54    local current_enability = getEntityEnability(object_id);
55    if(current_enability) then
56        disableEntity(object_id);
57        return ENTITY_TRIGGERING_DEACTIVATED;
58    else
59        enableEntity(object_id);
60        return ENTITY_TRIGGERING_ACTIVATED;
61    end;
62end;
63