Fragen aus dem Forum

Top  Previous  Next

Q: Ich habe Probleme damit, den Feind-Code in Workshop 32 aon C-Skript in lite-C zu konvertieren. Können Sie helfen?

A: Hier ist es:

 

STRING* bullet_mdl = "bullet.mdl";

 

function fire_bullets(); // creates the bullets

function remove_bullets(); // removes the bullets after they've hit something

function got_shot();

function move_enemy_bullets();

 

#define idle 1

#define attacking 2

#define dead 3

#define status skill1

#define health skill10

 

function fire_bullets()

{

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

       while (mouse_left) {wait (1);} // wait until the player releases the mouse button

       ent_create (bullet_mdl, camera.x, move_bullets); // create the bullet at camera's position and attach it the "move_bullets" function

}

 

function remove_bullets() // this function runs when the bullet collides with something

{

       wait (1); // wait a frame to be sure (don't trigger engine warnings)

       ent_remove (my); // and then remove the bullet

}

 

action my_enemy() // attach this action to your enemies

{

       while (!player) {wait (1);}

       var idle_percentage = 0;

       var run_percentage = 0;

       var death_percentage = 0;

       VECTOR content_right; // tracks the content in front of the player

       VECTOR content_left; // tracks the content in front of the player

       VECTOR temp;

       set (my, POLYGON); // use accurate collision detection

       my.health = 100;

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY); // the enemy is sensitive to impact with player's bullets

       my.event = got_shot; // and runs this function when it is hit

       my.status = idle; // that's the same thing with my.skill1 = 1; (really!)

       while (my.status != dead) // this loop will run for as long as my.skill1 isn't equal to 3

       {

               if (my.status == idle) // hanging around?

               {

                       ent_animate(my, "stand", idle_percentage, ANM_CYCLE); // play the "stand" aka idle animation

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

                       if (vec_dist (player.x, my.x) < 1000) // the player has come too close?

                       {

                               // scanned in the direction of the pan angle and detected the player?

                               if ((c_scan(my.x, my.pan, vector(120, 60, 1000), IGNORE_ME) > 0) && (you == player))

                               {

                                       my.status = attacking; // then attack the player even if it hasn't fired at the enemy yet

                               }

                       }

               }

               if (my.status == attacking) // shooting at the player?

               {

                       // the road is clear? then rotate the enemy towards the player

                       if (c_content (content_right.x, 0) + c_content (content_left.x, 0) == 2)

                       {

                               vec_set(temp, player.x);

                               vec_sub(temp,my.x);

                               vec_to_angle(my.pan, temp); // turn the enemy towards the player

                       }

                       if (vec_dist (player.x, my.x) > 500)

                       {

                               vec_set(content_right, vector(50, -20, -15));

                               vec_rotate(content_right, my.pan);

                               vec_add(content_right.x, my.x);

                               if (c_content (content_right.x, 0) != 1) // this area isn't clear?

                               {

                                       my.pan += 5 * time_step; // then rotate the enemy, allowing it to avoid the obstacle

                               }

                               vec_set(content_left, vector(50, 20, -15));

                               vec_rotate(content_left, my.pan);

                               vec_add(content_left.x, my.x);

                               if (c_content (content_left.x, 0) != 1) // this area isn't clear?

                               {

                                       my.pan -= 5 * time_step; // then rotate the enemy, allowing it to avoid the obstacle

                               }

                               c_move (my, vector(10 * time_step, 0, 0), nullvector, GLIDE);

                               ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation

                               run_percentage += 6 * time_step; // "6" controls the animation speed

                       }

                       else

                       {

                               ent_animate(my, "alert", 100, NULL); // use the last frame from the "alert" animation here

                       }

                       if ((total_frames % 80) == 1) // fire a bullet each second

                       {

                               vec_for_vertex (temp, my, 8);

                               // create the bullet at enemy's position and attach it the "move_enemy_bullets" function

                               ent_create (bullet_mdl, temp, move_enemy_bullets);

                       }

                       if (vec_dist (player.x, my.x) > 1500) // the player has moved far away from the enemy?

                       {

                               my.status = idle; // then switch to "idle"

                       }

               }

               wait (1);

       }

       while (death_percentage < 100) // the loop runs until the "death" animation percentage reaches 100%        

       {

               ent_animate(my, "deatha", death_percentage, NULL); // play the "die" animation only once

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

               wait (1);

       }

       set (my, PASSABLE); // allow the player to pass through the corpse now

}

 

