View Single Post
  #1  
Old 03-30-2006, 06:04 AM
Warcaptain Warcaptain is offline
Banned
Warcaptain's Avatar
Join Date: Jun 2001
Location: Virginia, USA
Posts: 2,086
Warcaptain is on a distinguished road
Send a message via ICQ to Warcaptain Send a message via AIM to Warcaptain Send a message via Yahoo to Warcaptain
Script: findplayers and findnpcs

I am sure most people already made functions for this.. but some haven't so I have decided to post it for people to use.

This is a function to get all the players within a specified box. There are functions for this serverside, but not clientside so I figured I would add it.
Syntax is simple, findplayers(x,y,w,h)
Function to find an area of players
NPC Code:
function findplayers(tx,ty,tw,th){
treturn=NULL;
for (i=1;i<playerscount;i++){
if (players[i].x in |tx,tx+tw| && players[i].y in |ty,ty+th|){
treturn.add(players[i]);
}
}
return treturn;
}



It is probably best to make a class for them, ie: "findfunctions" that way you can simply put join("findfunctions") in a script and be able to use the find functions without having to copy and paste it over and over.

**Note** the function returns the object of the npcs/players not the index (I think the serverside command returns the index) so to find the nickname of nearby player with nick "Tengo" you would do something like this:

NPC Code:

function onCreated(){
nearplayers = findplayers(player.x-10,player.y-10,20,20)
//searches a 20x20 and sets var 'nearplayers' to the returned value
for (i=0;i<nearplayers.size();i++)
if (nearplayers[i].nick=="Tengo") break;
// finds the player with the nickname 'Tengo'
nearplayers[i].nick="Layo";
//sets that players nick to 'Layo'
}



What do you think? Please do not flame this post because I am just trying to help PW's and scripters that are starting out.

Last edited by Warcaptain; 03-30-2006 at 06:14 AM.. Reason: removed findnpcs because forgot about findareanpcs()
Reply With Quote