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-17-2011, 12:27 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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);
  }

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 09-17-2011, 05:43 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #3  
Old 09-18-2011, 05:31 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 09-18-2011, 05:41 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Set the image's rotation to the angle towards the mouse.
__________________
Quote:
Reply With Quote
  #5  
Old 09-18-2011, 06:45 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
ahh i feel so stupid now, you told me how to do it and i was too blind to see it.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
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 02:29 PM.


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