function got_shot()

{

       if (you.skill30 != 1) {return;} // didn't collide with a bullet? Then nothing should happen

       my.health -= 35;

       if (my.health <= 0) // dead?

       {

               my.status = dead; // stop the loop from "action my_enemy"

               my.event = NULL; // the enemy is dead, so it should stop reacting to other bullets from now on

               return; // end this function here

       }

       else // got shot but not (yet) dead?

       {

               my.status = attacking; // same thing with my.skill1 = 2

       }

}

 

function move_enemy_bullets()

{

       VECTOR bullet_speed; // this var will store the speed of the bullet

       my.skill30 = 1; // I'm a bullet

       // the bullet is sensitive to impact with other entities and to impact with level blocks

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);

       my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run

       my.pan = you.pan; // the bullet has the same pan

       my.tilt = you.tilt; // and tilt with the enemy

       bullet_speed.x = 50 * time_step; // adjust the speed of the bullet here

       bullet_speed.y = 0; // the bullet doesn't move sideways

       bullet_speed.z = 0; // or up / down on the z axis

       // the loop will run for as long as the bullet exists (it isn't "null")

       while (my)

       {

               // move the bullet ignoring its creator (the enemy)

               c_move (my, bullet_speed, nullvector, IGNORE_YOU);

               wait (1);

       }

}

 

 

Q: Ich habe ein Spiel gemacht, das mit 1024 x768 Pixeln läuft. Als ich es aber auf einem Monitor mit einem Breitbildschirm (1440 x 900 Pixel) versuchte, stellte fest, dass das Bild nicht scharf ist. Gibt es irgendeine Möglichkeit die Schärfe der Bilder unabhängig von der Auflösung wieder herzustellen?

A: Die beste Methode ist die, das Spiel in derselben Auflösung wie Ihr Display zu starten. Hier ein Schnipselchen, das das automatisch macht.

 

function main()

{

       video_set(sys_metrics(0), sys_metrics(1), 32, 1); // detect and use the best screen resolution

       level_load (test_wmb);

       // put the rest of your code here

}

 

 

Q: Ich weiß, dass man in C-Skript Breite oder Höhe von Buchstaben in einem speziellen Font bestimmen kann, indem man die Eigenschaften .char_x und .char_y benutzt. Im lite-C-Handbuch kann ich die aber nicht finden. Wurde das aus der Language herausgenommen? Wie bestimmt man die Höhe eines Buchstabens für einen Font in lite-C?

A: Höhe und Breite der Fonts werden in lite-C automatisch berechnet. Wenn Sie aber trotzdem gerne Höhe und Breite eines Buchstabens aus einem gebitmappten Font wissen wollen, können Sie das folgende Stück Code verwenden:

 

var char_width, char_height;

 

BMAP* ethnocentric18_tga = "ethnocentric18.tga";

 

FONT* arial_font = "Arial#20b";

 

function check_font(BMAP* font_bitmap) // checks bitmapped fonts with up to 4 rows of characters

{

       if (bmap_width(font_bitmap) % 11 == 0) // the image width is divisible by 11? Then it's a single row font!

       {

               char_width = bmap_width / 11;

               char_height = bmap_height;                                

       }

       else // we've got a font that consists of 4 rows, each one of them having 32 characters here

       {

               char_width = bmap_width(font_bitmap) / 32;

               char_height = bmap_height(font_bitmap) / 4;

       }

}

 

PANEL* font_pan =

{        

       pos_x = 0;

       pos_y = 0;

       layer = 15;

       digits(10, 5, "Font character width: %.0f", arial_font, 1, char_width);

       digits(10, 25, "Font character height: %.0f", arial_font, 1, char_height);

       flags = SHOW;

}

 

function test_fonts_startup()

{

       wait (-5); // wait until the level is loaded

       check_font(ethnocentric18_tga); // use your own font(s) here

}

 

 

Q: Ich brauche einen Feind, der auf den Player zugeht bis er noch 100 Quants von ihm entfernt ist und der diesen Abstand dann einhält. Auch dann, wenn der Player auf ihn zugeht, sollte der Feind zurückweichen und diese 100 Quants zwischen sich und dem Player einhalten.

