Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-01-2007, 03:12 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
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... _|
__________________
Stan.
Reply With Quote
  #2  
Old 09-01-2007, 06:47 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
add(or subtract, I don't remember) pi/2 to the angle.
Reply With Quote
  #3  
Old 09-01-2007, 07:29 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Neither worked Dusty.
__________________
Stan.
Reply With Quote
  #4  
Old 09-01-2007, 01:37 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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)); 
__________________
Reply With Quote
  #5  
Old 09-01-2007, 05:29 PM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
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.
__________________
Stan.
Reply With Quote
  #6  
Old 09-01-2007, 09:10 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
PHP Code:
this.+= cos(this.attr[1])*speed;
this.+= sin(this.attr[1])*speed
__________________
Reply With Quote
  #7  
Old 09-02-2007, 01:30 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
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.
__________________
Stan.
Reply With Quote
  #8  
Old 09-02-2007, 05:05 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
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
__________________
Stan.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:12 AM.


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