Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 04:10 PM.


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