A: Verwenden Sie den folgenden Schnipsel als Grundlage für Ihren Code:

 

#define idle 1

#define following 2

#define dead 3

#define status skill1

 

action my_enemy() // attach this action to your enemies

{

       while (!player) {wait (1);}

       var idle_percentage = 0;

       var run_percentage = 0;

       VECTOR temp;

       set (my, POLYGON); // use accurate collision detection

       my.status = idle; // that's the same thing with my.skill1 = 1; (really!)

       vec_set (temp.x, my.x); // trace 10,000 quants below the player

       temp.z -= 10000;

       my.z -= c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 20; // play with 20

       while (my.status != dead) // this loop will run for as long as my.skill1 isn't equal to 3

       {

               vec_set (temp.x, my.x); // trace 10,000 quants below the player

               temp.z -= 10000;

               temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 20; // play with 20

               if (my.status == idle) // hanging around?

               {

                       ent_animate(my, "stand", idle_percentage, ANM_CYCLE); // play the "stand" aka idle animation

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

                       if (vec_dist (player.x, my.x) < 1000) // the player has come too close?

                       {

                               // scanned in the direction of the pan angle and detected the player?

                               if ((c_scan(my.x, my.pan, vector(120, 60, 1000), IGNORE_ME) > 0) && (you == player))

                               {

                                       my.status = following; // then attack the player even if it hasn't fired at the enemy yet

                               }

                       }

               }

               if (my.status == following) // shooting at the player?

               {

                       vec_set(temp, player.x);

                       vec_sub(temp,my.x);

                       vec_to_angle(my.pan, temp); // turn the enemy towards the player

                       if (vec_dist (player.x, my.x) > 100) // the distance between player and enemy is bigger than 100 quants?

                       {

                               c_move (my, vector(10 * time_step, 0, temp.z), nullvector, GLIDE); // move towards the player

                               ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation

                               run_percentage += 6 * time_step; // "6" controls the animation speed, using normal animation

                       }

                       if (vec_dist (player.x, my.x) < 90) // the distance between player and enemy is smaller than 90 quants?

                       {

                               c_move (my, vector(-10 * time_step, 0, temp.z), nullvector, GLIDE); // move away from the player

                               ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation

                               run_percentage -= 6 * time_step; // "6" controls the animation speed, using a reversed animation

                       }

                       if (vec_dist (player.x, my.x) > 500) // the player has moved far away from the enemy?

                       {

                               my.status = idle; // then switch to "idle"

                       }

               }

               wait (1);

       }

       set (my, PASSABLE); // allow the player to pass through the corpse now

}

 

 

Q: Wie kann ich auf dem Boden einen Kreis um eine Entity machen?

A: Die einfachste Methode ist es, ein passables tga-Sprite zu nehmen.

 

STRING* circle_tga = "circle.tga";

 

function adjust_circle()

{

       set (my, PASSABLE);

       my.tilt = 90;

       while (1)

       {

               vec_set (my.x, you.x);

               my.z = you.min_z + 35; // place the circle 35 quants above the entity's min_z value, play with 35

               wait (1);

       }

}

 

action my_entity() // moves the entity in a circle

