Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-21-2010, 02:09 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Shoot arrows where you click.




Works on terrain too.


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(mousex, mousey)];
    
temp.targetNPC = npcs[testnpc(mousex, mousey)];
    if (
temp.targetNPC != null)
    {
      
temp.target = {temp.targetNPC.x + 1.5, temp.targetNPC.y + 2.0, temp.targetNPC.z + 1};
    }
    elseif (
temp.targetPlayer.account != null && temp.targetPlayer.account != player.account)
    {
      
temp.target = {temp.targetPlayer.x + 1.5, temp.targetPlayer.y + 2.0, temp.targetPlayer.z + 1};
    }
    else
    {
      
temp.target = {mousex, mousey, getz(mousex, mousey)};
    }
    
    
shootAt(player.x, player.y, player.z, temp.target[0], temp.target[1], temp.target[2], "arrow", "barrow0.png");
  }
}

function 
shootAt(temp.ox, temp.oy, temp.oz, temp.tx, temp.ty, temp.tz, temp.gani, temp.ganiparam)
{
  
temp.timeStep = 0.05;
  
  
temp.origin = {temp.ox, temp.oy, temp.oz};
  
temp.target = {temp.tx, temp.ty, temp.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^2 + temp.dy^2) ^ 0.5; //Pythagoras' theorem
  
temp.verticalDistance = temp.dz;
  
temp.angle = getangle(temp.dx, temp.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_horizontalVelocity, temp.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.angle, temp.zangle, temp.power,
        
temp.gani, temp.ganiparam);
} 
Reply With Quote
 


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 01:58 PM.


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