Fragen aus dem Forum

Top  Previous  Next

F: Ist es möglich, ein sich drehendes Objekt zu definieren, welches die Gesundheit aller Entities verringert, die ihm nahe kommen?

A: Unter der Annahme, dass die Gesundheit Ihrer Entities in Skill99 gespeichert ist, können Sie diesen Code nutzen:

 

sound damaged_wav = <damaged.wav>; // use a very short, looping sound effect here

 

action spinning_entity // attach this action to your entity

{

       while (1)

       {

               my.pan += 5 * time_step; // 5 = rotation speed

               // scan around this entity on a range of 70 quants

               c_scan (my.x, my.pan, vector(360, 180, 70), SCAN_ENTS | SCAN_LIMIT | IGNORE_ME);

               wait (1);

       }

}

 

function player_scanned()

{

       my.skill99 -= 1.5 * time_step; // play with 1.5

       snd_play (damaged_wav, 20, 0);

}

 

action players_action // sample player action with health stored inside skill99

{

       my.skill99 = 100; // the player has 100 health points

       my.enable_scan = on;

       my.event = player_scanned;

       player = my; // I'm the player

       my.polygon = on;

       var players_distance;

       var anim_percentage;

       var attack_percentage;

       var sword_base;

       var sword_tip;

       while (my.skill99 > 0)

       {

               // place the camera 230 quants behind the player and 250 quants above it

               vec_set (camera.x, vector (-230, 0, 250));

               vec_rotate (camera.x, player.pan);

               vec_add (camera.x, player.x);

               camera.pan = player.pan;

               camera.tilt = -30; // look down at the player

               // rotate with the keys A and D or with the mouse

               my.pan += 5 * (key_a - key_d) * time_step - 10 * mouse_force.x * time_step;

               // move forward / backward with W / S, 10 gives the movement speed

               players_distance.x = 10 * (key_w - key_s) * time_step;

               players_distance.y = 0;

               players_distance.z = 0;

               c_move (my, players_distance, nullvector, glide);

 

               if ((key_w == 1) || (key_s == 1)) // the player is walking?

               {

                       ent_animate(my, "walk", anim_percentage, anm_cycle);

                       anim_percentage += 8 * time_step; // "8" controls the animation speed

               }

               else // the player is standing still?

               {

                       ent_animate(my, "stand", anim_percentage, anm_cycle);

                       anim_percentage += 0.5 * time_step; // "0.5" controls the animation speed

               }                        

 

               if (mouse_left == 1) // if we press the left mouse button

               {

                       attack_percentage = 0; // reset the "attack" animation frames

                       while (attack_percentage < 100)

                       {

                               vec_for_vertex (sword_tip, my, 456); // sword tip vertex - get the value in Med

                               vec_for_vertex (sword_base, my, 512); // sword base vertex - get the value in Med        

                               // the player has hit something?

                               if (c_trace (sword_base, sword_tip, ignore_me | ignore_passable) > 0)

                               {

                                       snd_play (sword_wav, 10, 0); // sword sound

                                       if (you != null)

                                       {

                                               // if the player has hit an entity, decrease its health

                                               you.healthpoints -= 10 * time_step;

                                       }

                               }

                               ent_animate(my, "attack_sword_up", attack_percentage, null);

                               attack_percentage += 6 * time_step;

                               wait (1);

                       }

               }

               wait (1);

       }

       // the player is dead here

       my.enable_scan = off;

       anim_percentage = 0;

       while (anim_percentage < 90)

       {

               ent_animate(my, "death", anim_percentage, null);

               anim_percentage += 3 * time_step; // "3" controls the animation speed

               wait (1);

       }

}

 

 

F: Wie kann ich dafür sorgen, dass eikn Objekt "aufleuchtet", wenn die Maus darüber ist, selbst wenn nicht geklickt wurde?

A: Hier ist ein Beispiel.

 

bmap cursor_tga = <cursor.tga>;

 