{

       var anim_percentage = 0;

       ent_create(circle_tga, my.x, adjust_circle);

       while (1)

       {

               anim_percentage += 3 * time_step; // 3 = "walk" animation speed

            ent_animate(my, "walk", anim_percentage, ANM_CYCLE); // play the "walk" animation

               c_move (my, vector(5 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

               my.pan += 2 * time_step; // 2 sets the radius of the circle

               wait (1);

       }

}

 

aum88_faq1

 

 

Q: Ich programmiere meine Waffen und würde gerne wissen, wie man diese korrekt animiert. Wenn ich die linke Maustaste gedrückt halte, sollte das Gewehr korrekt animiert werden und nur eine Kugel pro Sekunde abschiessen. Können Sie mir helfen?

A: Hier ist der Code für eine animierte Waffe, die eine Kugel pro Sekunde abfeuert.

 

var front_offset = 30; // animates player's weapon while it is firing by moving it backwards

var init_offset = 30; // stores front_offset's value

 

ENTITY* weapon1;

 

STRING* bullet_mdl = "bullet.mdl";

 

SOUND* bullet_wav = "bullet.wav";

 

function fire_bullets();

function move_bullets();

function remove_bullets();

 

action players_weapon() // place your weapon model in the level and attach it this action

{

       weapon1 = my; // I'm weapon1

       VECTOR player1_pos; // stores the initial position of the player

       VECTOR player2_pos; // stores the position of the player after a frame

       VECTOR weapon_offset;

       var weapon_height;

       set (my, PASSABLE); // the weapon model is passable

       while (!player) {wait (1);} // wait until the player is created

       while (vec_dist (player.x, my.x) > 50) {wait (1);} // wait until the player comes close to pick up the weapon

       my.roll = 0;

       while (1)

       {

               vec_set (player1_pos.x, player.x); // store the initial player position

               // place the weapon 30 quants in front, 18 quants to the right and 20 quants below camera's origin

               vec_set (weapon_offset.x, vector (front_offset, -18, -20));

               if (vec_dist (player1_pos.x, player2_pos.x) != 0) // the player has moved during the last frame?

               {

                       weapon_height += 30 * time_step; // then offset weapon_height (30 = weapon waving speed)

                       weapon_offset.z += 0.3 * sin(weapon_height); // (0.3 = weapon waving amplitude)

               }

               // rotate weapon_offset according to the camera angles

               vec_rotate (weapon_offset.x, vector (camera.pan, camera.tilt, 0));

               vec_add (weapon_offset.x, camera.x); // add the camera position to weapon_offset

               vec_set (my.x, weapon_offset.x); // set weapon's coords to weapon_offset

               my.pan = camera.pan; // use the same camera angles for the weapon

               my.tilt = camera.tilt;

               vec_set (player2_pos.x, player.x); // store the new player coordinates after 1 frame

               wait (1);

       }

}

 

function weapon_startup()

{

       on_mouse_left = fire_bullets; // call function fire_bullets() when the left mouse button is pressed

}

 

function fire_bullets() // includes the code that animates the weapon as well

{

       var temp_seconds = 0;

       VECTOR temp;

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

       while (mouse_left) // this loop runs for as long as the left mouse button is pressed

       {

               front_offset -= 1; // move the weapon backwards a bit

               vec_for_vertex (temp.x, weapon1, 29); // get the coordinates for the bullets' origin

                // create the bullet at camera's position and attach it the "move_bullets" function

               ent_create (bullet_mdl, temp.x, move_bullets);

               temp_seconds = 0;

               snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100

               while (temp_seconds < 0.5)

               {

                       temp_seconds += time_step / 16; // adds 0.5 to temp_seconds in 0.5 seconds)

                       front_offset -= 0.1; // restore the position of the weapon

                       wait (1);

               }

               while (front_offset < init_offset)

               {

                       front_offset += 0.1; // restore the position of the weapon

                       wait (1);

               }

               front_offset = init_offset;

       }

}

 

function move_bullets()

{

       VECTOR bullet_speed; // stores the speed of the bullet

       my.skill30 = 1; // I'm a bullet

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);

       my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run

       my.pan = camera.pan; // the bullet has the same pan

       my.tilt = camera.tilt; // and tilt with the camera

       bullet_speed.x = 200 * time_step; // adjust the speed of the bullet here

       bullet_speed.y = 0; // the bullet doesn't move sideways

       bullet_speed.z = 0; // then don't allow the gravity to have its ways with the bullet

       while (my) // this loop will run for as long as the bullet exists (it isn't "null")

       {

               // move the bullet ignoring the passable entities and store the result in distance_covered

               c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);

               wait (1);

       }

}

 

function remove_bullets() // this function runs when the bullet collides with something

{

       wait (1); // wait a frame to be sure (don't trigger engine warnings)

       ent_remove (my); // and then remove the bullet

}

 

 

Q: Weiß irgendjemand wie man einen Mündungsfeuer-Effekt vor ein animierte Waffenmodell kriegt?

A: So geht es:

 

ENTITY* weapon1;

 

STRING* bullet_mdl = "bullet.mdl";

STRING* muzzle_tga = "muzzle.tga";

STRING* explosion_pcx = "explosion+5.pcx"; // explosion sprite

 

SOUND* bullet_wav = "bullet.wav";

 

function fire_bullets();

function move_bullets();

function remove_bullets();

function display_muzzle();

function explosion_sprite();

 

action players_weapon() // place your weapon model in the level and attach it this action

