Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 911 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: How do I...structures [Re: EvilSOB] #234459
11/03/08 01:04
11/03/08 01:04
Joined: May 2006
Posts: 53
Puerto Rico
monchito Offline OP
Junior Member
monchito  Offline OP
Junior Member

Joined: May 2006
Posts: 53
Puerto Rico
Hi:
Thanks for the reply. When I tested with the global structures and worked ok the first logical thinking was the local created structures got destroyed. The need for using malloc is a must....but...
Can't share the same action function like the C-script for a bunch of entities.
Still learning
Thanks a lot.
Code:
[/code]
#include <acknex.h> 
#include <default.c>
////////////////////////////////////////////////////////////////////
var video_depth = 32; // 32 bit mode
var d3d_lockable = 1;

typedef struct
{
   int health;
   int shield;
   int state;
   int pathnode;
   int lin_speed;
   int rot_speed;
   int anim_speed;
   int range;
   int weapon_type;
   int weapon;
   int weapon_range;
   int ammo;
   ENTITY* model;
}entity3d; 

entity3d npc[5];
STRING* buff = "          ";
static int NPC_Counter = 0;

entity3d* player1 = &npc[0];
entity3d* enemy1 = &npc[1];
entity3d* enemy2 = &npc[2];
entity3d* enemy3 = &npc[3];

#define MODE_STAND  0
#define MODE_WALK   1
#define MODE_RUN    2
#define MODE_DEATH  3
#define MODE_ATTACK 4
#define MODE_STOP   5
#define MODE_MARCH  6
#define MODE_STANDBY 7
 
STRING* work01_wmb = "arabcity.wmb";
ENTITY* any;
function all_events(); 
function act_player(entity3d* ent);
function check_downward(ent, vmin, vmax);
function act_enemy(entity3d* ent);
function loadEntity();
entity3d* LoadEntity(STRING* modelname, VECTOR* position);

VECTOR level_min;
VECTOR level_max;

////////////////////////////////////////////////////////////////////
function main()
{
	fps_max = 50;
	level_load (work01_wmb);
   vec_set(level_min,level_ent.min_x);
   vec_set(level_max,level_ent.max_x);
   wait(5);
// loadEntity();   // used on global structures
   
   entity3d* hero = LoadEntity("player.mdl", vector(270,120,20));
   act_player(hero);

   entity3d* enemy = LoadEntity("gangst1.mdl", vector(300,-300, 25));
   act_enemy(enemy);

   entity3d* enemy2 = LoadEntity("gangst1.mdl", vector(200,-300, 25));
   act_enemy(enemy2);
}

function act_player(entity3d* ent)
{
  my = player = ent.model;
  my.scale_x = .5;
  my.scale_y = .5;
  my.scale_z = .5;
  my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT);
  my.event = all_events;

  set(ent.model, INVISIBLE);
  ent.lin_speed = 5;
  ent.rot_speed = 3;
  ent.health = 100;
  ent.range = 250;
  ent.shield = 100;
  
  while(1)
  {
     camera.x = my.x;
     camera.y = my.y;
     camera.z = my.z + 5;
     camera.pan = my.pan;
     camera.tilt = my.tilt;

     move_mode = IGNORE_PASSABLE + USE_BOX;  
      
     if(key_w == 1)
     { 
        ent_move (vector(ent.lin_speed * time_step,0,0), nullvector);

        my.z += .5 * sin(total_ticks * 25) * time_step;


        if(my.tilt < 1)
           my.tilt += .25;
        
        if(my.tilt > 1)
           my.tilt -= .25;
     }
     if(key_s == 1)
     {
     	  ent_move (vector(-ent.lin_speed * time_step,0,0), nullvector);

        if(my.tilt < 1) 
           my.tilt += .25;

        if(my.tilt > 1)
           my.tilt -= .25;
     }

     if(key_a == 1) 
        my.pan += ent.rot_speed * time_step;
     
     if(key_d == 1)
        my.pan -= ent.rot_speed * time_step;
     
     if(key_q == 1)
     { 
       if(my.tilt > 30)
          my.tilt = 30;
          
       my.tilt += 1;
     }

     if(key_z == 1)
     {
     	 if(my.tilt < -30)
     	    my.tilt = -30;
     	 
     	 my.tilt -= 1;
     }
    
   check_downward(my, 10, 13);

   wait(1);
  }
}

