View Single Post
  #1  
Old 03-17-2010, 07:46 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Hit Players and NPC's with ease.

Specify Width*Height to create a set of co-ordinates for a Hitbox in front of the player. Additionally specify x and y offsets if directly in front of the player isn't what your going for.

Usage.
PHP Code:
temp.box = {2,3,1,0};
temp.hitbox getHitBox(player.dir,player.x,player.y,temp.box); 
PHP Code:
function onActionServerside(){
  if (
params[0] == "hitthings"){
    
temp.box = {2,3,1,0}; // The weapon's Box, Plus any needed offsets. Ignore if not needed.
    
temp.hbox getHitBox(player.dir,player.x,player.y,temp.box);
    
temp.list = findAreaPlayers(temp.hbox[0],temp.hbox[1],temp.hbox[2],temp.hbox[3],player.account);
    
//triggerClient("gui",this.name,"showbox",temp.hbox);//so we can see the box
    
for (temp.objtemp.list){
      
temp.obj.ani "hurt";
      
// call your public Hit the players functiosn here, based on whatever other params you send.
    
}
    
temp.list = findAreaNpcs(temp.hbox[0],temp.hbox[1],temp.hbox[2],temp.hbox[3]);
    for (
temp.objtemp.list){
      
temp.obj.ani "hurt";
      
//call your public Hit the npc functions here. based on whatever other params you send.
    
}
  }
}

// A find area players function! Account should be your own to avoid hitting yourself by mistake.
// Checks at the base of the player, not the top left, where the x,y usually is considered
function findAreaPlayers(x,y,w,h,account){
  for (
temp.pl findNearestPlayers(x+w/2,y+h/2)){
    if (
temp.pl.account != account){
      if (
temp.pl.x+1.5 in |x,x+w| && temp.pl.2 in |y,y+h|){
        
temp.list.add(temp.pl);
      }
    }
  }
  return 
temp.list;
}

//Direction, X, Y, BOX = {width,height,offsetx,offsety};
//Returns co-ordinates for rectnagular hit checking in front of X,Y offset by an X,Y of shape W,H oriented by Dir
function getHitBox(d,x,y,box){
  
temp.wi = (d in {1,3}) ? box[1]:box[0];// swap width/height if direction is different.
  
temp.hi = (d in {1,3}) ? box[0]:box[1];
  
temp.ox = {box[2],box[3],-box[2],-box[3]};//created custom arrays for the offsets 
  
temp.oy = {box[3],-box[2],-box[3],box[2]};// because it was getting confusing otherwise. 
  
temp.+= 1.5 wi/vecx(d)*(wi/2) - ox[d]; // the magic happening here also.
  
temp.+= hi/2  vecy(d)*(hi/2) - oy[d];
  return {
x,y,wi,hi};
}

//#CLIENTSIDE

function onWeaponFired(){
  
triggerServer("gui",this.name,"hitthings");
}

//Just so we can see where the box is exactly on screen, for testing.
function onActionClientside(){
  if (
params[0] == "showbox"){
    
temp.params[1];
    
showpoly(0,{b[0],b[1],b[0],b[1]+b[3],b[0]+b[2],b[1]+b[3],b[0]+b[2],b[1]});
  }
  
settimer(2);
}
function 
onTimeout()hideimg(0); 
Attached Images
 
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly

Last edited by adam; 03-17-2010 at 09:12 AM..
Reply With Quote