Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,459 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Surveillance camera problem #331075
07/01/10 19:59
07/01/10 19:59
Joined: Apr 2010
Posts: 56
Badrizmo Offline OP
Junior Member
Badrizmo  Offline OP
Junior Member

Joined: Apr 2010
Posts: 56
I'm trying to make a surveilance camera, so my logic was as follows

1- rotate the camera pan back and forth
2- use c_scan to scan what is infront of the camera
3- when the camera detects the player
3-1 use c_trace from the camera to the detected object to make sure that there are no walls between the camera and the player.

the problem is that when I use the c_trace inside the event function I got the error message "Dangerous instruction in event detected".

here is my code

Click to reveal..

// CSCAN.c
#include <default.c>
#include <acknex.h>
#define SRV_CAM 1
#define ON 1
#define OFF 0


SOUND* alarm = "Alarm.wav";
var alarm_handle;
var alarm_mode = OFF;
var alarm_launched = OFF;


function alarming()
{
if(alarm_mode == ON && alarm_launched != ON)
{
alarm_launched = ON;
snd_start(alarm_handle);

}
else if (alarm_mode ==OFF && alarm_launched ==ON)
{
alarm_launched = OFF;
snd_pause(alarm_handle);
}
}


function detected()
{
ENTITY* playerAvatar = you;
ENTITY* cameraAvatar = me;
while (event_type == EVENT_DETECT)
{
c_trace(my.x,you.x,IGNORE_ME|IGNORE_PASSABLE|ACTIVATE_SHOOT|IGNORE_CONTENT);
if (you == player)
{
alarm_mode = ON;
alarming();
wait(1);
}

}
if (event_type != EVENT_DETECT)
{
alarm_mode =OFF;
alarming();
}
}

SOUND* cam_actuator = "Actuator.wav";
var cam_actuator_handle;

action SRVCamera()
{

var counter = 0;
var cam_step = 2;
var cam_max_rot = 60;
var cam_stop_time = 250;
var cam_scan_range = 150;
var cam_scan_cone_horizontal = 45;
var cam_scan_cone_vertical = 45;


my.emask |= ENABLE_DETECT;
my.event = detected;


//Playing the actuator sound as the camera moves
cam_actuator_handle= ent_playloop(my,cam_actuator,40);

//Rotating the camera for one time for 90 degrees
for (counter=0;counter<=cam_max_rot;counter+=cam_step*time_step)
{

my.pan =counter;
c_scan(my.x,my.pan,vector(cam_scan_cone_horizontal,cam_scan_cone_vertical,cam_scan_range),SCAN_ENTS | SCAN_LIMIT|IGNORE_ME);
wait(1);
}

my.pan = counter = cam_max_rot;
//The actuator sound stops when the camera stops
snd_pause(cam_actuator_handle);
wait(cam_stop_time);



while (1)
{
//The actuator sound plays again when the camera starts moving
snd_start(cam_actuator_handle);
while (counter <= cam_max_rot && counter> -cam_max_rot)
{
counter -= cam_step *time_step;
my.pan =counter;
c_scan(my.x,my.pan,vector(cam_scan_cone_horizontal,cam_scan_cone_vertical,cam_scan_range),SCAN_ENTS | SCAN_LIMIT|IGNORE_ME);
wait (1);
}
my.pan =counter = -cam_max_rot;

snd_pause(cam_actuator_handle);

wait(cam_stop_time);

snd_start(cam_actuator_handle);

while (counter <= cam_max_rot && counter>= -cam_max_rot)
{
counter += cam_step *time_step;
my.pan =counter;
c_scan(my.x,my.pan,vector(cam_scan_cone_horizontal,cam_scan_cone_vertical,cam_scan_range),SCAN_ENTS | SCAN_LIMIT|IGNORE_ME);
wait (1);
}
my.pan =counter = cam_max_rot;
snd_pause(cam_actuator_handle);
wait(cam_stop_time);

wait(1);
}
}


var MoveSpeed = 8;
var TurnSpeed = 8;
action move()
{
alarm_handle = snd_loop(alarm,100,0);
snd_pause(alarm_handle);
player = me;
my.emask|=ENABLE_SCAN;

while (1)
{
if(key_w)
{
c_move(me,vector(MoveSpeed*time_step,0,0),nullvector, GLIDE);
}
if(key_s)
{
c_move(me,vector(MoveSpeed* -time_step,0,0),nullvector, GLIDE);
}
if(key_a)
{
me.pan +=TurnSpeed*time_step;
}
if(key_d)
{
me.pan -=TurnSpeed*time_step;
}
wait(1);
}
}

function main()
{
level_load("CSCAN.wmb");
wait (2);
}




Re: Surveillance camera problem [Re: Badrizmo] #331077
07/01/10 20:05
07/01/10 20:05
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
insert a wait(1); before your c_trace
note that you must save your my and you pointer!
Code:
function detected()
{
ENTITY* playerAvatar = you;
ENTITY* cameraAvatar = me;
while (event_type == EVENT_DETECT)
{
wait(1);
c_trace(my.x,you.x,IGNORE_ME|IGNORE_PASSABLE|ACTIVATE_SHOOT|IGNORE_CONTENT);
if (you == player)
{
alarm_mode = ON;
alarming();
wait(1);
}

}
if (event_type != EVENT_DETECT)
{
alarm_mode =OFF;
alarming();
}
}




Visit my site: www.masterq32.de
Re: Surveillance camera problem [Re: MasterQ32] #331130
07/02/10 07:28
07/02/10 07:28
Joined: Apr 2010
Posts: 56
Badrizmo Offline OP
Junior Member
Badrizmo  Offline OP
Junior Member

Joined: Apr 2010
Posts: 56
Thanks a lot Richi007, that worked. But I was wondering why a wait instruction is required. and why I need to save them. I always save them but as a good programming practice to improve the readability, but in this specific case why do I need to do that.

Re: Surveillance camera problem [Re: Badrizmo] #331146
07/02/10 08:11
07/02/10 08:11
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
It is all explain in the manual, have a look at "event".


Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1