function loadEntity()
{
	zero(npc[0]);
	npc[0].model = ent_create ("player.mdl", vector(270,120,20), NULL);
   act_player(npc[0]);
 	
	zero(npc[1]);
 	npc[1].model = ent_create ("gangst1.mdl", vector(300,-300, 25), NULL);   
   act_enemy(npc[1]);
   
	zero(npc[2]);
 	npc[2].model = ent_create ("gangst1.mdl", vector(-300,-300, 45), NULL);
   act_enemy(npc[2]);
}

entity3d* LoadEntity(STRING* modelname, VECTOR* position)
{
   entity3d* ptr = malloc(sizeof(entity3d));
   zero(*ptr);
	ptr->model = ent_create (modelname, position, NULL);
	return (ptr);
}

function all_events() 
{
  switch (event_type)
  {
    case EVENT_BLOCK:
      
      return;
    case EVENT_ENTITY: 

      return;
  }
}  

function check_downward(ent, vmin, vmax)
{
    proc_kill(4);
    var dist;
    VECTOR temp;
    
    my = ent;

    // check downward
    vec_set (temp, my.x);
    temp.z = my.z - 15000;
    trace_mode = IGNORE_ME + IGNORE_SPRITES + USE_BOX + IGNORE_PASSABLE;
    dist = trace (my.x, temp);
    
    // stay above ground
    if(dist < vmin) { my.z += 1; }
    if(dist > vmax) { my.z -= 1; }
    if(dist > (vmax + 5)) { my.z -= 3; }
    if(dist < (vmin - 4)) { my.z += 3; }   
}

function act_enemy( entity3d* ent )
{
  var percent;
  var d1;
  var d2;
  var vmin = 0;
  var vmax = 3;
  VECTOR temp;
  var dist_trace;

  ent.model.scale_x = .4;
  ent.model.scale_y = .4;
  ent.model.scale_z = .4;
      
  while(!player){wait(1);}

  ent.state = MODE_WALK;
  ent.lin_speed = 2;
  ent.rot_speed = 3;
  ent.health = 100;
  ent.range = 250;
  ent.shield = 100;
  ent.anim_speed = 3;

  while(ent.health > 10)
  {
     d1 = vec_dist(ent.model.x, player.x);

    if (ent.state == MODE_WALK)
    {
       percent += ent.anim_speed * time_step;
       ent_animate(ent.model,"walk", percent, ANM_CYCLE);
       percent %= 100;
       
       // obstacle in front...change direction
       if ( ent_move (vector(ent.lin_speed * time_step,0,0), nullvector) < (ent.lin_speed * time_step))
          ent.model.pan += 1.5;
    }
    
    if (ent.state == MODE_ATTACK)
    {
       vec_set(temp,ent.model.x);
       if(vec_dist(ent.model.x, player.x)<1000 && vec_to_screen(temp,camera)!=NULL)
       {
  		   str_for_num(buff, ent.health);
  		   draw_text(buff, temp.x, temp.y-20, vector(200,200,200));
       }
       // perform animation
       percent += ent.anim_speed * time_step;
       ent_animate(ent.model,"attack", percent, ANM_CYCLE);
       percent %= 100;
       // rotate to the target
       vec_set(temp,player.x); 
       vec_sub(temp,ent.model.x);
       vec_to_angle(ent.model.pan,temp);
    }   

    // traced something in range AND is the player
    if((c_trace (ent.model.x, player.x, IGNORE_ME | IGNORE_PASSABLE) < ent.range) && (you == player))
    {  
       d2 = vec_dist(ent.model.x,player.x);
       // i'm moving toward the player
       if((d2 <= d1) && ( ent.health > 30))
       {         	
          ent.state = MODE_ATTACK;
       }
    }
    else
    {
 	   ent.state = MODE_WALK;
    }    
    wait(1);
    check_downward(ent.model, vmin, vmax);
  }
}
[code]


