View Single Post
  #6  
Old 02-21-2011, 11:08 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Your latency is pretty high; you're in Germany and the servers are in Texas.

Here's how I would do it:
PHP Code:
// Weapon -Swords
function onActionServerSide(cmdsxsy) {
  if (
cmd == "slash") {
    
// security check: is the player too far away?
    
if (getDist(player.xplayer.ysxsy) > 4) {
      return; 
// player is too far away from the hit location
    
}
    
    
// security check: when was the last time they hit?
    
if (timevar2 player.lastHit 0.5) {
      return; 
// player last hit less than half a second ago
    
}

    
temp.radius 0.1;
    
temp.npcs player.level.findAreaNPCs(sx radiussy radiusradius 2radius 2);
    
    for (
temp.npc npcs) {
      
// it's good practice to pass the player object rather than
      // the account—it's just the object-oriented thing to do
      
npc.trigger("hitByPlayer"player);
    }
  }
}

function 
getDist(x1y1x2y2) {
  return (((
x1 x2) ^ 2) + ((y2 y1) ^ 2)) ^ 0.5;
}

//#CLIENTSIDE
function slashObjects(sxsy) {
  
temp.radius 0.1;
  
  for (
temp.npc findAreaNPCs(sx radiuxsy radiusradius 2radius 2)) {
    
npc.trigger("hitByPlayer"null); // second parameter is only needed for v5
  
}
  
  
triggerServer("gui"this.name"slash"sxsy);

This way, you don't have to worry about players tampering with a list of NPCs (it's also a pain to make that list since there's no easy way of identifying an NPC on clientside and serverside unless it's a putnpc2 or DB NPC; level NPCs don't have names and the IDs differ from clientside to serverside.)
__________________
Reply With Quote