// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
// rayp's interact / doors example 26.03.2014 free2use have fun forum: www.coniserver.net/ubb7
// updated version 27.03.2014
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
#include <default.c> // 4ex STRING* needs this .c file included
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
STRING* str_help = "WASD move, mouse2look, space = interact, press 1 to give player key1";
STRING* map1 = "sample.wmb";
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
#define id skill100 // identification 4ex my.id = id_door <- it's a door
#define operate skill99 // player hit us with trace ( or were operating already ) ? then 1
#define allow_move skill98 // when 1 my - object is able / allowed 2 move ( 0 = dont move! )
#define _random skill97 // u can store random values here 4 later usage ( optional )
#define do_nothing skill96 // maybe locked? this skill is used 2 skip / goto lines: Doors_WED
//#define sound skill95 // our sound - handle
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
#define id_door 1000 // use this id - markers with "my.id = ..." to identify objects
//#define id_car 1001 // id_dog 1002, and so on...
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
var key1 = 0; // 1=player got this key and is able 2 open doors with skill2==1
var key2 = 0; // ...same here, another key ... maybe the red one ^^
//those are no "commentedout lines" the lines will rename your WED-Properties 4 this ents-skills
//skill1 PlusPAN 90 // swing this far ( door.pan + n )
//skill2 KeyNr // 1 = need key1 = 1, 2 = need key2 = 1 ...and so on
//flag1 DummyDoor 0 // a fake door, never open this
action Door_WED(){
my.id = id_door;
my.group = 2;
set (my, POLYGON);
// ---=[ its a fake door ]=-------------------------------------------------------------------
if (is (my, FLAG1)){ // fake door? then stay in this while!
while (my){
if (my.operate){ // && !snd_playing (my.sound)){ // would avoid endless - sound (- loop)
my.operate = 0;
//my.sound = ent_playsound (me, snd_door_locked, 200);
}
wait (1);
}
}
// ---=[ we can open this door, no faked door ]=----------------------------------------------
my.allow_move = 1;
var _rotateto = my.pan + my.skill1; // swing 2 this point
var _door_pan = my.pan; // start pan
while (my){
if (random (1) > 0.95) my._random = random (1);
if (my._random > 0.5) _door_pan += _rotateto;
else _door_pan -= _rotateto;
// ---=[ player started interaction via c_trace with us. step1: check 4 keys ]=------------
if (my.operate){ // interact - c_trace will set this to 1
if (my.skill2 == 1 && !key1){ // player has no key1 !
//if (!snd_playing (my.sound)) my.sound = snd_play (snd_door_locked, 90,0);
my.do_nothing = 1;
}
if (my.skill2 == 2 && !key2){ // player has no key2 !
//if (!snd_playing (my.sound)) my.sound = snd_play (snd_door_locked, 90,0);
my.do_nothing = 1;
}
//if (!my.do_nothing) ent_playsound (me, snd_door_move, 100); // unlocked? play opensound!
// ---=[ keys checked, door's movement part is next ( maybe were still locked? ) ]=-------
if (my.allow_move){
my.allow_move = 0; // ignore further interact requests
while (my.pan < _rotateto && !my.do_nothing){
//if (random (1) > 0.98 && !snd_playing (my.sound)) my.sound = ent_playsound (me, snd_door_quietsch, 100);
move_mode = IGNORE_ME | IGNORE_PASSABLE | IGNORE_WORLD | IGNORE_SPRITES;
c_ignore (1, 2, 0); // ignore player and other doors + myself
c_rotate (me, vector (time_step * 4, 0, 0), move_mode);
wait (1);
}
my.operate = 0; // ready 4 action again!
my.do_nothing = 0;
}
if (!my.allow_move && my.operate){
my.allow_move = 1;
while (my.pan > 0 && !my.do_nothing){ // my.pan > _door_pan
//if (random (1) > 0.98 && !snd_playing (my.sound)) my.sound = ent_playsound (me, snd_door_quietsch, 100);
move_mode = IGNORE_ME | IGNORE_PASSABLE | IGNORE_WORLD | IGNORE_SPRITES;
c_ignore (1, 2, 0);
c_rotate (me, vector (-time_step * 4, 0, 0), move_mode);
wait (1);
}
//ent_playsound (me, snd_door_close, 200);
my.operate = 0; // ready 4 action again!
my.do_nothing = 0;
}
}
// ---=[ interaction done, my.operate = 0 again ]=-----------------------------------------
wait (1);
}
}
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
var tracing_already = 0; // dont "loop - trace"
void interact_with_world(){
proc_mode = PROC_GLOBAL;
if (tracing_already) return;
tracing_already = 1;
// ---=[ prepare trace vectors and trace with "range" in cam - direction ]=-------------------
var range = 50;
VECTOR tpos;
vec_for_angle (tpos, vector (camera.pan, camera.tilt, camera.roll));
vec_scale (tpos, range);
vec_add (tpos, vector (camera.x,camera.y,camera.z));
trace_mode = IGNORE_ME | IGNORE_PASSABLE | USE_POLYGON | SCAN_TEXTURE | IGNORE_SPRITES;
c_ignore (1, 0);
c_trace (vector (camera.x, camera.y, camera.z), tpos, trace_mode);
// ---=[ look if and what we have hit, checking "ent.id - marker" ( id_dog ... ) ]=-----------
if (HIT_TARGET && you){
draw_point3d (target.x, vector (50,50,255), 100, 3); // debug
if (you.id == id_door){ // trace hit door
if (!you.operate) you.operate = 1; // let the door swing, baby !
}
//if (you.id == id_car){ // and so on...
//}
}
// ---=[ interaction complete ]=--------------------------------------------------------------
tracing_already = 0; // hero's able 2 trace again
//wait (-1); // no need to "loop-call" - "c_trace - void" : performance!
}
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
action MyHero_WED(){
wait (1);
my.eflags |= FAT | NARROW;
vec_set (my.min_x, vector (-5,-5,-15));
vec_set (my.max_x, vector ( 5, 5, 20));
my.group = 1; // this group is ignored from our c_trace - laser
while (my){
// ---=[ simple movement ]=----------------------------------------------------------------
VECTOR vdist;
vdist.x = (key_w - key_s) * (time_step * 4);
vdist.y = (key_a - key_d) * (time_step * 4);
move_mode = IGNORE_ME | IGNORE_PASSABLE | GLIDE;
c_ignore (1, 0); // ignore all ent's in this group
c_move (me, vector (vdist.x, vdist.y, 0), nullvector, move_mode);
my.pan -= (mickey.x * time_step) * 4;
// ---=[ handle cam ]=---------------------------------------------------------------------
vec_set (camera.x, my.x);
camera.pan = my.pan;
camera.tilt -= (mickey.y * time_step) * 4;
camera.tilt = clamp (camera.tilt, -90, 90);
// ---=[ interact with game world ]=-------------------------------------------------------
if (!tracing_already && key_space) interact_with_world(); // not tracing? space? interact!
// ----------------------------------------------------------------------------------------
draw_text (str_help, 10, 10, vector (0,0,255)); // info text
if (!key1 && key_1) key1 = 1; // give key1 to player if he pressed 1
wait (1);
}
}
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
ENTITY* skycube = {
type = "skycube+6.tga";
flags2 = SKY | CUBE | SHOW;
}
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
void main(){
camera.clip_near = 0; // reduce near clipping distance
level_load (map1); // load the level and go!
}
// -----------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------
// end of this great contribution ... ifuwant give credits 2 rayp ... building a deathstar with it
// -----------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------