really i have a big problem that summarized that i want to make the switch key is an smart key to be able to distinguish which door to be open by player . i have one action for switch_key to the all keys and another one action to the all doors . then the player going to open the press tha switch then the bordering door to the switch to be opned. my problem now is the all doors in the level opened when the player press any switch. Hint the switch sacn the player if he have the security card or not then trigger the actions .
here is my code...
#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;
var door_check=0;
function detect() // detecting
{
if (event_type == EVENT_DETECT)
{
}
}
function security_card_event() // security card function
{
if (event_type== EVENT_IMPACT)
{
card_check=ON;
my.z=200;
}
}
function open_door() //open door function
{
if(card_check==ON)
{
if (event_type == EVENT_SCAN && key_o)
{
door_check=ON;
}
if (event_type == EVENT_SCAN && key_c)
{
door_check=OFF;
}
}
}
action security_card()// action security card
{
my.push=0;
my.emask |= ENABLE_IMPACT; // lite-C
my.event =security_card_event;
}
action switch_key() // action switch key
{
var switch_scan_range = 80;
var switch_scan_cone_horizontal = 90;
var switch_scan_cone_vertical = 90;
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()//action door
{
var door_step=3;
var door_full_trip=200;
var counter=0;
var door_travelled_dist = 0.0;
while(1)
{
if( door_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(door_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);
}
in the end the player action that have pointer player=me;
/////////////////////// SOLVED BY 3RUN (Muhamed) ////////////////////////////
#define switch_number skill19 //only use these skill numbers for
#define switch_status skill20 //entities that react to switches
function switch_event()
{
if(event_type == EVENT_IMPACT)
{
my.emask &= ~(ENABLE_IMPACT);
you=NULL;
if(my.skill20)
{
my.skill20 = 0; //toggle switch setting
}
else
{
my.skill20 = 1; //toggle switch setting
}
while((you=ent_next(you)))
{
if(you.skill19==my.skill19)
{
you.skill20 = my.skill20;
}
wait(-1);
}
if(my.skill18)
{
my.emask |= (ENABLE_IMPACT);
}
}
}
//skill18: switch_type 0 //0=one-shot, 1=toggle
//skill19: switch_number 0
//skill20: switch_status 0
action door_button()
{
c_setminmax(my);
my.emask |= (ENABLE_IMPACT);
my.event = switch_event;
}
//skill16: door_speed 10
//skill17: door_highest 100
//skill18: door_lowest 0
//skill19: switch_number 0
//skill20: switch_status 0
action door_()
{
wait(1);
c_setminmax(my);
while(1)
{
if(my.skill20)
{
if(my.z < my.skill17)
{
my.z += my.skill16*time_step;
}
if(!my.skill20)
{
if(my.z > my.skill18)
{
my.z -= my.skill16*time_step;
}
}
}
wait(1);
}
}
[b][/b]
Last edited by EID; 08/02/10 10:34.