Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Raelyn's Big Book of Scripting Questions. (https://forums.graalonline.com/forums/showthread.php?t=85091)

Raelyn 05-01-2009 06:26 AM

Quote:

Originally Posted by fowlplay4 (Post 1488079)
You can use GS2 now! Don't be a slave to GS1 conventions.

PHP Code:

function onTrigger() {
  
with (findimg(index)) {
     
image clientr.weapon_img;
     
thiso.x;
     
thiso.y;
  }



The thing I don't understand is that this looks like it is outlining a function... so if I made function onTrigger(), how would I call it? Just with onTrigger();?

Pelikano 05-01-2009 10:13 AM

Quote:

Originally Posted by Raelyn (Post 1488106)
The thing I don't understand is that this looks like it is outlining a function... so if I made function onTrigger(), how would I call it? Just with onTrigger();?

Why don't you try it before asking :o?

And yes, onTrigger() would call it.

Raelyn 05-01-2009 03:34 PM

Quote:

Originally Posted by Pelikano (Post 1488112)
Why don't you try it before asking :o?

And yes, onTrigger() would call it.

Well, I did.. I believe I posted it.

I tried to do

PHP Code:

function onTrigger(){
}

if 
onTrigger(){


Which doesn't look right to me. o.o

Chompy 05-01-2009 04:04 PM

Quote:

Originally Posted by Raelyn (Post 1488148)
Well, I did.. I believe I posted it.

I tried to do

PHP Code:

function onTrigger(){
}

if 
onTrigger(){


Which doesn't look right to me. o.o

Well,

PHP Code:

function onCreated() {
  
onTrigger();
}

function 
onTrigger() {
  
// do stuff



Raelyn 05-01-2009 04:31 PM

Quote:

Originally Posted by Chompy (Post 1488154)
Well,

PHP Code:

function onCreated() {
  
onTrigger();
}

function 
onTrigger() {
  
// do stuff



See, that confuses me, so there is no need to designate functions anymore? Or, alternatively, there is no need to set up triggers? The function itself is a trigger?

So instead of writing:

PHP Code:


function ThisStuff(){
  
stuff;
}

if (
trigger){
  
ThisStuff();


I can just do:

PHP Code:

function onThisStuffTrigger(){
  
stuff;


and it would act the same?

Chompy 05-01-2009 04:51 PM

Quote:

Originally Posted by Raelyn (Post 1488159)
See, that confuses me, so there is no need to designate functions anymore? Or, alternatively, there is no need to set up triggers? The function itself is a trigger?

So instead of writing:

PHP Code:


function ThisStuff(){
  
stuff;
}

if (
trigger){
  
ThisStuff();


I can just do:

PHP Code:

function onThisStuffTrigger(){
  
stuff;


and it would act the same?

Well, no.

PHP Code:

// This is an event that occurs when the WNPC is updated
function onCreated() {
  
this.string "foo";
}

function 
onTrigger() {
  
this.string "bar";


Since onTrigger() isn't triggered, this.string will be "foo"

However,

PHP Code:

function onCreated() {
  
this.string "foo";

  
onTrigger();
}

function 
onTrigger() {
  
this.string "bar";


Would now make this.string equal "bar" since the function is triggered.

Raelyn 05-01-2009 05:37 PM

Quote:

Originally Posted by Chompy (Post 1488166)
Well, no.

PHP Code:

// This is an event that occurs when the WNPC is updated
function onCreated() {
  
this.string "foo";
}

function 
onTrigger() {
  
this.string "bar";


Since onTrigger() isn't triggered, this.string will be "foo"

However,

PHP Code:

function onCreated() {
  
this.string "foo";

  
onTrigger();
}

function 
onTrigger() {
  
this.string "bar";


Would now make this.string equal "bar" since the function is triggered.

So I write functions like normal basically in GS1, but to call a trigger, I have to make a function... also?

So, creating the function onCreated() basically itself is a trigger, so you have to use that trigger to initialize all other triggers?

Admins 05-01-2009 06:07 PM

The function onCreated() will automatically be called when the "created" event is triggered by the engine.

Object1 triggers an event on Object2 -> onEvent() in the script of Object2 is called
Object1 can be the engine.

This is working exactly the same in GS1 as in GS2, just looking different:
instead of if (trigger) you write onTrigger(). In GS1 it was actually scanning for "if (trigger)" and was trying to only call that part of the script when the event was triggered.

Raelyn 05-01-2009 06:31 PM

Quote:

Originally Posted by Stefan (Post 1488191)
The function onCreated() will automatically be called when the "created" event is triggered by the engine.

Object1 triggers an event on Object2 -> onEvent() in the script of Object2 is called
Object1 can be the engine.

This is working exactly the same in GS1 as in GS2, just looking different:
instead of if (trigger) you write onTrigger(). In GS1 it was actually scanning for "if (trigger)" and was trying to only call that part of the script when the event was triggered.

I see. :)

Raelyn 05-03-2009 12:41 PM

Quote:

Originally Posted by cbk1994 (Post 1488032)
onKeyPressed is called on default. Basically all of the event if's were converted to "function onEvent", such as "onPlayerTouchsMe", "onCreated", and "onPlayerEnters". There's no need for the if (keypressed) statement.

Ok, sorry to ask this again, but I am still having problems with this.. I am trying to use the GS2 solution and it's not working (I'm probably doing it wrong.)

Here is what I got..

PHP Code:

function onKeyPressed(codekeychar) {
  if (
key == "i") {
    
temp.img findImg(209);
    
img.visible = ! img.visible;
  }


I have a function doing showimg 209, and trying to use the code snippet you suggested on key i, the image remains shown, and is not hid, as expected.

Is there a way in GS1 to do this?

PHP Code:

if (keypressed) {
   if (
strequals(#p(1),I)){
      
if (img 209 is visible){
         
hideimg 209;
      } else {
         
showimg 209,file,x,y;
      }
   }



fowlplay4 05-03-2009 04:32 PM

visible doesn't work with images.

you could do something like..

PHP Code:

function onKeyPressed(codekeychar) {
  if (
key == "i") {
    if (
findImg(209).image != NULL) {
      
hideimg(209);
    }
  }



Raelyn 05-03-2009 04:34 PM

Quote:

Originally Posted by Raelyn (Post 1488664)
Is there a way in GS1 to do this?

PHP Code:

if (keypressed) {
   if (
strequals(#p(1),I)){
      
if (img 209 is visible){
         
hideimg 209;
      } else {
         
showimg 209,file,x,y;
      }
   }



Solved myself with

PHP Code:



this
.inv_shown 1;

if (
keypressed) {
   if (
strequals(#p(1),I)){
      
Inventory();
   }


function 
Inventory(){

  if (
this.inv_shown == 0){

    
// inventory pane
    
showimg 209;
    
this.inv_shown 1;

  } else {

    
hideimg 209;
    
this.inv_shown 0;
  }


I have another question though, I am trying to change profilevars in server options, and I have

PHP Code:

profilevars=Level:=#v(clientr.level), 

Yet it is not picking up the clientr.level off my NPC...?

Raelyn 05-03-2009 04:56 PM

Quote:

Originally Posted by fowlplay4 (Post 1488698)
visible doesn't work with images.

you could do something like..

PHP Code:

function onKeyPressed(codekeychar) {
  if (
key == "i") {
    if (
findImg(209).image != NULL) {
      
hideimg(209);
    }
  }



Mmm, ok thanks. I was just having someone test me script, and I have it calling replaceani in clientside, so his client is not downloading the ganis from the server. But if I put the replaceani in serverside, the RC reports an error that the server doesn't know that command... So, what command does it understand to get new ganis for the player?

cbk1994 05-03-2009 06:22 PM

Quote:

Originally Posted by Raelyn (Post 1488699)
Solved myself with

PHP Code:



this
.inv_shown 1;

if (
keypressed) {
   if (
strequals(#p(1),I)){
      
Inventory();
   }


function 
Inventory(){

  if (
this.inv_shown == 0){

    
// inventory pane
    
showimg 209;
    
this.inv_shown 1;

  } else {

    
hideimg 209;
    
this.inv_shown 0;
  }



Be sure to convert that to GS2...
Quote:

I have another question though, I am trying to change profilevars in server options, and I have

PHP Code:

profilevars=Level:=#v(clientr.level), 


You don't need #v, just (for example):
PHP Code:

profilevars=Level:=clientr.level,HP:=clientr.hp 

Quote:

Originally Posted by Raelyn (Post 1488705)
Mmm, ok thanks. I was just having someone test me script, and I have it calling replaceani in clientside, so his client is not downloading the ganis from the server. But if I put the replaceani in serverside, the RC reports an error that the server doesn't know that command... So, what command does it understand to get new ganis for the player?

What do you mean, like download them? Just displaying the animations will download them, but if you really want you can use update packages.

fowlplay4 05-03-2009 06:48 PM

Make sure you have the following the folder config.

PHP Code:

file  ganis/*.gani 

So people can download the ganis from the the levels/ganis folder.

Then in a clientside script you can just use

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
replaceani("idle""someotheridleani");
  
replaceani("walk""someotherwalkani");



Raelyn 05-03-2009 07:08 PM

Quote:

Originally Posted by cbk1994 (Post 1488726)
Be sure to convert that to GS2...

You don't need #v, just (for example):
PHP Code:

profilevars=Level:=clientr.level,HP:=clientr.hp 


What do you mean, like download them? Just displaying the animations will download them, but if you really want you can use update packages.

Ok, well, my script is clientside, so that means the server can't GET my clientr.level, right? I need to find some way for for the server to read my clientside variables..

If I join a class to a clientside script, does everything in that class become clientside as if it waste pasted into the class? I am trying to think of another way to split this script so I can maintain my clientside timeouts but have my variables accessible by the server...

Also, I have another problem that is whenever more than one person is on my server, (having the -Player weapon), ONE part of my interface is duplicated in the center of the screen... it's only the one part, and everything else works as intended.. :confused:

Raelyn 05-03-2009 07:17 PM

Quote:

Originally Posted by fowlplay4 (Post 1488728)
Make sure you have the following the folder config.

PHP Code:

file  ganis/*.gani 

So people can download the ganis from the the levels/ganis folder.

Then in a clientside script you can just use

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
replaceani("idle""someotheridleani");
  
replaceani("walk""someotherwalkani");



Thanks, that was the problem. :)

Deas_Voice 05-04-2009 02:48 PM

Quote:

Originally Posted by Raelyn (Post 1488731)
Ok, well, my script is clientside, so that means the server can't GET my clientr.level, right? I need to find some way for for the server to read my clientside variables..

Pass them to the server with
PHP Code:

//#CLIENTSIDE
function onEvent() {
triggerServer("gui","WeaponName","Equal",this.bar,temp.foo);


then on the serverside u could do something like this:
PHP Code:

function onActionServerSide(){
  if (
params[0] == "Equal") {
    
this.thing params[1];
    
this.var = params[2];
  }


then u can use this.bar and temp.foo at serverside. :)
but they will be named this.thing and this.var ofc ;)

Deas_Voice 05-04-2009 02:51 PM

Quote:

Originally Posted by fowlplay4 (Post 1488728)
Make sure you have the following the folder config.

PHP Code:

file  ganis/ *.gani 

So people can download the ganis from the the levels/ganis folder.

fixed, the forum didn't show it :)
(no space between the / and the *)

Raelyn 05-04-2009 05:09 PM

I am trying to do a script for something like:

PHP Code:

if (playerchats){
  if (
strequals(#c,/summon "otherplayeraccountname")){
    
otherplayeracctname newxnewy;
  }


What would I use to get the account name of the said player, and what would I use to set the x/y of ANOTHER player other than the player triggering?

fowlplay4 05-04-2009 05:21 PM

Here's a simple summon weapon script, however since you probably deal with community names you may have to modify the findplayer to findplayerbycommunityname, or whatever it is.

PHP Code:

function onActionServerSide() {
  
// Summons Player to You
  
if (params[0] == "summon") {
    
// Adjusts the Players Level, X, Y
    
findplayer(params[1]).setlevel2(player.levelplayer.xplayer.y);
    
// Adjusts Players Chat 
    
findplayer(params[1]).chat "Summoned by" SPC player.account;
  } 
}

//#CLIENTSIDE

function onPlayerChats() {
  if (
player.chat.starts("/summon")) {
    
// Gets acct from "/summon acct"
    
temp.toSummon player.chat.substring("/summon ".length());
    
// Sends Trigger to Server
    
triggerserver("gui"this.name"summon"toSummon);
  }




All times are GMT +2. The time now is 08:05 PM.

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