starter init_mouse()

{

       mouse_mode = 2; // show the mouse pointer

       mouse_map = cursor_tga;

       while (1)

       {

               mouse_pos.x = mouse_cursor.x;

               mouse_pos.y = mouse_cursor.y;

               wait (1);

       }

}

 

function entity_glow()

{

       while (event_type == event_touch)

       {

               my.lightrange = 100;

               my.blue = 255;

               my.green = 255;

               my.red = 255;                

               wait (1);

       }

       while (event_type == event_release)

       {

               my.lightrange = 0;

               my.blue = 0;

               my.green = 0;

               my.red = 0;                

               wait (1);

       }

}

 

action my_entity

{

       my.enable_touch = on;

       my.enable_release = on;

       my.event = entity_glow;

       // the rest of the code for your entity would go here

}

 

 

F: Wie kann ich eine Explosion als Stereo-Geräusch abspielen?

A: Verwenden Sie media_play mit einem Stereo-Effekt oder manipulieren Sie Ihre Wave Datei, indem Sie den Sound auf einem Kanal leicht verzögern.

 

sound explomono_wav = <explomono.wav>;

 

function explosion()

{

       media_play ("explosion.wav", null, 100); // use a stereo explosion.wav sound effect

}

 

function fake_stereo() // uses a monophonic explosion sound

{

       snd_play (explomono_wav, 100, -100); // play the explosion from the left speaker

       sleep (0.1); // play with 0.1

       snd_play (explomono_wav, 100, 100); // now play the same explosion from the right speaker

}

 

on_e = explosion;

on_f = fake_stereo;

 

 

F: Ich möchte, dass mein Waffenmodel eine Animation abspielt, wenn die linke Maustaste zum Feuern gedrückt wird. Wie geht das?

A: Definieren Sie Ihre Waffe als "entity" - und verwenden Sie dann folgenden Code.

 

entity my_weapon

{

       type = <my_weapon.mdl>;

       x = 25; // 25 quants ahead of the view, play with this value

       y = -12; // 12 quants towards the right side of the screen, play with this value

       z = -9; // 9 quants below, play with this value

       pan = 2; // weapon's pan angle (you can also use tilt and roll)

       flags = visible;

}

 

starter animate_weapon()

{

       proc_kill(4); // don't allow more than 1 instance of this function to run

       while (my_weapon.frame < 10) // the weapon has 10 animation frames

       {

               my_weapon.frame += 2 * time_step; // 2 sets the animation speed

               wait (1);        

       }

       my_weapon.frame = 1; // restore the initial animation frame

}

 

on_mouse_left = animate_weapon;

 

 

F: Ich habe ein Model, das nur die "stand" Animation hat, aber mit Bones ausgestattet ist. Wie spiele ich nur diese Animation in einer Schleife ab?

A: Hier ist ein einfaches Beispiel.

 

action loop_bones

{

       var anim_speed;

       while(1)

       {

               ent_animate(my, NULL, 0, 0); // not really needed here

               anim_speed += 2 * time_step; // 2 = animation speed

               ent_animate(my, "stand", anim_speed, ANM_CYCLE);

               wait (1);

       }

}

 

 

F: Ich möchte gern mehrere Bilder in bestimmer Reihenfolge anzeigen, entsprechend dem Wert einer Variablen.

A: Verwenden Sie folgenden Code.

 

entity sprite_entity // adjust x, y, z until the picture is placed properly on the screen

{

       type = <pictures+6.tga>; // display 6 pictures

       x = 1000; // 100 quants ahead of the view, play with this value

       y = 280; // 280 quants towards the left side of the screen, play with this value

       z = -100; // 100 quants below, play with this value

       flags = visible;

}

 

starter change_picture()

{

       while (1)

       {

               sprite_entity.frame += 0.03 * time_step;

               if (sprite_entity.frame >= 7)

               {

                       sprite_entity.frame = 1;

               }

               wait (1);

       }

}

 

 

