To create an entity (a bullet, in your case) at runtime, you must use the ent_create() function. Here's an example.

Code:
var allow_fire = 1;

action bullet_act()
{
  while( my )
  {
    // we must use IGNORE_PUSH to prevent the bullet from getting stuck in the player

    c_move( my, vector( 32*time_step, 0, 0 ), nullvector, IGNORE_PASSABLE | IGNORE_PUSH );

    if( trace_hit ) // this is true if I hit an object
      ent_remove(my);

    wait(1);
  }
}

action player_act()
{
  my.push = -1;
  while( my )
  {
    if( key_space && allow_fire ) // if key_space is pressed...
    {
      your = ent_create( "bullet.mdl", my.x, bullet_act ); // fire a bullet

      vec_set( your.pan, my.pan ); // set your angles

      allow_fire = 0; // this prevents multiple bullets from appearing whenever the space bar is held down
    }
    if( !key_space ) allow_fire = 1;

    wait(1);
  }
}



Last edited by Redeemer; 04/07/11 19:50.

Eats commas for breakfast.

Play Barony: Cursed Edition!