Hi,
I would advise some changes to enhance the performance and readability.
Use macros in order to rename the relevant skills and get them named into WED.
#define Door_ID skill1
...
#define State skill98
#define Type skill99
...
// uses: Door_ID
action actDoor ()
{...
...
// uses: Door_ID
action actTrigger ()
{...
Identify the doors linked to the trigger before the loop and save them into a local array, so when the trigger is activated it only goes through the saved entities instead of the whole level entities.
#define MC_DOOR_MAX_BY_TRIGGER 4 // whatever
action actTrigger ()
{
// Set starting values
...
wait(1); // wait a frame, so all level entities are created.
ENTITY *entDoors[MC_DOOR_MAX_BY_TRIGGER];
int iDoorCount = 0;
ENTITY *ent = ent_next ( NULL );
for ( ; ent!=NULL; ent=ent_next(ent) )
{
if ( ent.Type != TYPE_DOOR )
continue;
if ( ent.Door_ID != my.Door_ID )
continue;
entDoors[iDoorCount] = ent;
iDoorCount += 1;
}
...
int i = 0;
for ( ; i<iDoorCount; i+=1 )
{
if ( entDoors[i].State % 2 == 1 )
{
entDoors[i].State += 1;
entDoors[i].State %= 4;
}
}
...
Use entity groups in order to scan relevant entities exclusively by ignoring the rest of entities on the scan.
#define GROUP_DOORS 2
#define GROUP_TRIGGERS 3
...
action actTrigger ()
{
my.group = GROUP_TRIGGERS;
...
action actDoor ()
{
my.group = GROUP_DOORS;
...
action actPlayer ()
{
...
c_ignore ( GROUP_DOORS, ..., 0 );
c_scan ( ...
Execute the scan only when the enter key is pressed, only once and inside the player action loop.
action actPlayer ()
{
...
var nKeyEnter = 0;
while (1)
{
...
if ( key_enter )
{
if ( !nKeyEnter )
{
nKeyEnter = 1;
c_ignore ( GROUP_DOORS, ..., 0 );
c_scan ( ...
if ( you )
{
if ( you.Type == TYPE_TRIGGER ) // May be different scaneable types of entities...
{
if ( you.State % 2 == 1 )
{
you.State += 1;
you.State %= 4;
}
}
}
}
}
else if ( nKeyEnter )
{
nKeyEnter = 0;
}
...
Anyway I would use the scan event for triggers, so the called event performs all the trigger and doors animations. This way there is no need of a continuous loop for each of them. There shall be a loop for animated ones only.
Salud!