Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 03-30-2006, 04:08 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #3  
Old 03-31-2006, 02:11 PM
KuJi KuJi is offline
Banned
Join Date: Apr 2004
Location: Staten Island, New York
Posts: 2,202
KuJi will become famous soon enough
Send a message via ICQ to KuJi Send a message via AIM to KuJi Send a message via MSN to KuJi Send a message via Yahoo to KuJi
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
Reply With Quote
  #4  
Old 03-31-2006, 03:51 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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..
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #5  
Old 03-31-2006, 08:49 PM
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
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
Reply With Quote
  #6  
Old 03-31-2006, 09:27 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to 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.
__________________
Skyld
Reply With Quote
  #7  
Old 03-31-2006, 09:29 PM
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
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.
Reply With Quote
Reply


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:03 PM.


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