View Single Post
  #3  
Old 03-11-2018, 10:43 PM
MysticalDragon MysticalDragon is offline
Global Administration
MysticalDragon's Avatar
Join Date: Oct 2002
Location: Lynn Ma
Posts: 883
MysticalDragon is a jewel in the roughMysticalDragon is a jewel in the rough
Send a message via AIM to MysticalDragon Send a message via MSN to MysticalDragon
Quote:
Originally Posted by kittygirl765 View Post
Oh, this is actually a good starting place for a state machine (especially for gscript2, where making ai isn't easily done natively or ends up becoming spaghetti code)

Now I need to make an ai_execute_firing_my_lasers() function

PHP Code:
function ai_enter_float() { 
  
this.ani = "idle"; 
  
this.aiPeriod = 1; 
} 

function 
ai_execute_float() { 
  
temp.pl = this.acquireTarget(); //you can do findnearestplayers to see if there is a target
  
if (temp.pl != nil) {
    
this.ani = "alert";
    
changeState("attack");
    return;
  }
  
//logic here move? 
  
this.ani = "move"; 
}

function 
ai_enter_attack() {
  
this.aiPeriod = 0.4 * this.attack_speed;
}

function 
ai_execute_attack() {  
   
temp.target = this.acquireTarget();
  if (
temp.target == nil) {
    
changeState("float");
    return;
  }
  
attack(temp.target);
}

function 
attack(temp.target) {
  
temp.pos_x = this.x + 0.5 + vecx( this.dir ) * 1.5;
  
temp.pos_y = this.y - 1 + vecy( this.dir ) * 1.5;
  
temp.angle = getangle( temp.target.x - temp.pos_x, temp.target.y - temp.pos_y );
  
temp.speed = 1;
  
setshootparams( this, temp.dmg, params);
  
shoot(
     
temp.pos_x, temp.pos_y, 0,
     
temp.angle, 0.1, temp.speed,
     
this.ani_arrow, null
   
);
}

function 
acquireTarget() {
  
// Add aggro to players near entity
  
temp.targets = findnearestplayers(this.x, this.y);
  return 
temp.targets[0];
} 
__________________
~Delteria Support
~Playerworld Support
~PWA Chief
http://support.toonslab.com
[email protected]




Last edited by MysticalDragon; 03-11-2018 at 11:01 PM..
Reply With Quote