hey all;
all i need to know that how to activate the entity event to open the door that work with security card .i have to make the player picked up the security card and go toward the switch of the door and the switch will scan the palyer if he have the security card or not. now we have a global variable that name card_check it's set to zero and when it's equal the switch will open the door. and here is the code .


//Actions library that contains some actions to be used in any game project
///////////////////////////////
#include <acknex.h>
#include <default.c>
#define ON 1
#define OFF 2
var key_check=0;// global variable should be to set to ON when the key_pressed
var card_check=OFF;

/////////////////////////////////////////// DOOR SECTION ///////////////////////////////////////////////////
function entity()
{
if(event_type == EVENT_ENTITY)
{
card_check=ON;
my.z=60;

}
}
function detect()
{
if (event_type == EVENT_DETECT)
{
}
}
function scan()
{
if(card_check==ON)
{
var light_state=1000;
if (event_type == EVENT_SCAN && key_z)
{
camera.ambient = light_state;
key_check=OFF;
}
else if (event_type == EVENT_SCAN && key_f)
{
camera.ambient = -light_state;
}
if (event_type == EVENT_SCAN && key_o)
{
key_check=ON;
}
else if (event_type == EVENT_SCAN && key_c)
{
key_check=OFF;
}
}
}
action card()
{
entity;
}
action switch_key()
{
var switch_scan_range = 80;
var switch_scan_cone_horizontal = 90;
var switch_scan_cone_vertical = 90;

my.emask |= ENABLE_DETECT;
my.event = detect;
while(1)
{
c_scan(my.x,my.pan,vector(switch_scan_cone_horizontal,switch_scan_cone_vertical,switch_scan_range),SCAN_ENTS | SCAN_LIMIT|IGNORE_ME);
wait(1);
}
}

action door()
{
var door_step=3;
var door_full_trip=200;
var counter=0;
var door_travelled_dist = 0.0;
while(1)
{
if( key_check==ON)
{
if (door_travelled_dist < door_full_trip)
{
door_travelled_dist += door_step*time_step;
my.z+=door_step*time_step;
}
else
{
my.z += door_full_trip -door_travelled_dist ;
door_travelled_dist = door_full_trip;
}
}
if(key_check ==OFF)
{
if (door_travelled_dist > 0)
{
door_travelled_dist -= door_step*time_step;
my.z-=door_step*time_step;
}
else
{
my.z -= -door_travelled_dist ;
door_travelled_dist = 0;
}
}
wait(1);
}
wait(1);
}

action Hero_Animation()
{
var walk_percentage;
var death_percentage;
var run_percentage;
var crouch_percentage;
var idle_percentage;
var crawl_percentage;
var jump_percentage;
var attack_percentage;

my.emask |= ENABLE_SCAN;
my.event = detect;
my.event = scan;
my.event = entity;

while (1)
{
ent_animate(my,"idle",idle_percentage, ANM_CYCLE); // "walk" animation loop
idle_percentage += 5 * time_step; // 3 = animation speed for "walk"
if (key_d)
{
my.pan += 10*time_step; // increase the pan angle of the car
}
if (key_a)
{
my.pan -= 10*time_step; // decrease the pan angle of the car
}
if(key_s)
{
c_move (me, vector(-5 * time_step,0, 0), nullvector, GLIDE);
ent_animate(my,"walk",walk_percentage, ANM_CYCLE); // "walk" animation loop
walk_percentage += 5 * time_step; // 3 = animation speed for "walk"
}
if(key_w)
{
c_move (me, vector(15 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my,"walk",walk_percentage, ANM_CYCLE); // "walk" animation loop
walk_percentage += 10 * time_step; // 3 = animation speed for "walk"
wait (1);
}
if(key_shift && key_w)
{
c_move (me, vector(15 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my,"run",run_percentage, ANM_CYCLE); // "walk" animation loop
run_percentage += 5 * time_step; // 3 = animation speed for "walk"
}
if(key_ctrl)
{
ent_animate(my,"crouch",crouch_percentage, 0); // "walk" animation loop
}
if(key_n)
{
c_move (me, vector(2 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my,"crawl",crawl_percentage, ANM_CYCLE); // "walk" animation loop
crawl_percentage += 3.5 * time_step; // 3 = animation speed for "walk"
}
if(key_space)
{
ent_animate(my,"jump",jump_percentage, ANM_CYCLE); // "walk" animation loop
jump_percentage += 10 * time_step; // 3 = animation speed for "walk"
}
if(mouse_left)
{
ent_animate(my,"attack",attack_percentage, ANM_CYCLE); // "walk" animation loop
attack_percentage += 10 * time_step; // 3 = animation speed for "walk"
}
wait(1);
}
}
function main()
{
//video_mode = 7;
level_load ("exeperment.wmb");
wait (2); // wait until the level is loaded
}