Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Script: findplayers and findnpcs (https://forums.graalonline.com/forums/showthread.php?t=65063)

Warcaptain 03-30-2006 06:04 AM

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.

ApothiX 03-30-2006 04:08 PM

Hmm, wouldn't it be better if you just did something like:

PHP Code:

function findplayers(tx,ty,tw,th){
  
treturn=NULL;
  for (
temp.plplayers){
    if (
temp.pl.x in |tx,tx+tw| && temp.pl.y in |ty,ty+th|){
      
treturn.add(temp.pl);
    }
  }
  return 
treturn;


Some people may want to include theirselves in the search.

Also, you can't set other people's nicknames clientside :p

KuJi 03-31-2006 02:11 PM

Quote:

Originally Posted by Warcaptain
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. :)

You should make one class called customfunctions and put all the functions in their. Then you can easily join that one class, and use all the custom functions you have made. Speaking of that, I didn't even know you can make custom functions like that :O

ApothiX 03-31-2006 03:51 PM

Quote:

Originally Posted by KuJi
You should make one class called customfunctions and put all the functions in their. Then you can easily join that one class, and use all the custom functions you have made. Speaking of that, I didn't even know you can make custom functions like that :O

The name of the class is pretty irrelevant..

Warcaptain 03-31-2006 08:49 PM

Yes, it doesn't matter what you name it.

On Mana Realms we try to divide up the custom functions as much as we can so that later on we dont have one huge file with 3000 functions in it.. and we only need to access one :)

Skyld 03-31-2006 09:27 PM

temp. variables might be slightly more effective, since they are cleared at the end of the active function. It will save you doing treturn = NULL; or so.

Warcaptain 03-31-2006 09:29 PM

Quote:

Originally Posted by Skyld
temp. variables might be slightly more effective, since they are cleared at the end of the active function. It will save you doing treturn = NULL; or so.

I thought only this.variables saved after functions?

If not then that will save me lots of typing.. I hate having to prefix everything with this. moreso because I am lazy than anything but also for appearance. so many this. this. this. clutteres things and makes them less readable

I try to make my variables easy to understand what they are and as dynamic as possible so that anyone can pick up the script and figure it out. Er1c on the other hand.. woof.. its like trying to put a jigsaw puzzle together with all the peices upside down.


All times are GMT +2. The time now is 04:54 PM.

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