View Single Post
  #5  
Old 04-06-2011, 05:44 AM
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
Quote:
Originally Posted by MrOmega View Post
PHP Code:
for ( temp.p = 0; temp.p < allPlayerscount; temp.p ++;)
{

//Use if to check player coords with players[ temp.p]

} 
If you're using allplayerscount, then you need to use allplayers, not players.

You should also use allplayers.size() rather than allplayerscount as it makes no sense to use the latter.

I would recommend using a foreach loop.

PHP Code:
function hitPlayers(x, y, radius) {
  for (
temp.pl : findNearestPlayers(x, y)) {
    if (
getDistance(pl.x, pl.y, x, y) < radius && pl != player) {
      
pl.chat = "I was hit!";
    }
  }
}

function 
getDistance(x1, y1, x2, y2) {
  return (((
x1 - x2) ^ 0.5) + ((y1 - y2) ^ 0.5)) ^ 2;
} 
This should work, haven't tested it though.
__________________

Last edited by cbk1994; 04-06-2011 at 09:05 PM..
Reply With Quote