![]() |
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). |
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 |
That's right Soala, and a * as a prefix will make it show up, but you won't be able to delete in.
|
Quote:
|
+Rep
|
Quote:
- : 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 :) |
Quote:
|
Quote:
|
Dynamic function calling.
I.e: PHP Code:
|
Another handy thing is assigning WNPCs to vars. Let's say you got the following in -System/Inventory:
PHP Code:
PHP Code:
|
It was playersprite, not player.sprite :0
|
Quote:
|
Quote:
I see uses. |
bump for requesting stickythready.
|
Quote:
|
Tips for creating resizable GUI controls
The variables "vertSizing" and "horizSizing" let you easily make GUI controls that resize when the parent control resizes. vertSizing is usually either "height" or "top". A value of "height" will change the height of the control as the height of the parent control changes. A value of "top" will move the control down as the parent control's height changes. horizSizing is usually either "width" or "height". A value of "width" will change the width of the control as the width of the parent control changes. A value of "left" will move the control to the right as the width of the parent control changes. These can be combined to do most kinds of resizing schemes. PHP Code:
http://img85.imageshack.us/img85/6418/guiexamples.png There are also other values for vertSizing and horizSizing, but I have never needed to use them. Their names should be self-explanatory. Quote:
Creating custom objects types While it's not really possible to create custom object types, you can use a few tricks to replicate the functionality. For example, let's say you're making a mail system for players to send mail back and forth, but also for scripts to send mail to players. You could do this by joining a class to every script that needs to send mail or by using a public function, but there's an even cleaner way. First, you will need a database NPC to make the object. PHP Code:
PHP Code:
PHP Code:
|
Nice job. :)
|
Those gui sizings are pretty awesome :)
|
Nice work man. I am very pleased!
|
Haha, on my mail system I've done exactly the same as you, weird :p
Good job, learned about the re-sizing :) (would rep but can't) |
nice, didn't know about the re-sizing stuff.
why haven't this thread been stickied yet? )= |
bump, still not stickied! :\
|
Quote:
|
Quote:
|
WHY haven't this awesome thread been stickied yet?!
|
Quote:
I still think someone needs to compile all the documentation on the forums and populate the Wiki(s) with it. First step: Compile list of helpful posts. (Any reply in the NPC-Scripting forum with [PHP] or [HTML] tags by someone who knows what they're doing usually) |
After Tig said about the new playerlist having pm windows open in the middle of the screen, I asked him how he did this. Apparently Stefan had said how to at some point?
But it went unnoticed (to me at least). I think some people will find it helpful. PHP Code:
(However, it seems when the window is initially created, it ignores the external.x/y position...and you need to set those after the window is visisble) Found the post! http://forums.graalonline.com/forums...&postcount=746 |
Quote:
Just thought I'd elaborate on your example there: PHP Code:
|
Quote:
|
I've moved the list of helpful posts to the wiki, added some new links, and categorized them. It'd be nice if new useful posts were added to this list in the future.
If anybody would like to add, please just edit the page. If you don't have wiki access, I'll be happy to make the edits for you (post here or PM me). |
I found this helpfull, also thanks cbk1994 I need to study the wiki some more.
|
On the clientside, using the setshape2 value of 5 lets you define NPCs with a shape that can be interacted with but doesn't block the player.
PHP Code:
|
Quote:
|
Quote:
|
Quote:
|
Here's a little tip for understanding the options part of move(), showstats(), enablefeatures() etc and how it works:
If these functions are known to you, you might have noticed the build up of the options going like this 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 ETC ETC Basically you can create any numbers using the numbers given above 31 = 1 + 2 + 4 + 8 + 16 30 = 2 + 4 + 8 + 16 29 = 1 + 4 + 8 + 16 Following? Now, why are those functions using numbers like that? Why not use normal numbers from 1 to 10 for example? To answer that, let me set an example up: PHP Code:
Now, how can it be done instead? Well, yeah, you use the numbers given further up this post and do like this: PHP Code:
so instead of doing something like createNPC(x, y, type, true, true, false);, or set up predefined options, use this method instead! :) |
| All times are GMT +2. The time now is 07:31 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.