Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   A problem with getangle (https://forums.graalonline.com/forums/showthread.php?t=76592)

Kyranki 09-01-2007 03:12 AM

A problem with getangle
 
Currently scripting some custom projectiles however I'm having a problem with my getangle();

PHP Code:

/*

  ** Custom Projectile Notes **
: Attributes
  - Attr 1: Base Direction
  - Attr 2: Speed Calc
  - Attr 3: P-Type, (Random, Track)
  - Attr 4: Tracking Who/Owner, (String: Npc, Player)
  - Attr 5: (Npc/Player Id
  - Attr 6: Coords of mouse click
 
: Variables
  - Speed: How fast this projectile will travel
 
*/
function onCreated() {
  
canwarp();
  
canwarp2();
  
  
setimg("block.png");
  
setTimer(0.1);
}
function 
onTimeout() {
  if (
this.attr[3] == "random") {
    echo(
"Projectile: Has a randomized movement pattern.");
  }
  else if (
this.attr[3] == "track") {
    
temp.obj this.attr[4] == "npc" this.level.npcs[this.attr[5]] : this.level.players[this.attr[5]];
    if (
temp.obj.objecttype() in {"TServerPlayer""TServerNPC"}) {
      
temp.tx temp.obj.x;
      
temp.ty temp.obj.y;
    
      
this.dir getdir((temp.tx this.x), (temp.ty this.y));
      
this.attr[1] = getangle((temp.tx this.x), (temp.ty this.y));
    }
  }
  
this.chat "Direction: " this.dir;
  if (
onwall(this.xthis.y))
    
destroy();
  for (
temp.pl this.level.players) {
  }
  for (
temp.nc this.level.npcs) {
  }
  
this.+= cos(this.attr[1]);
  
this.+= sin(this.attr[1]);
   
  
setTimer(1);
}
function 
onPlayerChats() {
  if (
player.account in serveroptions.staffdevaccess.tokenize(",")) {
    if (
player.chat == ":destroy") {
      
destroy();
    }
  }


The major problem is where I use getangle to set this.attr[1]. It's getting the wrong angle tho that should work.

It's moving in an arc away from the player like this... _|

DustyPorViva 09-01-2007 06:47 AM

add(or subtract, I don't remember) pi/2 to the angle.

Kyranki 09-01-2007 07:29 AM

Neither worked Dusty. :(

Chompy 09-01-2007 01:37 PM

PHP Code:

// for player direction
getangle(vecx(temp.obj.dir), vecy(temp.obj.dir));

// to a target
getangle((this.temp.tx), (this.temp.ty));

// to the mouse
getangle((mousex temp.tx), (mousey temp.ty)); 



Well.... to the point:
PHP Code:

getangle((temp.tx this.x), (temp.ty this.y)); 

Change it into:

PHP Code:

getangle((this.temp.tx), (this.temp.ty)); 


Kyranki 09-01-2007 05:29 PM

Well, Chompy what you said to do was a step in the right direction. It's just going around the player now.

Before what I originally had
PHP Code:

temp.tx this.

worked in another projectile test.

Chompy 09-01-2007 09:10 PM

PHP Code:

this.+= cos(this.attr[1])*speed;
this.+= sin(this.attr[1])*speed


Kyranki 09-02-2007 01:30 AM

Didn't work Chompy, the main problem I think is getangle() not working properly. Considering getdir() is working perfectly fine with the same calculations I had in my original post.

Kyranki 09-02-2007 05:05 AM

Problem Solved.

It was where I was calculating the this.x and this.y. I added to the y when I was supposed to be subtracting from it. =D


All times are GMT +2. The time now is 06:13 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.