Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   array search (https://forums.graalonline.com/forums/showthread.php?t=63011)

jake13jake 12-27-2005 02:15 AM

array search
 
Stefan, you should add this, it can be used like findplayer(account), but with a lot more flexibility.

NPC Code:

//Script made by jake13jake
//on Friday, December 9th,
//also the day of his sister's 21st birthday,
//at 2:45 in the morning!

function find(arr,attr,val) {
for (i=0; i<arr.size(); i++) {
if (arr[i].(@attr) == val)
return arr[i];
}
return -1;
}


Skyld 12-27-2005 03:21 PM

You could just create a function class and join the class to NPCs you wish to use it in.

Also, it might be a bit nicer to use the built-in for () iterator.
PHP Code:

function find(arrattrval)
{
  for (
keyarr)
  {
    if (
key.(@attr) == val)
    {
      return 
key;
    }
  }
  return -
1;



jake13jake 12-27-2005 03:24 PM

Quote:

Originally Posted by Skyld
You could just create a function class and join the class to NPCs you wish to use it in.

Also, it might be a bit nicer to use the built-in for () iterator.
PHP Code:

function find(arrattrval)
{
  for (
keyarr)
  {
    if (
key.(@attr) == val)
    {
      return 
key;
    }
  }
  return -
1;



oh cooool... I didn't know gscript2 ripped that out of java :D. I still think it would be useful as a built in function though. I'd honestly rather have it as a public function, but you can't do clientside public functions.

Admins 12-27-2005 03:55 PM

Quote:

Originally Posted by jake13jake
oh cooool... I didn't know gscript2 ripped that out of java :D. I still think it would be useful as a built in function though. I'd honestly rather have it as a public function, but you can't do clientside public functions.

You can, in weapon scripts

jake13jake 12-27-2005 04:08 PM

Quote:

Originally Posted by Stefan
You can, in weapon scripts

REALLY, I'll tell master storm then :D. Wait a second though, do you think you could elaborate a little bit?

<3 Stefan

Yen 12-27-2005 09:31 PM

PHP Code:

Weapon1
function onWeaponFired() {
  
player.chat Weapon2.Omg(player.account);


PHP Code:

Weapon2
public function Omg(acc) {
  return 
"Zomg your account is" SPC acc;



Help?

jake13jake 12-27-2005 10:08 PM

Quote:

Originally Posted by Yen
PHP Code:

Weapon1
function onWeaponFired() {
  
player.chat Weapon2.Omg(player.account);


PHP Code:

Weapon2
public function Omg(acc) {
  return 
"Zomg your account is" SPC acc;



Help?

Well, one of the reasons I'd want this command integrated is that it helps you find Weapon2.

ApothiX 12-27-2005 10:22 PM

Quote:

Originally Posted by jake13jake
Well, one of the reasons I'd want this command integrated is that it helps you find Weapon2.

Never heard of System NPCs? :(

We don't need a scripting language that is bloated with functions we will never use in our life-time.

Skyld 12-27-2005 11:15 PM

Quote:

Originally Posted by Yen
PHP Code:

Weapon1
function onWeaponFired() {
  
player.chat Weapon2.Omg(player.account);


PHP Code:

Weapon2
public function Omg(acc) {
  return 
"Zomg your account is" SPC acc;



Help?

PHP Code:

findWeapon("Weapon2").Omg("variable"); 

... is what I'm thinking.

Yen 12-28-2005 12:58 AM

Yeah, you need to use findweapon() if it has a space, -, *, +, ect.

jake13jake 12-28-2005 04:16 AM

Is that why findweapon never worked for me?

Lance 12-28-2005 05:29 AM

Quote:

Originally Posted by Yen
Yeah, you need to use findweapon() if it has a space, -, *, +, ect.

Or if you'd like to remove any ambiguity.

Admins 12-29-2005 01:27 AM

You can also do ("Complex-Name").omg(stuff). findweapon() and findnpc() have the advantage though that they are not case-sensitive.
The possibility to call code of other Weapon/GUI scripts is good for separating functionality into smaller scripts, instead of having one huge system-script.

jake13jake 12-29-2005 02:22 AM

Quote:

Originally Posted by Stefan
You can also do ("Complex-Name").omg(stuff). findweapon() and findnpc() have the advantage though that they are not case-sensitive.
The possibility to call code of other Weapon/GUI scripts is good for separating functionality into smaller scripts, instead of having one huge system-script.

Yea, it was in my movement script that I'm hoping master storm will help me on. It separates into a lot of weapons. Complete list now is: -system_moving, -system_sidemoving, -system_action, -system_gani, -system_keys, -system_extra.

Moving handles the default dir/dx/dy handling (pretty simple).
Sidemoving handles the sliding off of corners (not as simple).
Action handles grab/push/pull/jump all on the same counter.
Gani handles the default moving ganis.
Keys handles sword and extra commands like whistle and hug
Extra does the extra simple stuff, like bed movement, handling all movement related scripts, etc. The main goal is to have them work mostly independently of eachother. But, seeing that that could lead to a bit of redundant code, it would be better in some cases to have the systems interact with eachother. The action system and the gani system still need a little bit of work before this new movement is released for Classic, as well as a new carry system created. I also would like to document and post this movement on graal.net. I'm just hoping that Master Storm will actually help out a little bit. I've done it all on my own so far.

Inverness 12-29-2005 04:10 AM

I also like to set global variables in weapon scripts for calling functions. So I don't have to use makevar everytime I call something from another script.
PHP Code:

First Weapon:
function 
onCreated() {
  
mud makevar("-SystemMudlib");
}
public function 
additem(itemidqty) {
  
junkhere;


PHP Code:

Second Weapon:
public function 
playerIni() {
  
mud.additem("skill_battleaura1",1);




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

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