Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Tips and tricks! (https://forums.graalonline.com/forums/showthread.php?t=134257978)

DustyPorViva 02-11-2010 09:17 PM

Tips and tricks!
 
Post various things not exactly documented. I know there is a page on the wiki about it, but all it does is link to various forum threads.


Comparing arrays! You can easily compare two arrays without having to run a loop, provided the two arrays are exactly the same, in the same order. This is good... for example, comparing tiles. Props go to Skyld for teaching me this one, I believe.

if (@this.arrayOne == @this.arrayTwo) // YAY!
or
if (@this.arrayOne == @{0,0,1,1}) // YAY!


This works by converting the arrays into strings, in which Graal simply compares them, much like "foo" == "foo".


Another one that's been floating around is the ability to setAni to specific frames. This is useful sometimes when you need a specific frame of a gani(like a single sword frame), or perhaps scripting your own looping system where you can control the speed of a gani by script. You can use this to duplicate the old player.sprite system.

setAni("sword[3]",null); // MAKE SURE THE VALUE IS PART OF THE STRING!
setAni("walk[" @ foo @ "]",null);
setAni("def[" @ spritenum @ "]",null); // WILL MIMIC player.sprite FROM GS1



Forming dynamic variable names! Probably something anyone who's been scripting for a while knows how to do, but I think is useful for those who are newer to the GS2 scene. You can use variable values to create new variable names.

temp.foo = 1;
temp.var = 2;
client.("data_" @ foo) = "test";
("client.data_" @ var) = "hmm";


What makes this even more powerful is the ability to capture all variables that begin with a certain string:

temp.prefix = "client.data_";
for (temp.i : getstringkeys(prefix) {
..// WILL ECHO THE NAME OF THE VAR AND ITS VALUE
..echo((prefix @ i) @ " : " @ makevar(prefix @ i));
}


For more information on this, the original post may help: http://forums.graalonline.com/forums...70&postcount=6


You can also pass parameters along with attributes. The process is fairly easy:

player.attr[5] = "scriptgani.gani,foo";
player.attr[5] = "scriptgani.gani,foo,hmm";
player.attr[5] = "scriptgani.gani," @ temp.var;
player.attr[5] = "scriptgani.gani," @ temp.var @ "," @ temp.foo;


The original post from Stefan is here: http://forums.graalonline.com/forums...61&postcount=3
Be aware though, that parameters do not update until the attribute is cleared and then reset. This makes it somewhat useless for attributes that are constant(like an HP bar).


This is all I have for now, though it was never even intended to be this long. I'd love to see more posts written that share some more unknown information so we can get it organized and hopefully easy-to-read. Maybe eventually it can be converted into a wiki page in itself(I can't edit the wiki though).

Soala 02-11-2010 09:45 PM

You can make a weapon invisible in your classic inventory (if you don't want to change it) by putting a - before its name, like:

-Playerstuffs

Do I recall correctly ? Been ages I didn't use this duh

Crow 02-11-2010 10:39 PM

That's right Soala, and a * as a prefix will make it show up, but you won't be able to delete in.

Immolate 02-11-2010 11:02 PM

Quote:

Originally Posted by Crow (Post 1555689)
That's right Soala, and a * as a prefix will make it show up, but you won't be able to delete in.

Also bare in mind, although the above techniques are very useful if you keep the default weapon system and inventory GUI, they'll be redundant if you use a customised item and inventory system. Probably better to use your own preferred markers for items that you can't see or delete.

Tigairius 02-12-2010 02:00 AM

+Rep

DustyPorViva 02-12-2010 02:05 AM

Quote:

Originally Posted by Immolate (Post 1555695)
Also bare in mind, although the above techniques are very useful if you keep the default weapon system and inventory GUI, they'll be redundant if you use a customised item and inventory system. Probably better to use your own preferred markers for items that you can't see or delete.

Default Inventory Prefixes:
- : hides the inventory
* : can't be deleted by player
category/itemname : Organizes the weapons in category names.

However, these aren't exactly script functions, so much as client features :)

WhiteDragon 02-12-2010 02:07 AM

Quote:

Originally Posted by DustyPorViva (Post 1555673)
Comparing arrays! You can easily compare two arrays without having to run a loop, provided the two arrays are exactly the same, in the same order.

Although this may be more concise, it also hides what ends up happening. The engine will have to do a loop in order to concatenate the array together, therefore it is still technically a O(n) operation.

DustyPorViva 02-12-2010 02:09 AM

Quote:

Originally Posted by WhiteDragon (Post 1555735)
Although this may be more concise, it also hides what ends up happening. The engine will have to do a loop in order to concatenate the array together, therefore it is still technically a O(n) operation.

Better done by the engine than by script.

fowlplay4 02-12-2010 02:14 AM

Dynamic function calling.

I.e:
PHP Code:

function onCreated() {
  
temp.func "dispWorld";
  
temp.parm "Hello";
  (@
temp.func)(temp.parm);
}

function 
dispWorld(greeting) {
  echo(
format("%s World!"greeting)); // Echos "Hello World!"



Crow 02-12-2010 04:01 PM

Another handy thing is assigning WNPCs to vars. Let's say you got the following in -System/Inventory:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
inventory this;
  
// more stuff..
}

public function 
Toggle() {
  
// toggle


Then you could do something like this in -System/InputHandler:
PHP Code:

//#CLIENTSIDE
function HandleKey(key) {  // careful, I made this one up, assuming it was implemented in the WNPC earlier
  
if (key == "q")
    
inventory.Toggle();
  
// probably more stuff..



12171217 02-12-2010 05:41 PM

It was playersprite, not player.sprite :0

DustyPorViva 02-12-2010 05:47 PM

Quote:

Originally Posted by 12171217 (Post 1555807)
It was playersprite, not player.sprite :0

Well it's player.sprite now :P

calani 02-14-2010 10:21 AM

Quote:

Originally Posted by Crow
stuff

Handy.
I see uses.

Deas_Voice 05-30-2010 03:21 AM

bump for requesting stickythready.

adam 05-30-2010 03:30 AM

Quote:

Originally Posted by Deas_Voice (Post 1579334)
bump for requesting stickythready.

I second.


All times are GMT +2. The time now is 08:53 AM.

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