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: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
  #2  
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
  #3  
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
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 01:43 AM.


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