Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-11-2010, 09:17 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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).

Last edited by DustyPorViva; 02-11-2010 at 09:35 PM..
Reply With Quote
  #2  
Old 02-11-2010, 09:45 PM
Soala Soala is offline
Ideas on Fire
Soala's Avatar
Join Date: Jun 2007
Location: In my head
Posts: 3,208
Soala is a jewel in the roughSoala is a jewel in the rough
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
Reply With Quote
  #3  
Old 02-11-2010, 10:39 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
That's right Soala, and a * as a prefix will make it show up, but you won't be able to delete in.
__________________
Reply With Quote
  #4  
Old 02-11-2010, 11:02 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by Crow View Post
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.
Reply With Quote
  #5  
Old 02-12-2010, 02:00 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
+Rep
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 02-12-2010, 02:05 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Immolate View Post
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
Reply With Quote
  #7  
Old 02-12-2010, 02:07 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by DustyPorViva View Post
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.
Reply With Quote
  #8  
Old 02-12-2010, 02:09 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by WhiteDragon View Post
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.
Reply With Quote
  #9  
Old 02-12-2010, 02:14 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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!"

__________________
Quote:
Reply With Quote
  #10  
Old 02-12-2010, 04:01 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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..

__________________
Reply With Quote
  #11  
Old 02-12-2010, 05:41 PM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
It was playersprite, not player.sprite :0
Reply With Quote
  #12  
Old 02-12-2010, 05:47 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by 12171217 View Post
It was playersprite, not player.sprite :0
Well it's player.sprite now :P
Reply With Quote
  #13  
Old 02-14-2010, 10:21 AM
calani calani is offline
Scriptess
calani's Avatar
Join Date: Aug 2003
Location: asmgarden.gmap
Posts: 606
calani is on a distinguished road
Send a message via AIM to calani
Quote:
Originally Posted by Crow
stuff
Handy.
I see uses.
__________________
Reply With Quote
  #14  
Old 05-30-2010, 03:21 AM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
bump for requesting stickythready.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #15  
Old 05-30-2010, 03:30 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally Posted by Deas_Voice View Post
bump for requesting stickythready.
I second.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
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 10:28 AM.


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