F: Gibt es eine Möglichkeit, einen String in einer externen .txt Datei zu speichern? Ich brauche das für ein Frage und Antwort Quizspiel.

A: Hier ist entsprechender Code.

 

string temp1_str = "evolution ";

string temp2_str = "is ";

string temp3_str = "progress ";

string temp4_str = "! ";

string temp5_str = "? ";

 

string temporary_str = "                                                                  "; // allow long quotes

 

var filehandle;

 

starter random_quotes()

{

       randomize();

}

 

function save_quote() // generates random, "wise" quotes

{

       var index;

       index = random(7);

       var tempo = 0;

       str_cpy (temporary_str, ""); // reset the string

       while (index > 0)

       {

               tempo = random (1);

               if (tempo <= 0.2)

               {

                       str_cat (temporary_str, temp1_str);

               }

               if ((tempo > 0.2) && (random (1) <= 0.4))

               {

                       str_cat (temporary_str, temp2_str);

               }

               if ((tempo > 0.4) && (random (1) <= 0.6))

               {

                       str_cat (temporary_str, temp3_str);

               }

               if ((tempo > 0.6) && (random (1) <= 0.8))

               {

                       str_cat (temporary_str, temp4_str);

               }

               if (tempo > 0.8)

               {

                       str_cat (temporary_str, temp5_str);

               }

               index -= 1;

       }

       // the quote was stored inside temporary_str here, so let's save it

       filehandle = file_open_write ("important_quote.txt");

       file_str_write (filehandle, temporary_str);

       file_close (filehandle);

}

 

on_s = save_quote; // press "S" to generate a new quote and save it to the "important_quote.txt" file on the disk

 

 

F: Ich brauche eine Action, die dafür sorgt, dass der Spieler stirbt, wenn er ein Model berührt. Wie geht das?

A: Benutzen Sie einfach event_impact.

 

function kill_player()

{

       if (you == player) // the player has touched the killer entity?

       {

               player.skill99 = 0; // kills the player if its health is stored inside skill99

       }

}

 

action killer_entity

{

       my.enable_impact = on;

       my.event = kill_player;

}

 

 

F: Ich habe ein Problem mit meinem Charakter; er bewegt sich zu schnell. Wie kann ich ihn verlangsamen und wo kann ich die Optionen für die Bewegung einstellen? Ich verwende eine 3rd Person Kamera und PlBiped01 für meinen Spieler.

A: Klicken Sie mit der rechten Maustaste auf Ihr Model und wählen dann "Behavior". Editieren Sie die Werte im "Movement" Abschnitt, um die Geschwindigkeit zu ändern und die im "Animation" Abschnitt, um die Geschwindigkeit der Animation anzupassen. Im Template Abschnitt von AUM 59 finden Sie weitere Informationen.

 

 

F: Wie kann ich Partikel erstellen, die über ein bestimmtes Gebiet, wie z.B. eine Brücke, fließen?

A: Benutzen Sie folgenden Code.

 

bmap flame_pcx = <flame.pcx>;

 

function flame_particles()

{

       my.alpha -= 1 * time; // particle fading speed

       if (my.alpha < 0) {my.lifespan = 0;}

}

 

function torch_fx()

{

       temp.x = random(1) - 2; // play with x, y, z

       temp.y = random(1) - 4;

       temp.z = random(1) + 2;

       vec_normalize (temp, 20); // particle speed

       vec_add(my.vel_x, temp);

       my.bmap = flame_pcx;

       my.flare = on;

       my.bright = on;

       my.size = 20; // particle size

       my.move = on;

       my.beam = on;

       my.gravity = 1.2; // particle gravity

       my.function = flame_particles;

       my.lifespan = 100; // particle life span

}

 

action particle_generator

{

       my.invisible = on;

       my.passable = on;

       while (1)

       {

               effect (torch_fx, 5, my.x, normal); // generate 5 particles per frame

               wait (1);

       }

}

 

aum62_faq1