Q: How can I make my player to loose energy when it comes close to another entity?
A: Here's the code:
action another_entity
{
while (player == null) {wait (1);}
while (1)
{
if (vec_dist(my.x, player.x) < 50 && player._health > 0) { player._health -= 0.5 * time; }
wait (1);
}
}
Q: When I try to build my level I get this error message: "Block outside level boundaries". What can I do?
A: Your level is bigger than 50000 quants. Click build and write -bound 100000 in "Build options". You can use values of up to 250000.
Q: I want to open a dll in main and then close it before the app exits. When I hit esc the app just closes, how can I catch all close messages to make sure I close the dll?
A: Use the code below as an example:
dllfunction ComputeTime(value);
function end_game();
var game_over = 0; // set it to 1 to finish the game
function main()
{
on_esc = null; // disable the keys
on_f10 = null; // that shut down the engine
load_level <sarl.wmb>;
dll_open ("timer.dll");
while (game_over == 0)
{
ComputeTime(25);
wait (1);
}
dll_close(dll_handle);
exit;
}
function end_game()
{
game_over = 1;
}
on_esc = end_game; // use the same keys
on_f10 = end_game; // to stop the game
Q: I know it is easy, I know it is in the manual, but can someone help me with the code to put a panel on the screen?
A: Here's your code sample:
bmap mypicture_pcx = <mypicture.pcx>;
panel mypanel_pan
{
bmap = mypicture_pcx;
pos_x = 10; // position on x
pos_y = 20; // and y
layer = 20;
flags = overlay, refresh, d3d;
}
Q: When I save my model it's like it has a save snap that moves some vertices to the closest snap measurement.
A: Older model formats (including mdl, md2) save their vertex positions to a matrix of 256x256 possible coords. Use the new mdl format (high precission) when you save your model. Choose View -> Model properties and check "High Precision" before saving and you will get rid of your problem.
Q: How would one scale a 250x250 panel, which only contains a bitmap of the same size, 3 times its normal size at runtime?
A: Use an entity:
entity my_sprite
{
type = <mysprite.pcx>;
layer = 25;
view = camera;
x = 600;
y = 222;
z = 135;
flags = visible;
}
These x y z values will show the sprite as a panel in the upper left corner. Modify the x y z values for the entity to make it appear bigger:
function increase_size()
{
my_sprite.x = 250; // play with these values
my_sprite.y = 19;
my_sprite.z = -10;
}
Q: I have a sword and when the player reaches a certain distance near the sword he can pick it up by pressing the spacebar. Is this possible?
A: Combine the code bellow with your sword code:
action pick_up_sword
{
while (player == null) {wait (1);}
while (1)
{
if ((vec_dist (player.x, my.x < 100)) && (key_space == 1))
{
call your sword action / function here
}
wait (1);
}
}
Q: I use the Sword Combat code in Aum12 for my game. Is it possible to jump forward when I press space? If I press the spacebar the player should jump a distance.
A: Replace action player_fight in the original file with this action:
action player_fight // attached to the player
{
player = me; // I'm the player
player.healthpoints = 100; // and I have 100 health points
while (player.healthpoints > 0) // as long as I'm alive
{
camera.x = player.x - 200 * cos(player.pan); // 200 = distance between the player and the camera
camera.y = player.y - 200 * sin(player.pan); // same value here
camera.z = 200; // above the player
camera.pan = player.pan; // looks in the same direction with the player
camera.tilt = -30; // look down at the player
my.pan += 4 * (key_a - key_d) * time - 20 * mouse_force.x * time; // rotates with the keys A and D or with the mouse
player_distance.x = 10 * (key_w - key_s) * time; // moves forward / backward with W / S
player_distance.y = 0;
player_distance.z = 0;
if ((key_w == 1) || (key_s == 1)) // the player is walking
{
ent_cycle("walk", my.skill20); // play walk frames animation
my.skill20 += 4 * time; // "walk" animation speed
if (my.skill20 > 100) {my.skill20 = 0;} // loop animation
}
if (key_space == 1) // space to jump
{
ent_cycle("jump", my.skill20);
my.skill20 += 3 * time; // "jump" animation speed
if (my.skill20 < 100)
{
player_distance.z += 0.1 * time;
player_distance.x += 2 * time;
}
}
if (key_any == 0) // the player is standing
{
player_distance.z = 0;
player.skill20 = 0;
ent_cycle("stand", my.skill21); // play stand frames animation
my.skill21 += 2 * time; // "stand" animation speed
if (my.skill21 > 100) {my.skill21 = 0;} // loop animation
}
ent_move(player_distance, nullvector);
if (mouse_left == 1) // if we press the left mouse button
{
my.skill22 = 0; // reset "attack" frames
while (my.skill22 < 100)
{
ent_vertex(my.sword_tip, 315); // sword tip vertex coords - get the value in Med
ent_vertex(my.sword_base, 293); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable; // ignore me (the player) and all the entities that are passable
trace (my.sword_base, my.sword_tip); // trace between these sword positions
if (result != 0) // the player has hit something
{
effect (particle_sparks, 10, target, normal);
if (you != null) {you.healthpoints -= 6 * time;} // if it hasn't hit a wall, decrease health
ent_playsound (my, sword_snd, 50); // sword sound
}
ent_cycle("attack", my.skill22); // play attack frames animation
my.skill22 += 8 * time; // "attack" animation speed
wait (1);
}
while (mouse_left == 1) {wait (1);} // can't use autofire on a sword :)
}
wait (1);
}
while (my.skill23 < 90) // the player is dead
{
ent_cycle("death", my.skill23); // play death frames animation
my.skill23 += 3 * time; // "death" animation speed
wait (1);
}
my.passable = on; // the corpse can't be hit by the enemy sword from now on
}
Q: I create my terrain as a combination of level geometry and heightmaps. I want to limit the vertical climbing abilities of game characters in the heightmap area of my maps by making an invisible ceiling but leaving the skysphere visible. Is this possible?
A: Use invisible level blocks; add a block in Wed, right click on it choose Properties and make it invisible.
Q: How would I use vec_to_mesh or vec_for_mesh to emit particles from say, three different vertices on a sword model?
A: Get the vertex coords in the action that is attached to the sword:
var vertex1;
var vertex2;
var vertex3;
action my_sword
{
while (1)
{
ent_vertex(vertex1, 115); // get this value in Med
ent_vertex(vertex2, 215); // get this value in Med
ent_vertex(vertex3, 315); // get this value in Med
// the rest of your sword action code
..........................
wait (1);
}
}
Place the lines below in the action that will start the particles:
effect (particle_init, 1, vertex1, normal);
effect (particle_init, 1, vertex2, normal);
effect (particle_init, 1, vertex3, normal);
function particle_init()
{
// the function that creates the particles
}
|