Q:
I'd need the code for a camera that allows you to fly freely
in the level, and yet use collision detection. Can you help?
A:
Attach the action below to your player model. Use the mouse to rotate; press
and hold one of the mouse buttons to move.
action free_camera
{
my.invisible = on;
mouse_mode = 0;
while (1)
{
camera.x = my.x;
camera.y = my.y;
camera.z = my.z;
camera.pan = my.pan;
camera.tilt = my.tilt;
my.pan -= 10 * mouse_force.x * time;
my.tilt += 10 * mouse_force.y * time;
if (mouse_left == 1)
{
move_mode = ignore_passable
+ glide;
result = ent_move (vector
(10 * time, 0, 0), nullvector); // 10 = speed
}
if (mouse_right == 1)
{
move_mode = ignore_passable
+ glide;
result = ent_move (vector
(-10 * time, 0, 0), nullvector); // -10 = speed
}
wait (1);
}
}
Q: Can
you please tell me how can I use my models as a "resource"?
A: Follow these simple steps (you will need A5 pro
or A6 pro):
- Create a small script file that looks like this and name it resources.wdl (or any other name):
bind <guard.mdl>;
bind <warlock.mdl>; // "bind" as many models as you need
- Start Wed, place a simple block in the level and assign it the resources.wdl script file (File -> Map properties).
- Use File -> Resource and you will see the newly created resources.wrs file inside the current folder.
- Use the resource file this way in your script.
resource "resources.wrs"; // open the "resources.wdl" file
string guard_mdl = "guard.mdl"; // retrieve the guard model from "resources.wrs"
starter create_guard_resource
{
sleep (1); // wait until the level is loaded
ent_create(guard_mdl, vector(100, 50, 200), null); // create the
guard.mdl model at x = 100, y = 50, z = 200 quants
}
Q:
Is there a simple method that would allow me to compute
and display the number of frames per second? I can't use the default
debugging panel in my game.
A:
Use the code below:
var fpsec;
var init_frames;
starter compute_fpsec()
{
while (1)
{
init_frames = total_frames; // store the initial
total_frames value
sleep (1); // wait for a second
fpsec = total_frames - init_frames; // get the
new total_frames value and subtract init_frames from it
}
}
panel debug_panel
{
layer = 20;
pos_x = 50;
pos_y = 50;
digits = 10, 10, 3, _a4font, 1, fpsec;
flags = overlay, refresh, visible;
}
Q:
I'd like to be able to control 200 different actors for
my strategy game but I don't like
the idea of defining 200 separate pointers for them. What can I do?
A:
Use "handle" instead:
entity* my_actor;
var index = 0;
var actors[200]; // store 200 handles in this array
action my_actors
{
actors[index] = handle(my); // store the handle inside the array
index += 1; // move to the next actor
// put the rest of the code for your actors here
}
function move_actors_upwards(actor_number)
{
my_actor = ptr_for_handle(actors[actor_number]);
my_actor.z += 100;
}
function
increase_height() // a simple test function
{
move_actors_upwards(2); // increase the z of the 2nd actor by 100
quants
move_actors_upwards(32); // increase the z of the 32nd actor by
100 quants
move_actors_upwards(85); // increase the z of the 85th actor by
100 quants
}
on_i = increase_height;
Q:
I need to place many trees at certain positions on my terrain and doing
that in Wed takes too long. Is there an alternative method?
A: Place the trees close to their
final positions and use the code below. Attach the action named "dummy_tree"
to all your trees, build and run the level, and then move the mouse pointer
over one of the trees. Use "A", "Z", "S", "X", "D", "C" to set the correct
position of the tree, and then write down the 3 values (x, y, z) that
appear on the screen and use them in Wed to set the proper coordinates
for the tree. Repeat these steps until all the trees are positioned correctly.
Oh, and don't forget to use F2 (quick save) and F3 (quick load) in order
to save your current position in the level (if you need to).
bmap arrow_pcx = <arrow.pcx>;
panel entity_pan
{
pos_x = 0;
pos_y = 0;
digits = 50, 10, 5, _a4font, 1, mouse_ent.x;
digits = 50, 22, 5, _a4font, 1, mouse_ent.y;
digits = 50, 34, 5, _a4font, 1, mouse_ent.z;
flags = refresh, visible;
}
starter set_tree_coords()
{
mouse_mode = 2;
mouse_map = arrow_pcx;
while (1)
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
if (mouse_ent != null) // entity detected?
{
if (key_a == on) {mouse_ent.x
+= 1 * time;}
if (key_z == on) {mouse_ent.x
-= 1 * time;}
if (key_s == on) {mouse_ent.y
+= 1 * time;}
if (key_x == on) {mouse_ent.y
-= 1 * time;}
if (key_d == on) {mouse_ent.z
+= 1 * time;}
if (key_c == on)
{mouse_ent.z -= 1 * time;}
}
wait (1);
}
}
action dummy_tree // attach this action to all the tree models
{
my.invisible = off; // put something (anything!) here
}

