Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Scripting questions (https://forums.graalonline.com/forums/showthread.php?t=134268910)

iDigzy 01-03-2014 10:29 PM

Quote:

Originally Posted by cbk1994 (Post 1724864)
In the future please use [PHP] tags to format code.

Your trigger is fine except that it looks like you're using the code in an NPC (since you use onPlayerTouchsMe). You can't trigger NPCs the same way you trigger weapons. You would either have to do a triggerAction at the NPC's position, or a fancier trigger (like triggering a weapon or DB NPC).

However, since you're using it in an NPC, you don't even need a trigger. onPlayerTouchsMe gets called serverside, too, so you can just do...

PHP Code:

function onPlayerTouchsMe() {
  
// you can move this line clientside if you don't want everyone to see
  // the chat change
  
this.chat player.nick SPC "welcome to Castaway! To get started talk to Brian the skiller outside just outside of here";
  
player.clientr.tutorial 1;


(if this doesn't work, you may need to set the shape of the NPC serverside by using setShape).

Thanks for the quick response :D, that seems to work. However if I try to make it work for clientside so only the player sees the chat it does not work. I was wondering if it would make much of a difference if I used player.client.tutorial=1; instead of clientr as client seems to work on clientside. Or would it be better to do a trigger in an npc so it can use clientr?

cbk1994 01-03-2014 10:33 PM

Quote:

Originally Posted by iDigzy (Post 1724865)
Thanks for the quick response :D, that seems to work. However if I try to make it work for clientside so only the player sees the chat it does not work. I was wondering if it would make much of a difference if I used player.client.tutorial=1; instead of clientr as client seems to work on clientside. Or would it be better to do a trigger in an npc so it can use clientr?

You probably only want to move the chat line clientside.

PHP Code:

function onPlayerTouchsMe() {
  
player.clientr.tutorial 1
}

//#CLIENTSIDE
function onPlayerTouchsMe() {
  
this.chat player.nick SPC "welcome to Castaway! To get started talk to Brian the skiller outside just outside of here";


Alternatively, yes, you can use player.client instead as long as you don't care that cheating players can easily tamper with that variable.

iDigzy 01-14-2014 09:59 PM

I started working on a simple shop script, however I have already ran into another problem. I want to trigger a weapon so whenever the player clicks the object it will trigger the simple shop gui I made. How would I go about triggering a weapon from an npc :o?

Torankusu 01-14-2014 10:13 PM

in the item you are clicking on, you need this:

PHP Code:

function onActionRightMouse(){ //or if you want left click, switch Right for Left ;]
  
triggerClient("weapon""<WEAPONNAME>""actionorwhatever"additional params available);


and then in your weapon you will need to check for the trigger...
ex:
PHP Code:

//#CLIENTSIDE
function onActionClientside(actionorwhateverhereadditionalparamspossible..) 

  
//can do conditional or switch statement depending on the actionorwhatever
  //and how many things you want to check here..
  
displayPurchaseMenu(); // or whatever you want to call the function to display your menu


Be careful here, because you need to set up some serverside security as well, such as checking to ensure that the item the client is sending that they want to purchase is the correct item, as well as the price is the correct price that it should be (check a DB or something that stores the price information serverside so that it can not be manipulated). The reason for the additional security is because someone could essentially buy anything they wanted for FREE if all of the purchasing was handled on the clientside (adding items and things should be handled on serverside anyway)

--Hopefully someone can chime in with better examples of the above paragraph, as I have not fooled with it recently. ;]

Here are a few examples and helpful posts:
Skyld's Shop Script
That one is somewhat outdated, but still relevant (note, the triggeraction used there has since been replaced -> use triggerClient instead)

Also, it might be noted, that Skyld's example stores the items information in a Database (multiple) -- This could now be redone to support SQLite..

Also, some helpful posts for triggering:

Serverside / Clientside actions explained
http://forums.graalonline.com/forums...84&postcount=6

good trigger examples both ways:
http://forums.graalonline.com/forums...17&postcount=4

Trigger DB from Level NPC
http://forums.graalonline.com/forums...41&postcount=9

iDigzy 01-14-2014 10:46 PM

@Torankusu

Thank you :D, I'll play around with it and see what I can do for adding security. I''m pretty sure the ActionLeftMouse works on serverside as well, would it be better to make the trigger that triggers the weapon serverside also?

Torankusu 01-14-2014 11:29 PM

onActionLeftMouse () or right,

Will work on serverside.
You want to send serverside info to the client, so keep the trigger on serverside, and detect it in the weapon npc on clientside. (Note my usage: triggerClient [serverside to clientside] -- causes the event onActionClientside [clientside...].

My terminology might be incorrect, but look at the examples and how they are set up. Also check the other posts by cbk, they are really helpful.

iDigzy 01-15-2014 08:11 PM

I just haven't been able to get it to work. Am I doing something wrong?
I put this into the npc
PHP Code:

function onActionRightMouse(){
  
triggerClient("weapon""<guishop>""openshop");


than I use this for the weapon script, named guishop
PHP Code:

//#CLIENTSIDE
function onActionClientside(openshop){
  new 
GuiWindowCtrl("MyGUI_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,240";

    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text "Window 1";
    
849;
    
167;
  }



Emera 01-15-2014 08:46 PM

Remove the < and >

iDigzy 01-23-2014 07:03 PM

How would you make it so it knows what row is selected on a gui text list? I tried doing a few things, would this work?
PHP Code:

  function Tools.onSelect(temp.i) {
  if (
rowselected == 0){
  
Player.chat I clicked a row!;
  } 

this is the current code I have to get a better idea of what I mean, not too sure if my post is that clear..
http://pastebin.com/svjPXSGe

fowlplay4 01-23-2014 09:59 PM

PHP Code:

function Tools.onSelect(entryid,entrytext,entryindex) {
  
// use entryid, entrytext, or entryindex however you want
  
echo("Clicked " entrytext);



Torankusu 01-24-2014 01:44 AM

There are a few things you could change with what you have written up so far..

We'll start from the beginning, excluding the onSelect event...we'll get back to that, but first:

PHP Code:

//#CLIENTSIDE
/*ignore this...
function Tools.onSelect(temp.i) {
  if (row == 0){
    player.chat = this.items[temp.i][0] SPC "Selected";
  }
}
keep ignoring this..*/

//THIS:
this.tools = {
  {
"Boots"1"no-icon.gif"}, 
  {
"a"2"no-icon.gif"}
}; 

Try not to define arrays or variables outside of a function or an event (if it is not a constant.)
Putting this inside of onCreated() { this.tools = {blah...}; } will work, but I'd recommend an alternative method for defining the tools list (possibly something serverside if this is a shop menu and sending it to the client).

Continuing on...

PHP Code:

function onCreated() {
  new 
GuiWindowCtrl("MyGUI_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "180,218";

    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text "Tools";
    
1170// <----THIS... 

Alright...so what that's saying is it needs to start at 1170 pixels from the left of the screen, but not every user has a screen/w!ndow that wide

Use
PHP Code:

GraalControl.width this.width

That takes into account the width of their graal/client w!ndow and positions the new menu where you want it...

In your code, your list control is this:
PHP Code:

    new GuiTextListCtrl("Test_List") {
     
profile GuiBlueTextListProfile;
     
0;
     
width 140;
     
fitparentwidth true;
 
     
clearrows();
      for (
temp.ithiso.tools) {
          
addrow(temp.ntemp.i[0]);
          
temp.n++;
        }
     
setSelectedRow(0);
      } 

"Test_List", but in the function you are drawing up or testing, you reference it as "Tools" -- but there is not a control with the name tools...

It should be:

PHP Code:

function Test_List.onSelect(entryid,entrytext,entryindex) {
  
// use entryid, entrytext, or entryindex however you want
  
echo("Clicked " entrytext);


Also, please note, that this ECHO will have to be viewed by pressing F2 and looking at the output there since this is clientside.

iDigzy 01-24-2014 07:18 PM

@Fowlplay Thanks, I couldn't find a thing to use, that's just the kind of thing I was looking for :D

@Torankusu Thanks for looking through it, it's more of just a random thing I was working on to get more practice with gui's etc, so I didn't think of adding serverside protection or whatever for the array. As for the rest, thanks I'm gonna take a look at my code and see if I can fix these errors :)

fowlplay4 01-24-2014 08:50 PM

You can find more events for GUI objects here:

http://wiki.graal.net/index.php/Crea...ent/GuiControl

iDigzy 02-01-2014 03:03 AM

I am having trouble with params. I am really not sure how to phrase this question I will try the best I can. Ok so I was making a small shop menu, and I wanted to have the npc trigger the shop menu. In the npc trigger to the shop it would contain the price and other params. I want to be able to use these params in the weapon it triggers and for example make the price.txt = the param price. I also am confused on how the script will know what the trigger is and to make it so it only uses the param of that trigger. For example, if you had more than one triggers going to a weapon script and you wanted to make a gui txt say param 3, how would you be able to tell it to only use param 3 of a certain trigger? I pasted my current script also, as I''m pretty sure I did not phrase any of this right D:
Npc - http://pastebin.com/uiBWRAUL
Weapon - http://pastebin.com/W87eGjhX

iDigzy 02-03-2014 03:51 PM

Never mind on my last post. I was over thinking something simple.


All times are GMT +2. The time now is 04:01 AM.

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