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-20-2009, 06:46 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
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 ...
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #2  
Old 02-20-2009, 07:47 PM
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
Quote:
Originally Posted by Schetti View Post
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)); 
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 02-20-2009, 08:16 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
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?
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #4  
Old 02-20-2009, 08:26 PM
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
Quote:
Originally Posted by Schetti View Post
(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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
Old 02-20-2009, 08:36 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
this hardly helps me, I always had problems with serverside-clientside only commands
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #6  
Old 02-20-2009, 08:40 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
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
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #7  
Old 02-20-2009, 10:20 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
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. =]
__________________
Deep into the Darkness peering...
Reply With Quote
  #8  
Old 02-21-2009, 08:26 AM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
scripting is lame sometimes just because ""
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #9  
Old 02-21-2009, 07:21 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Schetti View Post
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"?
__________________
Reply With Quote
  #10  
Old 02-21-2009, 07:27 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
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
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #11  
Old 02-21-2009, 07:45 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Schetti View Post
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.
__________________
Reply With Quote
  #12  
Old 02-21-2009, 08:14 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
temp.foo = "foo";
echo(foo);
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #13  
Old 02-21-2009, 08:18 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Schetti View Post
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
__________________
Reply With Quote
  #14  
Old 02-21-2009, 08:40 PM
Schetti Schetti is offline
SC2 Player
Schetti's Avatar
Join Date: Nov 2008
Location: Austria
Posts: 269
Schetti is on a distinguished road
wouldn't
PHP Code:
temp.foo "foo";
echo(
foo); 
work also?
and
I like circles
you can go ROUNDnROUNDnROUNDnROUNDnROUNDnROUNDnROUNDnROUND
__________________
“Peace cannot be kept by force. It can only be achieved by understanding.” – Albert Einstein
Reply With Quote
  #15  
Old 02-21-2009, 09:20 PM
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
Quote:
Originally Posted by Schetti View Post
wouldn't
PHP Code:
temp.foo "foo";
echo(
foo); 
work also?
yes
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
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 01:29 PM.


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