Q: I use your forest script from Aum12, but I'd like the trees to be placed beside the road. Is this possible?
A: Use a different texture for the road and the modified forest script:

define num_trees = 100; // this forest will have 100 trees

var tree_index = 0;
var max_x = 1000;
var min_x = -1000;
var max_y = 1000;
var min_y = -1000;
var tree_pos;

string tree1_mdl = <tree1.mdl>;
string tree2_mdl = <tree2.mdl>;

function create_tree()
{
wait (1);
my.pan = random(360);
vec_set (temp, my.x);
temp.z -= 5000;
trace_mode = ignore_me + ignore_passable + ignore_models + ignore_sprites + use_box;
my.z -= trace (my.x, temp) + 20; // place the tree and stick its root in the ground (20 quants)
}

starter generate_forest()
{
sleep (1); // wait until the level is loaded
randomize(); // always generate a different forest
while (tree_index < num_trees)
{
tree_pos.x = sign(min_x) * random(abs(min_x)) + sign(max_x) * random(abs(max_x));
tree_pos.y = sign(min_y) * random(abs(min_y)) + sign(max_y) * random(abs(max_y));
tree_pos.z = 1000; // 1000 quants above the floor level
tree_index += 1;
vec_set(temp.x, tree_pos.x);
temp.z -= 5000;
trace_mode = ignore_me + ignore_passable + ignore_models + ignore_sprites + scan_texture;
trace (tree_pos.x, temp.x);
if (str_cmpi ("grass1", tex_name)) // if the tree would be placed on the grass (and not on the road)
{
if (random(1) > 0.5)
{
ent_create (tree1_mdl, tree_pos, create_tree); // then create tree1_mdl
}
else
{
ent_create (tree2_mdl, tree_pos, create_tree); // or tree2_mdl
}
}
}
}

Q: I'd like to have some particle sparks appear where an object makes contact with the level geometry. Can you help?
A: Use the code below as an example; it places a sprite decal on the floor if the ball collides with it.

action my_ball
{
my.enable_block = on;
my.enable_entity = on;
my.event = ball_event;
while (1)
{
// your ball code goes here
................
wait (1);
}
}

function particle_sparks()
{
my.passable = on; // make sure that your ball ignores passable objects (move_mode = ignore_passable)
// put your particle code here
}

function ball_event()
{
vec_set (temp, my.x);
temp.z -= 1000;
trace_mode = ignore_me;
trace (my.x, temp);
ent_create(decal_bmp, target, particle_sparks); // place a decal sprite at the right position on the floor ("target" gives us the coordinates)
}

Q: Just wondering if you may have a health bar script handy.
A: Use the code and the bitmap below it as an example:

bmap health_pcx = <health.pcx>;

panel health_pan
{
pos_x = 10;
pos_y = 10;
layer = 10;
window = 20, 10, 20, 60, health_pcx, 0, player._health;
flags = visible;
}

Q: I don't know how to trace forward (in player's looking direction). Is it possible to have a code that that is doing this?
A: Use the code below:

string target_pcx = <target.pcx>;

function trace_forward()
{
var trace_coords;
vec_set(trace_coords.x, vector(1000, 0, 0)); // trace 1000 quants in front of the player
vec_rotate(trace_coords.x, camera.pan); // rotate "temp" in the direction (angles) given by the camera (the player)
vec_add(trace_coords.x, camera.x); // add the resulting vector to camera's (player's) position
trace_mode = ignore_me + ignore_passable + ignore_models + ignore_sprites + use_box;
if (trace(player.x, trace_coords.x) > 0) // hit something?
{
ent_create (target_pcx, target.x, nullvector); // put a small sprite where the trace hits something
// you should replace the line of code above with your own code that is the result of the tracing operation
}
}

on_t = trace_forward;

Q: How can I create the code for a blurred view effect that doesn't use too many resources?
A: Use this example:

view second_camera
{
pos_x = 0;
pos_y = 0;
alpha = 40; // play with this value
flags = transparent, visible;
}

starter camera_blur()
{
camera.transparent = on;
camera.alpha = 30; // play with this value
second_camera.size_x = screen_size.x;
second_camera.size_y = screen_size.y;
while (1)
{
wait (2);
second_camera.x = camera.x;
second_camera.y = camera.y;
second_camera.z = camera.z;
second_camera.pan = camera.pan;
second_camera.tilt = camera.tilt;
second_camera.roll = camera.roll;
}
}

Q: I can't use "sleep" to count big time intervals because it isn't precise enough. Can I use sys_seconds instead?
A: Sure, use the example below:

var second_counter = 0;

starter precision_timer()
{
var temp_seconds;
while (1)
{
temp_seconds = sys_seconds;
wait (1);
if (temp_seconds != sys_seconds) // sys_seconds has changed during the last frame
{
second_counter += 1; // increase second_counter; use this value for your high(er) precision counter
}
}
}

panel time_pan
{
digits = 5, 15, 6, _a4font, 1, second_counter; // display the value that is stored in second_counter
flags = refresh, visible;
}

Q: How can I create a simple login / password system for my game?
A: Use the code below:

bmap serial_pcx = <serial.pcx>;

string serial_str = " "; // the password can have up to 20 characters

panel serial_pan
{
bmap = serial_pcx;
flags = overlay, refresh;
layer = 15;
}

text serial_txt
{
layer = 25;
pos_x = 300;
pos_y = 275;
font = _a4font;
string = serial_str;
}

starter check_password()
{
sleep (1);
serial_pan.visible = on;
serial_txt.visible = on;
inkey(serial_str);
if (str_cmpi(serial_str, "12345") == 0) // password = 12345
{
exit;
}
else
{
serial_pan.visible = off;
serial_txt.visible = off;
beep;
// put the code that starts your game here
}
}

Q: I'd like to have only 3 objects appear randomly in 9 predefined positions. How can I do that?
A: Place 9 objects in the level and attach them the action below:

var score = 0;
var objects_placed = 0;

starter randomize_numbers()
{
randomize();
}

action three_objects_only
{
my.skill1 = random(1) + 0.1; // generate a random number between 0.1 and 1.1
sleep (my.skill1); // wait 0.1 to 1.1 seconds
my.passable = on;
objects_placed += 1;
if (objects_placed > 3)
{
ent_remove(my);
}
else
{
while (player == null) {wait (1);} // wait until the player is created
while (vec_dist(player.x, my.x) > 50) {wait (1);} // wait until the player has come close to the object
ent_remove(my);
score += 10; // whatever
}
}

panel score_pan
{
layer = 15;
digits = 5, 15, 6, _a4font, 1, score;
flags = overlay, refresh, visible;
}

Q: I'd like to see how my game performs on low end PCs, but I've only got one PC and it is pretty fast. Is there anything I could do about this?
A: Set the frame rate to 10...200 using the code below:

starter adjust_fps()
{
while (1)
{
if ((key_k == on) && (fps_max < 200)) {fps_max += 1 * time;} // press "K" to increase the frame rate
if ((key_m == on) && (fps_max > 10)) {fps_max -= 1 * time;} // press "M" to decrease the frame rate
wait (1);
}
}