Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-20-2013, 09:02 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Scripting questions

Hi, I recently started scripting GS2 and I have a few questions.
1. What are classes for, like difference between weapons?
2. What is the point of npc's option when you can add npc's in level editor? Is it the same?
3. For setting things for a player, for example the hat or head would the script be something like player.attr1 = "filename"?
4. Are there any "and" or "or" words that can be used in an if statement? For example, a script like
function onPlayerchats() {
if (player.chat = "hello") *could you put an "and" or an "or" comparison here?* {
player.chat = "hi"
}
Reply With Quote
  #2  
Old 11-20-2013, 09:24 PM
cyan3 cyan3 is offline
Registered User
cyan3's Avatar
Join Date: Nov 2005
Location: England
Posts: 2,919
cyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant future
Quote:
Originally Posted by iDigzy View Post
Hi, I recently started scripting GS2 and I have a few questions.
1. What are classes for, like difference between weapons?
2. What is the point of npc's option when you can add npc's in level editor? Is it the same?
3. For setting things for a player, for example the hat or head would the script be something like player.attr1 = "filename"?
4. Are there any "and" or "or" words that can be used in an if statement? For example, a script like
function onPlayerchats() {
if (player.chat = "hello") *could you put an "and" or an "or" comparison here?* {
player.chat = "hi"
}
Classes are used to minimize code reuse and helps improve debugging/maintenance of your code as you'd only have to edit the single class to apply the changes to every script that uses that class. For example, you could have a class that handles damage which could then be called from any weapon script when you need to cause damage to a player instead of rewriting that same code in every weapon script.

It would be player.attr[1] = "filename";

and is && and or is ||

For example:

PHP Code:
function onPlayerChats() {

    if (
player.chat == "hello" || player.chat == "bye") {

        
player.chat "hi";
    }

Also if you are checking a value is equal to something please use the == operator instead of =, Although both work in GS2 it is good practice to use == for equality and = for assignment.

Last edited by cyan3; 11-20-2013 at 09:45 PM..
Reply With Quote
  #3  
Old 11-20-2013, 09:54 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
1. Like cyan said, with classes you don't need to copy and paste the same function all the time for every script, meaning if you got a bug and you fix it inside a class, that will do the change to every script being joined to that class -> you don't need to find all the weapons/npcs and update them manually.

2. DB NPCs are used to store information. Lets say you got something like:
PHP Code:
function onPlayerTouchsMe() {
  if (!(
player.account in this.playersThatTouchedMe)) {
    
this.playersThatTouchedMe.add(player.account);
  }

Inside a normal NPCs, the this.playersThatTouchedMe array would reset everytime you update/edit the level. with a DB NPC this would still be saved as a flag.

3. To change a players hat, you need to change the players attr[1] (player.attr[1] = "hat image file";) and for the players head, you need to set the player.head = "head image file"; (for trial users its limited to head0.png to head15.png, maybe even just head10.png).

4. Using && will get you the option to see if the 2nd statement is also true, while using || will check if either one of the statements is true

The or check:
PHP Code:
function onPlayerTouchsMe() {
    
//check if 'player.account' is either 'Stefan' or 'Unixmad'
  
if (player.account == "Stefan" || player.account == "Unixmad") {
    
player.chat "Hey I'm Stefan or Unixmad";
  }

Basically the same as
PHP Code:
function onPlayerTouchsMe() {
  if (
player.account == "Stefan") {
    
player.chat "Hey I'm Stefan or Unixmad";
  }
  else if (
player.account == "Unixmad") {
    
player.chat "Hey I'm Stefan or Unixmad";
  }



The and check:
PHP Code:
function onPlayerTouchsMe() {
    
//check if 'player.account' is 'Stefan' and if he is wearing the 'head0.png' head
  
if (player.account == "Stefan" && player.head == "head0.png") {
    
player.chat "Hey I'm Stefan wearing the head0.png!!";
  }

Basically the same as:
PHP Code:
function onPlayerTouchsMe() {
    
//check if 'player.account' is 'Stefan' and if he is wearing the 'head0.png' head
  
if (player.account == "Stefan") {
    if (
player.head == "head0.png") {
      
player.chat "Hey I'm Stefan wearing the head0.png!!";
    }
  }

__________________
MEEP!
Reply With Quote
  #4  
Old 11-20-2013, 10:09 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
So a class is kind of like a variable, where it has code that you can just type the class file instead of re-entering all the code?
Thanks for all the answers btw
Reply With Quote
  #5  
Old 11-20-2013, 09:43 PM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 353
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
in addition to what cyan3 said, classes are not an actual object such as an npc or weapon, but scripts which are essentially copied and pasted (dynamically) into other scripts. you can join multiple classes into one script, you can join classes within classes, and classes can be joined to multiple different types of objects which for example includes players

npcs within rc (often called database npcs) are permanent objects which are not binded to a particular level, so for example if you updated a level all npcs within it would reset to their original state whereas a database npc would retain variables which were stored on it. database npcs can also be warped into different levels and can have their scripts processed without players being in the same level
__________________
This signature has been deleted by Darlene159.
Reply With Quote
  #6  
Old 11-20-2013, 10:54 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Let's say more of a non-changeable flag ('const flag' if you're already familiar with that)
__________________
MEEP!
Reply With Quote
  #7  
Old 11-21-2013, 06:56 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Quote:
Originally Posted by Torankusu View Post
Thanks, I knew about fowlplay's but I'll check out the gscript dev one

I have another question, (I think it would be better just to post any questions I have under this thread instead of spamming forums, not sure). I am trying to make a staff block/spawn and npc. I somewhat know how to make it, but I'm not sure how you would do it. This is my current script so far.
NPC Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat = ":blockspawnon") {
enabled = true;
if (player.chat = ":blockspawnoff") {
enabled = false;
}
if (enabled = true) {
player.chat = "Block Spawned!";
putnpc("block.png","test",30,30);
this.chat = "block";
drawunderplayer();
block();
}
}
}

Reply With Quote
  #8  
Old 11-21-2013, 08:57 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by iDigzy View Post
Thanks, I knew about fowlplay's but I'll check out the gscript dev one

I have another question, (I think it would be better just to post any questions I have under this thread instead of spamming forums, not sure). I am trying to make a staff block/spawn and npc. I somewhat know how to make it, but I'm not sure how you would do it. This is my current script so far.
NPC Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat = ":blockspawnon") {
enabled = true;
if (player.chat = ":blockspawnoff") {
enabled = false;
}
if (enabled = true) {
player.chat = "Block Spawned!";
putnpc("block.png","test",30,30);
this.chat = "block";
drawunderplayer();
block();
}
}
}

putnpc needs to be serverside

PHP Code:
function onActionServerside() {
  
// ...
  // putnpc2()
}
//#CLIENTSIDE
... other stuff 
You will need to trigger this so look up triggerserver.
Reply With Quote
  #9  
Old 11-21-2013, 09:22 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Quote:
Originally Posted by scriptless View Post
putnpc needs to be serverside

PHP Code:
function onActionServerside() {
  
// ...
  // putnpc2()
}
//#CLIENTSIDE
... other stuff 
You will need to trigger this so look up triggerserver.
thanks
Reply With Quote
  #10  
Old 11-21-2013, 09:39 PM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 353
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
Quote:
Originally Posted by iDigzy View Post
Thanks, I knew about fowlplay's but I'll check out the gscript dev one

I have another question, (I think it would be better just to post any questions I have under this thread instead of spamming forums, not sure). I am trying to make a staff block/spawn and npc. I somewhat know how to make it, but I'm not sure how you would do it. This is my current script so far.
NPC Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat = ":blockspawnon") {
enabled = true;
if (player.chat = ":blockspawnoff") {
enabled = false;
}
if (enabled = true) {
player.chat = "Block Spawned!";
putnpc("block.png","test",30,30);
this.chat = "block";
drawunderplayer();
block();
}
}
}

when comparing values you need to use '==' rather than '=', as '=' is for assigning values and when assigning values it always returns true

for this example you should be assigning the variable using the 'this.' prefix, otherwise it would apply globally which would cause conflict if there were multiple copies of this npc

its also good to avoid checking conditions you already know to be false, for example you can do -

PHP Code:
if (player.chat == ":blockspawnon") {
  
this.enabled true;
}
else if(
player.chat == ":blockspawnoff") {
 
this.enabled false;

or -

PHP Code:
  this.enabled = (player.chat == ":blockspawnon") ? true :
    (
player.chat == ":blockspawnoff") ? false this.enabled
  

__________________
This signature has been deleted by Darlene159.
Reply With Quote
  #11  
Old 11-21-2013, 11:58 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Well I have absolutely no clue how to trigger the server, after reading a little on it, this is what I have made (not sure if it makes sense though). Hopefully someone can help me fix/understand it D:?
Quote:
function onActionServerSide(a) {
if (cmd == "testing") {
triggerClient("test", this.name, "testing");
}
}

//#CLIENTSIDE
function onPlayerChats() {
if (player.chat = "test") {
triggerServer("test", this.name, "testing");
}
}

function onActionClientSide(a) {
if (cmd == "testing") {

player.chat = "elephants";
triggerServer("test", this.name, "testing");
}
}
Reply With Quote
  #12  
Old 11-21-2013, 12:12 PM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu has a spectacular aura aboutTorankusu has a spectacular aura about
http://public.zodiacdev.com/Fowlplay4

http://www.graal.net/index.php/Creation/Dev/GScript

These two links have been helping me get back into gs2.
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #13  
Old 11-22-2013, 12:37 AM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu has a spectacular aura aboutTorankusu has a spectacular aura about
I am brushing up on these features as well, so I will link you directly to the resource(s) I am using...

http://forums.graalonline.com/forums...17&postcount=4
http://forums.graalonline.com/forums...84&postcount=6

Both, courtesy of cbk.


I guess to expound based on your usage:

I'd recommend creating a CLASS for your staff block.
Using putnpc2 (serverside only), it will determine the position to place that block when the server is triggered.
You will then join that NPC placed to the class of your staff block (ex: npc.join("class name"); )

Also, you should get into the habit of using the "echo" feature to ensure parts of your code are working correctly.

Example:

PHP Code:
function onActionServerSide(cmd){
  if (
cmd == "test"){
    echo(
"test successful");
  }
}


//#CLIENTSIDE

function onPlayerChats(){
  if (
player.chat == "test"){
    
triggerServer("gui"this.name"test");
  }


That is an example of a working trigger to the server, that will echo "test successful" in your RC if the player with the weapon says "test", and hopefully help you understand the basic format for it better.

Hopefully someone else can chime in as far as setting parameters to transfer to the server, as I am still messing around with that. :P
__________________
Quote:
Originally posted by Spark910
Think befreo you type.

Last edited by Torankusu; 11-22-2013 at 02:18 AM..
Reply With Quote
  #14  
Old 11-22-2013, 01:01 AM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Quote:
Originally Posted by Torankusu View Post
I am brushing up on these features as well, so I will link you directly to the resource(s) I am using...

http://forums.graalonline.com/forums...17&postcount=4
http://forums.graalonline.com/forums...84&postcount=6

Both, courtesy of cbk.
Thanks to you and cbk, I'll take a look at it
Reply With Quote
  #15  
Old 11-27-2013, 05:30 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Well I haven't posted a question on here in a bit, but I ran into another problem. I want to make a script that sets the players tag. I'm not sure if this script is correct in any way/or if I over thought it. Can someone tell me whats wrong :o?
PHP Code:
function onActionSeverside(tags){
if (
tokens[0] == "/tag"){
player.guild "Elepahnt";
}
}

//#CLIENTSIDE
function onPlayerChats(){
if (
player.chat == "/tag"){
temp.tokens player.chat.tokenize();
triggerServer("gui"this,nametags);
}

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:55 PM.


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