{

       VECTOR weapon_offset;

       weapon1 = my; // I'm weapon1

       set (my, PASSABLE); // the weapon model is passable

       while (!player) {wait (1);} // wait until the player is created

       while (1)

       {

               // place the weapon 30 quants in front, 18 quants to the right and 20 quants below camera's origin

               vec_set (weapon_offset.x, vector (30, -18, -20));

               // rotate weapon_offset according to the camera angles

               vec_rotate (weapon_offset.x, vector (camera.pan, camera.tilt, 0));

               vec_add (weapon_offset.x, camera.x); // add the camera position to weapon_offset

               vec_set (my.x, weapon_offset.x); // set weapon's coords to weapon_offset

               my.pan = camera.pan; // use the same camera angles for the weapon

               my.tilt = camera.tilt;

               wait (1);

       }

}

 

function weapon_startup()

{

       on_mouse_left = fire_bullets; // call function fire_bullets() when the left mouse button is pressed

}

 

function fire_bullets() // includes the code that animates the weapon as well

{

       VECTOR temp;

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

       while (mouse_left) // this loop runs for as long as the left mouse button is pressed

       {

               vec_for_vertex (temp.x, weapon1, 29); // get the coordinates for the bullets' origin

                // create the bullet at camera's position and attach it the "move_bullets" function

               ent_create (bullet_mdl, temp.x, move_bullets);

               ent_create (muzzle_tga, temp.x, display_muzzle); // create the gun muzzle

               snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100

               wait (-0.1); // fire 10 bullets per second

       }

}

 

function move_bullets()

{

       VECTOR bullet_speed; // stores the speed of the bullet

       my.skill30 = 1; // I'm a bullet

       my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);

       my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run

       my.pan = camera.pan; // the bullet has the same pan

       my.tilt = camera.tilt; // and tilt with the camera

       bullet_speed.x = 200 * time_step; // adjust the speed of the bullet here

       bullet_speed.y = 0; // the bullet doesn't move sideways

       bullet_speed.z = 0; // then don't allow the gravity to have its ways with the bullet

       while (my) // this loop will run for as long as the bullet exists (it isn't "null")

       {

               // move the bullet ignoring the passable entities and store the result in distance_covered

               c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);

               wait (1);

       }

}

 

function remove_bullets() // this function runs when the bullet collides with something

{

       wait (1); // wait a frame to be sure (don't trigger engine warnings)

       ent_create (explosion_pcx, my.x, explosion_sprite); // create the explosion sprite

       set (my, INVISIBLE | PASSABLE);

       wait (-2); // wait until the explosion_sprite() function is over

       ent_remove (my); // and then remove the bullet

}

 

function display_muzzle()

{

       set (my, PASSABLE | BRIGHT);

       my.roll = 0.01;

       my.ambient = 100; // and this line makes it even brighter

       my.pan = weapon1.pan; // has the same pan and tilt

       my.tilt = weapon1.tilt; // with the weapon

       my.roll = random(360); // and a random roll angle (looks nicer)

       my.scale_x = 0.3; // we scale it down

       my.scale_y = my.scale_x; // on all the axis

       my.scale_z = my.scale_z; // this would only be needed for a 3D (model-based) muzzle

       weapon1.ambient = 100; // highlight the weapon (makes it look more realistic)

       wait (2); // show the muzzle sprite for 2 frames

       weapon1.ambient = 0; // restore the normal weapon ambient value

       ent_remove (my); // and then remove it

}

 

function explosion_sprite()

{

       set (my, PASSABLE | BRIGHT | TRANSLUCENT);

       my.scale_x = 0.15; // we scale it down to 0.15

       my.scale_y = my.scale_x; // on both axis

       my.ambient = 100; // and we give it an ambient of 100

       my.roll = random(360); // we set a random roll angle

       my.alpha = 100; // but we set it to be completely opaque for now

       while (my.frame < 5) // go through all the animation frames

       {

               my.frame += 2 * time_step; // animation speed

               wait (1);

       }

       while (my.alpha > 0) // now fade the last frame quickly

       {

               my.alpha -= 50 * time_step; // 50 = fading speed

               wait (1);

       }

       ent_remove (my);

}

 

aum88_faq2

 

 

Q: Ich weiß wie man den Befehl ent_animate benutzt, aber ich weiß nicht, wie ich die Animationsszenen in MED hinkriege. Mein Modell 101 Animationsframes. Wie richte ich die ein, damit ich sie mit ent_animat benutzen kann?

