Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Shoot arrows where you click. (https://forums.graalonline.com/forums/showthread.php?t=134258849)

DrakilorP2P 04-21-2010 02:09 AM

Shoot arrows where you click.
 
http://i42.tinypic.com/2hcgizm.png

http://i41.tinypic.com/sphs8g.png
Works on terrain too.

http://i43.tinypic.com/351fyq0.png
You can shoot at flying people by clicking their shadows.

Don't see any arrows? Go to Graal Kingdoms to make it download.
Or you can use your own projectile gani if you change the script.

Install as a weapon and add to yourself.
PHP Code:

//#CLIENTSIDE

function onMouseDown()
{
  if (
leftmousebutton)
  {
    
temp.targetPlayer players[testplayer(mousexmousey)];
    
temp.targetNPC npcs[testnpc(mousexmousey)];
    if (
temp.targetNPC != null)
    {
      
temp.target = {temp.targetNPC.1.5temp.targetNPC.2.0temp.targetNPC.1};
    }
    elseif (
temp.targetPlayer.account != null && temp.targetPlayer.account != player.account)
    {
      
temp.target = {temp.targetPlayer.1.5temp.targetPlayer.2.0temp.targetPlayer.1};
    }
    else
    {
      
temp.target = {mousexmouseygetz(mousexmousey)};
    }
    
    
shootAt(player.xplayer.yplayer.ztemp.target[0], temp.target[1], temp.target[2], "arrow""barrow0.png");
  }
}

function 
shootAt(temp.oxtemp.oytemp.oztemp.txtemp.tytemp.tztemp.ganitemp.ganiparam)
{
  
temp.timeStep 0.05;
  
  
temp.origin = {temp.oxtemp.oytemp.oz};
  
temp.target = {temp.txtemp.tytemp.tz};
  
  
temp.dx = (temp.target[0] - 1.5) - temp.origin[0];
  
temp.dy = (temp.target[1] - 2.0) - temp.origin[1];
  
temp.dz temp.target[2] - temp.origin[2];
  
temp.horizontalDistance = (temp.dx^temp.dy^2) ^ 0.5//Pythagoras' theorem
  
temp.verticalDistance temp.dz;
  
temp.angle getangle(temp.dxtemp.dy);
  
  
//Look for 'ballistic trajectories' to find the equations used here.
  //Two lines of magic incantations to prevent an accuracy error. (Possibly caused by the projectile only being updated every 0.05 seconds)
  
temp.precognition_horizontalVelocity 20;
  
temp.timeToTarget shared.roundTo(temp.horizontalDistance temp.precognition_horizontalVelocitytemp.timeStep); //Constant horizontal velocity.
  //Alternatively: temp.timeToTarget = 1; //Constant time to reach target.
  
temp.horizontalVelocity = (temp.horizontalDistance temp.timeToTarget);
  
temp.verticalVelocity 0.5 * (gravity temp.timeStep) * temp.timeToTarget + (temp.verticalDistance temp.timeToTarget);
  
  
//Trigonometry
  
if (temp.horizontalVelocity != 0) {
    
temp.zangle arctan(temp.verticalVelocity temp.horizontalVelocity);
  }
  else {
    
//Happens when the origin and the target position are the same.
    
temp.zangle pi 2;
  }
  
  
temp.power temp.verticalVelocity sin(temp.zangle) * temp.timeStep;
  
  
shoot(temp.origin[0], temp.origin[1], temp.origin[2],
        
temp.angletemp.zangletemp.power,
        
temp.ganitemp.ganiparam);



salesman 04-21-2010 02:40 AM

Wow, pretty awesome that you posted this because I was just thinking about doing the exact same thing (but with something other than arrows) earlier today. Haven't tried it out yet, but nice work.

adam 04-21-2010 02:40 AM

That is awesome, good job man. I was also trying to do that one day, but my trial and error method, instead of cold hard math wasn't working out, I just made it go in a straight line to where you click which isn't that cool.

Grey 04-21-2010 02:44 AM

Tidy. Bravo.

Seeya 04-21-2010 07:30 AM

idk but i'm 99% sure that they have this on graal kingdoms

i think they call it a bow

DustyPorViva 04-21-2010 07:34 AM

Shoot arrows with your ****

Whaaaaaaaaaaaaaaat?

Cool stuff, like I said in IRC I was never able to calculate the numbers needed to do such a thing.

adam 04-21-2010 07:42 AM

If I remember right, on graal kingdoms the bow didn't shoot where you clicked. But that was a long time ago for me?

Seeya 04-21-2010 07:44 AM

setnick Kale (FAQ)
bows shoot where you click

DustyPorViva 04-21-2010 07:45 AM

Quote:

Originally Posted by adam (Post 1571007)
If I remember right, on graal kingdoms the bow didn't shoot where you clicked. But that was a long time ago for me?

It works off the formula, I'm pretty sure. Bows will show an circle around your mouse. The farther your mouse(thus, your target), the larger the circle would grow. This circle indicates the radius of where your arrow could land(accuracy).

Thus, they have to use a similar formula to start with, and then add/deduct from it to account for the accuracy.

Seeya 04-21-2010 07:53 AM

Quote:

Originally Posted by DustyPorViva (Post 1571009)
It works off the formula, I'm pretty sure. Bows will show an circle around your mouse. The farther your mouse(thus, your target), the larger the circle would grow. This circle indicates the radius of where your arrow could land(accuracy).

Thus, they have to use a similar formula to start with, and then add/deduct from it to account for the accuracy.

qft

Draenin 04-25-2010 09:10 AM

Excellent stuff, good sir. Yet another script you've made which will prove tremendously helpful to every developer in the future. :]

coreys 05-02-2010 01:52 AM

Well apparently it's not as simple as going on GK and downloading it since no one there is any help.

Can someone attach the gani and image here?

DrakilorP2P 05-02-2010 11:02 PM

2 Attachment(s)
Quote:

Originally Posted by coreys (Post 1573346)
Well apparently it's not as simple as going on GK and downloading it since no one there is any help.

Can someone attach the gani and image here?

Attached.

Pelikano 05-02-2010 11:09 PM

awesome dude


All times are GMT +2. The time now is 02:58 AM.

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