Re: How do I...structures [Re: monchito] #234462
11/03/08 01:42
11/03/08 01:42
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Yes, you CAN share actions like old c-script.
What do you mean by you cant, your last code IS doing so with
act_enemy(). Or am I mis-understanding what you mean?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How do I...structures [Re: EvilSOB] #234487
11/03/08 09:40
11/03/08 09:40
Joined: May 2006
Posts: 53
Puerto Rico
monchito Offline OP
Junior Member
monchito  Offline OP
Junior Member

Joined: May 2006
Posts: 53
Puerto Rico
Hi
I mean that only enemy perfom ok in the function, the others got freeze, they scale down as expected but do nothing. frown
To get the right behavior as C-script i need to:
Code:
[/code]
Do not call the 'act_enemy' as before
function main()
{
   entity3d* enemy = LoadEntity("gangst1.mdl", vector(300,-300, 25));
   //act_enemy(enemy);

   entity3d* enemy2 = LoadEntity("gangst1.mdl", vector(200,-300, 25));
   //act_enemy(enemy);

}

Modify the loading function: included an action function 'act_enemy2' that all enemies will share:
entity3d* LoadEntity(STRING* modelname, VECTOR* position)
{
   entity3d* ptr = malloc(sizeof(entity3d));
   zero(*ptr);
   ptr->model = ent_create (modelname, position, act_enemy2);
   return (ptr);
}

The new function C-script style:

function act_enemy2()
{
  var percent;
  var d1;
  var d2;
  var anim_speed = 2;
  VECTOR temp;
  
  my.scale_x = .4;
  my.scale_y = .4;
  my.scale_z = .4;      
  my.event = all_events;
  my.skill1 = MODE_ATTACK; // entity state
  my.skill2 = 100; //health
  my.skill3 = 200; // range 
  while(!player){wait(1);}
  
  while(my.skill2 > 30)  // in good health
  {
     d1 = vec_dist(my.x, player.x);

    if (my.skill1 == MODE_WALK)
    {    	
       percent += anim_speed * time_step;
       ent_animate(my,"walk", percent, ANM_CYCLE);
       percent %= 100;
       
       // obstacle in front...change direction
       if ( ent_move (vector(4 * time_step,0,0), nullvector) < (anim_speed * time_step))
          my.pan += 1.5;
    }
    
    // traced something in range AND is the player
    if((c_trace (my.x, player.x, IGNORE_ME | IGNORE_PASSABLE) < my.skill3) && (you == player))
    {  
       d2 = vec_dist(my.x,player.x);
       // i'm moving toward the player
       if((d2 <= d1) && ( my.skill2 > 30))
       {         	
          my.skill1 = MODE_ATTACK;
       }
    }
    else
    {
 	my.skill1 = MODE_WALK;
    }    
    
    if (my.skill1 == MODE_ATTACK)
    {
       vec_set(temp,my.x);
       if(vec_dist(me.x, player.x)<1000 && vec_to_screen(temp,camera)!=NULL)
       {
  	  str_for_num(buff, my.skill2);
  	  draw_text(buff, temp.x, temp.y-20, vector(200,200,200));
       }

       percent += anim_speed * time_step;
       ent_animate(my,"attack", percent, ANM_CYCLE);
       percent %= 100;
     
    }   
    wait(1);
 }
}

[code]

Now i can get many enemies moving and targeting player OK
I know...i know... my mind is really a c-script, c-lite, c, mix
crazy
I won't try to how, where and when each interact, better stick to c-script... I'm already know the rules.

Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1