A: Hier eine Schritt-für-Schritt-Erklärung:

 

1) Öffnen Sie Ihr Modell in MED und klicken Sie den Knopf "Animate" am unteren Bildschirmrand.

 

aum88_faq3

 

2) Untersuchen Sie die Animationsframes sorgfältig. Entscheiden Sie, welches die Frames für die erste Szene (bei meinem Modell ist das "walk") sein werden. Klicken Sie den Knopf "Play Setup" in der unteren linken Ecke und überprüfen Sie, ob Sie sie richtig erwischt haben oder nicht, indem Sie beobachten wie die Animation aussieht während sie in einer Schleife läuft.

 

aum88_faq4

 

3) Zeit, die Frame-Namen zu ändern. Wählen Sie Edit -> Manage Frames.

 

aum88_faq5

 

4) Wählen Sie die gewünschten (walk-) Frames im "Frames"-Fenster und klicken Sie dann auf den Knopf "Rename Frames". Ich habe beschlossen, die Geh-Frames meines Modells "walk" zu nennen.

 

aum88_faq6

 

5) Wiederholen Sie den Prozess für den Rest Ihrer Animationen. Zum Schluß werden Sie Animationsframes wie "walk", "stand" usw. haben und die können mit ent_animate benutzt werden.

 

 

Q: Ist es möglich, die Textur eines Blocks in einem bestimmten Bereich meines Levels zu verändern.

A: Die einfachste Methode ist es, Ihren Block als eine wmb-Entity zu speichern und dann mithilfe von ent_morph durch eine andere, die die gewünschte Textur hat, zu ersetzen.

 

BMAP* pointer_tga = "pointer.tga";

 

function mouse_startup()

       mouse_mode = 2;

       mouse_map = pointer_tga;

       while (1)

       

               vec_set(mouse_pos, mouse_cursor);

               wait(1);

       }

}

 

function replace_block()

{

       ent_morph(me, "newblock.wmb"); // replaces the old block with the new one; newblock.wmb must exist!

       my.event = NULL; // don't react to mouse clicks from now on

}

 

action special_block() // attach this action to your wmb block

{

       // the block will be replaced when the player clicks it using the left mouse button

       // you can replace the block when it is shot, etc.

       my.emask |= ENABLE_CLICK;

       my.event = replace_block;

}

 

 

Q: Wenn ich den Player mit seinem Gesicht dicht an eine Wand heranbewege (einen BSP-Block), mochte ich die Wandtextur prüfen und wissen, ob ihr Name "steel" ist. Ich hätte gerne, dass der Player automatisch seinen Rücken zur Wand kehrt. Wie kann ich das machen?

A: Verwenden Sie diesen Schnipsel:

 

action players_code() // attach this action to your player

{

       var movement_speed = 20; // movement speed

       VECTOR temp, players_sensor;

       set (my, INVISIBLE); // 1st person player

       player = my; // I'm the player

       while (1)

       {

               my.pan -= 7 * mouse_force.x * time_step;

               camera.x = my.x;

               camera.y = my.y;

               camera.z = my.z + 50 + 1.1 * sin(my.skill44); // play with 50 and 1.1

               camera.pan = my.pan;

               camera.tilt = player.tilt;

               vec_set (temp.x, my.x); // trace 10,000 quants below the player

               temp.z -= 10000;

               temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 2; // play with 2

               temp.x = movement_speed * (key_w - key_s) * time_step;

               temp.y = movement_speed * (key_a - key_d) * 0.6 * time_step;

               c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE);

 

               // place the sensor at x = 50, y = 0, z = 0 in relation to the origin of the player model

               vec_set (players_sensor.x, vector(50, 0, 0));

               vec_rotate (players_sensor.x, my.pan);

               vec_add (players_sensor.x, my.x);

 

               if (c_trace (my.x, players_sensor.x, IGNORE_ME | IGNORE_PASSABLE | SCAN_TEXTURE) > 0) // something was hit?

               {

                       if (str_cmpi(tex_name, "steel") == 1) // detected the steel texture?

                               vec_to_angle(my.pan, normal); // then rotate the player according to the normal of the surface!

               }

               wait (1);

       }

}

 

TEXT* message_txt =

{

       pos_x = 200;

       pos_y = 20;

       string(tex_name);

       flags = SHOW;

}