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(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);

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 06:44 AM.


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