Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Concept Of A Rocket Launcher (https://forums.graalonline.com/forums/showthread.php?t=134264577)

Gunderak 09-17-2011 12:27 PM

Concept Of A Rocket Launcher
 
Here is just a base of what iv made, any suggestions are welcome.
Also if you know how to make the rotation correct by where the mouse is it would be appriciated.
i havnt done any gfx for it yet as i suck at gfx.
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.rocketfired 0;
  
onTimeout();
}

function 
onWeaponfired() {
  if (
this.rocketfired == "1") {
    
this.rx mousex;
    
this.ry mousey;
    
onTimeout();
  }
  
this.rocketfired 1;
}

function 
onTimeout() {
  if (
this.rx mousex) {
    
this.rx++;
  }
  if (
this.ry mousey) {
    
this.ry++;
  }
  if (
this.rx mousex) {
    
this.rx--;
  }
  if (
this.ry mousey) {
    
this.ry--;
  }
  if (
this.rocketfired == "1") {
    
showimg(1"block.png"this.rxthis.ry);
    
player.chat "Rocket Moving!";
  }
  if (
onwall(this.rxthis.ry)) {
    
onExplodeRocket();
  }
  for (
temp.plplayers) {
    if (
this.rx in pl.xpl.2.5 | && this.ry in pl.ypl.| ) {
      
onExplodeRocket();
    }
  }
  
settimer(0.05);
}

function 
onExplodeRocket() {
  if (
this.rocketfired == "1") {
    
putexplosion(1this.rxthis.ry);
    
player.chat "Rocket Exploded!";
    
this.rocketfired 0;
    
hideimg(1);
  }



fowlplay4 09-17-2011 05:43 PM

Determining the angle between two objects.

1. Calculate the Delta between the Origin and the Target
2. Use getangle to return the angle based on the Delta

Note: Delta = Final - Initial

PHP Code:

function getTargetAngle(origintarget) {
  
// Calculate Delta X and Y
  
temp.delta_x target.origin.x;
  
temp.delta_y target.origin.y;
  
// Return Angle Based on Delta
  
return getangle(temp.delta_xtemp.delta_y);


The above will return the correct angle towards the target object.

If you want the Graal direction, you can just swap out getangle with getdir and it'll return a number in |0,3|.

Also:

PHP Code:

function onWeaponfired() { 
  if (
this.rocketfired == "1") { 
    
this.rx mousex
    
this.ry mousey
    
onTimeout(); 
  } 
  
this.rocketfired 1


Would require you to fire it twice to actually fire it, and even then you could fire it as much as you wanted to mess it up while the rocket is in motion. You want to do something like this:

PHP Code:

function onWeaponfired() { 
  if (
this.rocketfired == 0) { 
    
this.rx mousex
    
this.ry mousey;
    
this.rocketfired 1
    
onTimeout(); 
  }  


I would also suggest doing:

PHP Code:

function onTimeout() {
  
// other code...
  
if (this.rocketfired == 1setTimer(0.05);


So your script only loops when it needs to.

Gunderak 09-18-2011 05:31 AM

Thanks for the feedback, il be sure to test out angles and such.
do you happen to know how to make the rotation of the image aim towards the mouse?

fowlplay4 09-18-2011 05:41 AM

Set the image's rotation to the angle towards the mouse.

Gunderak 09-18-2011 06:45 AM

ahh i feel so stupid now, you told me how to do it and i was too blind to see it.


All times are GMT +2. The time now is 07:31 PM.

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