Q: I use your text engine from Morrowing. How can I have a different number of answers to choose from (1, 2, 3, or 4 answers)? Your code works fine, but I can’t have more than 2 answers at once.
A: Create a panel with 4 buttons and change its pos_y depending on how many buttons (answers) you want to show. A bigger pos_y value will hide the lower buttons and thus will give the player access to fewer answers. Don't forget to hide the texts that aren't supposed to show up.
Q: How can I show this message in my game: "Hello guardian, who are you?". The message must appear when I click an entity.
A: Use the following example:
text question_txt
{
layer = 25;
pos_x = 200;
pos_y = 25;
font = _a4font;
string = "Hello guardian, who are you?";
}
function ask_question()
{
question_txt.visible = on;
sleep (3); // display the question for 3 seconds
question_txt.visible = off;
}
action prisoner
{
my.enable_click = on;
my.event = ask_question;
}
Q: How can I find the distance from mouse_ent to the camera?
A: Use this snippet:
string distance_str[6];
string displayed_str[30];
text distance_txt
{
layer = 25;
pos_x = 10;
pos_y = 15;
font = _a4font;
flags = visible;
}
starter mouse_distance()
{
var distance_to_camera;
mouse_range = 10000; // the entities are sensitive to mouse touching and clicking up to 10,000 quants
while (1)
{
if (mouse_ent != null) // the mouse was placed over an entity?
{
distance_to_camera = vec_dist(mouse_ent.x, camera.x); // then compute the distance to it
str_for_num(distance_str, distance_to_camera);
}
else
{
str_cpy(distance_str, "+++");
}
str_cpy(displayed_str, "Distance to camera: ");
str_cat(displayed_str, distance_str);
distance_txt.string = displayed_str;
wait (1);
}
}
Q: I have tried to create a dll but I can't use the function inside it; I keep getting this error message: “function not found in dll” although the function is there. What should I do?
A: Copy your dll to the \acknex_plugins folder that exists inside your 3DGS folder (create that folder if you don't have it).
Q: How can I have a weapon (in the first person mode) that affects the amount of light in the level?
A: Use the code below:
define enemy_health skill48; // put your own skill here
string mp40_mdl = <mp40.mdl>;
string bullet_mdl = <bullet.mdl>;
sound bullet_wav = <bullet.wav>;
function remove_bullet()
{
wait (1);
if (you != null) // hit an entity
{
you.enemy_health -= 30; // remove 30 health points from the enemies
}
ent_remove (my);
}
function move_players_bullet()
{
my.pan = camera.pan; // the bullet and the player (the camera) have the same pan angle
my.passable = on; // at first
my.tilt = camera.tilt; // and tilt angle
my.enable_entity = on; // the bullet is sensitive to other entities
my.enable_impact = on;
my.enable_block = on; // and to level blocks
my.event = remove_bullet;
while (my != null)
{
if (vec_dist (you.x, my.x) > 30) {my.passable = off;}
my.skill1 = 100 * time; // bullet speed
my.skill2 = 0;
my.skill3 = 0;
move_mode = ignore_you + ignore_passable;
ent_move (my.skill1, nullvector);
wait (1);
}
}
function players_weapon()
{
var bullet_start;
while (1)
{
my.pan = camera.pan;
my.x = camera.x + 20 * cos(camera.pan) + 13 * sin(camera.pan); // place the weapon 20 quants in front of the camera
my.y = camera.y + 20 * sin(camera.pan) - 13 * cos(camera.pan); // 13 quants to the right
my.z = camera.z - 12; // and 12 quants below the camera
my.tilt = camera.tilt;
vec_for_vertex(bullet_start, my, 30); // get the position for the weapon vertex that will generate the bullet
if ((mouse_left == 1) && (total_frames % 10 == 1)) // fire every 10 frames
{
snd_play (bullet_wav, 50, 0);
ent_create (bullet_mdl, bullet_start.x, move_players_bullet);
}
my.lightrange = 300; // these lines make the weapon emit light
my.lightred = 100;
my.lightgreen = 100;
my.lightblue = 200;
wait (1);
}
}
action my_weapon
{
fps_max = 60;
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 70)
{
my.pan += 3 * time;
wait (1);
}
ent_remove (my);
ent_create (mp40_mdl, camera.x, players_weapon);
}
Q: I'd like to have a weapon that needs to be reloaded after firing 30 bullets, using ammo packs. Can you help?
A: Use this example:
var number_of_bullets = 30;
var ammo_available = 60;
define enemy_health skill48; // put your own skill here
string mp40_mdl = <mp40.mdl>;
string bullet_mdl = <bullet.mdl>;
sound bullet_wav = <bullet.wav>;
sound reload_wav = <reload.wav>;
function remove_bullet()
{
wait (1);
if (you != null) // hit an entity
{
you.enemy_health -= 30; // remove 30 health points from the enemies
}
ent_remove (my);
}
function move_players_bullet()
{
my.pan = camera.pan; // the bullet and the player (the camera) have the same pan angle
my.passable = on; // at first
my.tilt = camera.tilt; // and tilt angle
my.enable_entity = on; // the bullet is sensitive to other entities
my.enable_impact = on;
my.enable_block = on; // and to level blocks
my.event = remove_bullet;
while (my != null)
{
if (vec_dist (you.x, my.x) > 30) {my.passable = off;}
my.skill1 = 100 * time; // bullet speed
my.skill2 = 0;
my.skill3 = 0;
move_mode = ignore_you + ignore_passable;
ent_move (my.skill1, nullvector);
wait (1);
}
}
function players_weapon()
{
var bullet_start;
while (1)
{
my.pan = camera.pan;
my.tilt = camera.tilt;
my.x = camera.x + 20 * cos(camera.pan) + 13 * sin(camera.pan); // place the weapon 20 quants in front of the camera
my.y = camera.y + 20 * sin(camera.pan) - 13 * cos(camera.pan); // 13 quants to the right
my.z = camera.z - 12; // and 12 quants below the camera
vec_for_vertex(bullet_start, my, 30); // get the position for the weapon vertex that will generate the bullet
if ((mouse_left == 1) && (total_frames % 10 == 1) && (number_of_bullets > 0)) // fire every 10 frames (6 bullets a second with fps_max = 60)
{
snd_play (bullet_wav, 50, 0);
ent_create (bullet_mdl, bullet_start.x, move_players_bullet);
number_of_bullets -= 1;
if (number_of_bullets == 0) // no more bullets?
{
while (key_r == 0) // wait until the player has pressed the "R" key
{
my.pan = camera.pan;
my.tilt = camera.tilt;
my.x = camera.x + 20 * cos(camera.pan) + 13 * sin(camera.pan); // place the weapon 20 quants in front of the camera
my.y = camera.y + 20 * sin(camera.pan) - 13 * cos(camera.pan); // 13 quants to the right
my.z = camera.z - 12; // and 12 quants below the camera
wait (1);
}
// play your "reload" weapon animation here
while (key_r == 1) {wait (1);} // wait until the player has released the "R" key
if (ammo_available > 0)
{
ammo_available -= 30;
number_of_bullets = 30;
snd_play (reload_wav, 50, 0);
}
}
}
wait (1);
}
}
action my_weapon
{
fps_max = 60;
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 70)
{
my.pan += 3 * time;
wait (1);
}
ent_remove (my);
ent_create (mp40_mdl, camera.x, players_weapon);
}
action ammo_packs
{
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 70)
{
my.pan += 3 * time;
wait (1);
}
ent_remove (my);
ammo_available += 30; // add more ammo
}
Q: How can I tell if a certain model exists in the game's folder?
A: Ent_create returns zero if the model isn't available; use this example:
var create_result;
panel result_pan
{
layer = 15;
digits = 5, 15, 6, _a4font, 1, create_result;
flags = overlay, refresh, visible;
}
function some_function()
{
wait (1);
}
starter create_something()
{
warn_level = 0; // don't display any error message
sleep (2);
create_result = ent_create ("mp40.mdl", camera.x, some_function);
}
Q: How can I pass an entity and the RGB colors as parameters? I'd like to create several colored entities using the same model.
A: Take a look here:
function colored_entities(entity, r, g, b)
{
my = entity;
my.light = on;
my.lightrange = 0;
my.red = r;
my.green = g;
my.blue = b;
}
action test_blue
{
colored_entities(my, 50, 50, 200); // use any other entity name here
}
action test_red
{
colored_entities(my, 250, 50, 50); // use any other entity name here
}
Q: How can I make it so that when I touch my entity, it gives me this message: "Hi! I am darth vader"?
A: Use this example:
text darth_txt
{
layer = 15;
pos_x = 200;
pos_y = 5;
font = _a4font;
string = "Hi! I am darth vader";
}
function say_line()
{
darth_txt.visible = on;
sleep (2); // display the line for 2 seconds
darth_txt.visible = off;
}
action darth_vader
{
my.enable_touch = on;
my.event = say_line;
}
|