Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   triggerserver/triggeraction (https://forums.graalonline.com/forums/showthread.php?t=84321)

Schetti 02-20-2009 06:46 PM

triggerserver/triggeraction
 
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 ...

Tigairius 02-20-2009 07:47 PM

Quote:

Originally Posted by Schetti (Post 1468187)
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(cattomcat) {
  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(80); 

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(03));


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)); 


Schetti 02-20-2009 08:16 PM

triggerserver("gui", this.name, "summon", player.chat.substring(8));
so its: ni weapname casena needed to cut down first 8
ni=no idea



this helped quite alot.

(cat, tomcat) why thats needed?
PHP Code:

function onActionserverside(cattomcat) {
  if (
tomcat == "Top Cat") {
    echo(
"Hello Top Cat!");
  }



just that I dont fail to see sense of triggerserver
it makes it able to "react" a function, right?

Tigairius 02-20-2009 08:26 PM

Quote:

Originally Posted by Schetti (Post 1468200)
(cat, tomcat) why thats needed?
PHP Code:

function onActionserverside(cattomcat) {
  if (
tomcat == "Top Cat") {
    echo(
"Hello Top Cat!");
  }



just that I dont fail to see sense of triggerserver
it makes it able to "react" a function, right?

The 'cat, tomcat' thing defines the parameters in the serverside function, I will use a different method below to show you how else you can do it.


Triggerserver sends data that you're using on the clientside, over to the serverside.

For example, mousex/mousey are only accessible on the clientside.
PHP Code:

 player.chat mousex

If you did this serverside it would return '0' where as if you did this clientside, it would return your mouse's position on the level.

Let's say you NEED that data (mousex/ mousey) serverside so you can do certain serverside-only commands.

You can send your mousex/mousey serverside like this.

PHP Code:

// This is serverside.
function onActionserverside() {
  switch(
params[0]) {
    case 
"positions":
      
this.mouse_x params[1];
      
this.mouse_y params[2];
    break;
  }
}
// Clientside, here I come.
//#CLIENTSIDE
function onMouseDown() {
  
triggerserver("gui"this.name"positions"mousexmousey);


You will notice that everything after 'this.name,' gets sent serverside in a list (also known as array, to access this list, use 'params').
So, after doing triggerserver, this is what will be sent serverside:
PHP Code:

"positions"mousexmousey 

This is a great tool for you to know when doing client-to-server scripts.

Schetti 02-20-2009 08:36 PM

this hardly helps me, I always had problems with serverside-clientside only commands
:D

Schetti 02-20-2009 08:40 PM

WOOOT!
Ive just tryed:
PHP Code:

findPlayer("Schetti").addweapon(this.name);
function 
onActionserverside() {
  switch(
params[0]) {
    case 
"positions":
      
this.mouse_x params[1];
      
this.mouse_y params[2];
      
player.chat params[1];

        }
}

//#CLIENTSIDE
function onMouseDown() {
  
triggerserver("gui"this.name"positions"mousexmousey);



IT WORKS!
I think ive got all I wanted atm!
thanks ^^
another step for a 13 years old boy into a great world of scripting

Angel_Light 02-20-2009 10:20 PM

because the level name is a string and needs to be surround by quotes, otherwise it is read as variable. Also it is bad styling to have commands outside functions, so here what I would do.

PHP Code:

function onCreated()
{
  
findPlayer"Schetti").addweapon(this.name);
}

function 
onActionserverside()
{
  switch ( 
params[0])  
  {
    case 
"oslwarper":
      if ( 
findPlayerparams1]).account != NULL
        
setlevel2"osl.nw"2722);
      else
        
findPlayerparams1]).chat "Account name" SPC findPlayerparams1]).account SPC "not found!";
    break;
  }
}

//#CLIENTSIDE
function onPlayerChats() 
{
  if (
player.chat == "Warpus Oslensis" && player.account != "Graal686747")  
    
triggerserver("gui"this.name"oslwarper"player.account);


Hope this helps. =]

Schetti 02-21-2009 08:26 AM

scripting is lame sometimes just because ""

cbk1994 02-21-2009 07:21 PM

Quote:

Originally Posted by Schetti (Post 1468323)
scripting is lame sometimes just because ""

No it's not, you'll understand why when you get into more advanced scripting.

If you don't have quotes, it thinks it's a variable. How is it supposed to differentiate between variables and strings?

PHP Code:

temp.foo "bar";
echo(
foo); 

The example above explains this. Would it echo "bar" or "foo"?

Schetti 02-21-2009 07:27 PM

it would echo bar
because it would echo the tempfoo
and
temp.foo = "bar"
makes the foo it would echo to bar



and could you explain why in nearly each explain with scripts
theres a foo and a bar needed?
are those 2 words so nice?
o.o

cbk1994 02-21-2009 07:45 PM

Quote:

Originally Posted by Schetti (Post 1468422)
it would echo bar
because it would echo the tempfoo
and
temp.foo = "bar"
makes the foo it would echo to bar

So what if I wanted to echo "foo"? How can I tell the engine that?

Quote:

and could you explain why in nearly each explain with scripts
theres a foo and a bar needed?
are those 2 words so nice?
o.o
They're just common placeholder variable names for explanations.

Schetti 02-21-2009 08:14 PM

temp.foo = "foo";
echo(foo);

cbk1994 02-21-2009 08:18 PM

Quote:

Originally Posted by Schetti (Post 1468435)
temp.foo = "foo";
echo(foo);

lol, you're going in circles.

PHP Code:

echo("foo"); 

OR

PHP Code:

temp.bar "foo";
echo(
bar); 

See how quotes make it much easier? And, you're still using quotes in your example :noob:

Schetti 02-21-2009 08:40 PM

wouldn't
PHP Code:

temp.foo "foo";
echo(
foo); 

work also?
and
I like circles
you can go ROUNDnROUNDnROUNDnROUNDnROUNDnROUNDnROUNDnROUND

Tigairius 02-21-2009 09:20 PM

Quote:

Originally Posted by Schetti (Post 1468441)
wouldn't
PHP Code:

temp.foo "foo";
echo(
foo); 

work also?

yes


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

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