Q:
I'd like to show an "Alert!" panel on the hud whenever one player's
enemies can be seen. How can I do that?
A:
Place the following lines of code inside the "while" loop that
moves your enemies:
bmap alert_pcx = <alert.pcx>;
panel alert_pan
{
bmap = alert_pcx;
layer = 10;
pos_x = 10;
pos_y = 5;
flags = overlay, refresh;
}
action
my_enemy
{
my.skill1 = 100; // health = 100
// other code outside the "while" loop
.................
while (my.skill1 > 0) // as long as I'm alive
{
if(vec_to_screen(my.x, camera.x)) // if the camera
can see me
{
alert_pan.visible = on; //
show the "Alert!" panel
}
else // otherwise
{
alert_pan.visible = off; //
hide the panel
}
// the rest of the code that runs inside the "while" loop
goes here
...................
wait (1);
}
}

Q:
Is there a simple method to create a "hot" floor that would
decrease player's health?
A: Paste the code below at the end of
your script file:
starter hot_floor()
{
while (player == null) {wait (1);}
while (1)
{
vec_set (temp, player.x);
temp.z -= 5000;
trace_mode = ignore_me + ignore_passable + ignore_sprites
+ ignore_models + scan_texture;
trace(player.x, temp);
if (str_cmpi (tex_name, "lava")) // use
a texture named "lava" (without
the quotes) for the hot areas in your level
{
player._health -= 3 * time; // "3" gives the health decreasing speed
}
wait(1);
}
}
Q:
Would it be possible to turn on the lights that are close to the player
automatically and turn them off as soon as the player gets away from them?
A: Sure. Paste the code below
at the end of your script; attach the action "nice_light"
to the light bulbs.
action nice_light
{
while (player == null) {wait (1);}
my.lightred = 200;
my.lightgreen = 220;
my.lightblue = 100;
my.light = on;
while (1)
{
if (vec_dist (player.x, my.x) < 500) // play with
500
{
my.lightrange = 300;
my.ambient = 100;
}
else
{
my.lightrange = 0;
my.ambient = -100;
}
wait (1);
}
}
Q: How
I create a fire ring that follows the player all the time?
A: Use the code below:
bmap effect_tga = <effect.tga>;
function fade_them()
{
my.alpha -= 5 * time; // play with 5
if(my.alpha < 0) {my.lifespan = 0;}
}
function particle_init()
{
temp.x = random(2) - 1;
temp.y = random(2) - 1;
temp.z = random(2) - 1;
vec_set(my.vel_x, temp);
my.move = on;
my.bmap = fire_tga;
my.flare = on;
my.bright = on;
my.alpha = 100;
my.lifespan = 100;
my.size = 15;
my.function = fade_them;
}
starter player_ring()
{
var temp_var = 0;
var particle_start;
var ring_diameter = 50;
while (player == null) {wait (1);}
while(1)
{
particle_start.x = player.x + (ring_diameter
* sin(temp_var));
particle_start.y = player.y + (ring_diameter
* cos(temp_var));
particle_start.z = player.z;
effect(particle_init, 5, particle_start.x, nullvector);
temp_var += 50 * time; // play with 50
wait (1);
}
}
