Quote:
Originally Posted by Schetti
triggerserver("gui", this.name, "summon", player.chat.substring(8));
I often read lines like this and got near no clue how to use them.
someone can help me?
and also:
player.chat.substring(8)
is it is it 8 because of
/summon Schetti
12345 67 8?
ya I know I am noob ...
|
triggerserver("gui", weapon name, parameters);
I'll explain.
this.name = the current weapon name, for example, Staff/Summon
you could manually write it in if you wanted to:
PHP Code:
triggerserver("gui", "Staff/Summon", "summon");
but it's generally easier and better to just use this.name or 'name'.
Parameters are what needs to be sent to the server. Triggerserver/triggeraction are used to send information to the same server. There is no difference between the two when working with weapons, but triggeraction has more features if you're triggering level npcs, etc, but I won't get into that here.
For example,
PHP Code:
// This is my clientside part of the script.
//#CLIENTSIDE
function onCreated() {
this.tomcat = "Top Cat";
triggerserver("gui", this.name, "cat", this.tomcat);
}
PHP Code:
// This is my serverside script.
function onActionserverside(cat, tomcat) {
if (tomcat == "Top Cat") {
echo("Hello Top Cat!");
}
}
The most popular way for serverside string separation is switch statements, but you can learn about that later if you've never done any sort of scripting outside of Graal.
Substring is used in almost all scripting/coding languages in this format. Certain languages allow you to do negative substrings which makes it easier to chop off the ending of the string, however, this is how Graal's works:
PHP Code:
player.chat.substring(8);
Is the same thing as
PHP Code:
player.chat.substring(8, 0);
That is simply chopping off the first 8 characters of player.chat. That's simple enough, now let's play with the second number.
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
echo(player.chat.substring(0, 3));
}
This will echo the first three characters of player.chat into your F2 menu.
So, let's use both of them, just to make sure you got it down. Let's say I want to see the middle characters of player.chat. This means if I said:
'abcde' it would show 'c'
PHP Code:
//#CLIENTSIDE
function onCreated() {
echo(player.chat.substring(int(player.chat.length() / 2), player.chat.length() - int(player.chat.length() / 2) * 2));