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)

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.

Torankusu 02-03-2014 05:22 PM

For what its worth, params start at 0

Your npc script:
params[0] = buymenu1
params[1] = 1000
params[2] = nameyouhad?

Also, you can do:
onActionClientside (cmd, price, itemname)
and reference the parameters passed from serverside that way.

Ex: echo(price);

iDigzy 02-05-2014 06:22 AM

Quote:

Originally Posted by Torankusu (Post 1725855)
For what its worth, params start at 0

Your npc script:
params[0] = buymenu1
params[1] = 1000
params[2] = nameyouhad?

Also, you can do:
onActionClientside (cmd, price, itemname)
and reference the parameters passed from serverside that way.

Ex: echo(price);

Ahh, thanks for the reply anyways :).

Would anyone be able to explain tokenizing to me/link me to anything on it please?

Torankusu 02-05-2014 11:45 AM

Quote:

Originally Posted by iDigzy (Post 1725894)
Ahh, thanks for the reply anyways :).

Would anyone be able to explain tokenizing to me/link me to anything on it please?

obj.tokenize([delimiters]) - splits the string into an array wherever the delimiters occur

Example:
Player chats: "This is an example"

PHP Code:

player.chat.tokenize(" "); //uses spaces as separator 

Can access tokens like this:
tokenscount (will yield 4)
tokens[0] will reference the first token (the word "this").
Similarly,
tokens[2] will reference the word "an".

callimuc 02-05-2014 10:47 PM

Quote:

Originally Posted by Torankusu (Post 1725902)
obj.tokenize([delimiters]) - splits the string into an array wherever the delimiters occur

Example:
Player chats: "This is an example"

PHP Code:

player.chat.tokenize(" "); //uses spaces as separator 

Can access tokens like this:
tokenscount (will yield 4)
tokens[0] will reference the first token (the word "this").
Similarly,
tokens[2] will reference the word "an".

ps: if its only for spaces, you could also just do player.chat.tokenize()

iDigzy 02-05-2014 11:51 PM

Quote:

Originally Posted by Torankusu (Post 1725902)
obj.tokenize([delimiters]) - splits the string into an array wherever the delimiters occur

Example:
Player chats: "This is an example"

PHP Code:

player.chat.tokenize(" "); //uses spaces as separator 

Can access tokens like this:
tokenscount (will yield 4)
tokens[0] will reference the first token (the word "this").
Similarly,
tokens[2] will reference the word "an".

Thanks :), would you use tokenizeing as well when doing such scripts as
PHP Code:

if (player.chat.starts("text")){ 
player.chat.substring;


?
Also, for the delimiters, you would basically be able to put for example a word such as "idigzy" and wherever that word occurs it splits it :o?

Torankusu 02-06-2014 12:31 AM

Quote:

Originally Posted by iDigzy (Post 1725921)
Thanks :), would you use tokenizeing as well when doing such scripts as
PHP Code:

if (player.chat.starts("text")){ 
player.chat.substring;



Your example isn't a proper use of substring ( string.substring(index[,length]) ) , but, essentially, yes, you could tokenize the player's chat if a condition is met. I'll let someone else fill you in on substring as I know how it works (sometimes), but am not familiar enough to verse you on its uses...sorry...


random tailor example for tokenize [better ways to do this...example for simplicity sake..]:
PHP Code:

if (player.chat.starts("/set ")){ //player says "/set shoes"
  
player.chat.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
    
//OR...
    //player.colors[2] = player.chat.substring(10,-1); // not 100% sure on this??
  
}


Quote:

Also, for the delimiters, you would basically be able to put for example a word such as "idigzy" and wherever that word occurs it splits it :o?
yeah, you get the concept....
some common delimiters: are , (commas), spaces . (periods) , and so on...

there is a tokenize2 but I didn't want to include it.
You can scripthelp it.

Is there anything you are trying to do in specific, there might be a better approach?

iDigzy 02-06-2014 01:37 AM

@Torankusu Thanks for all the help on that :). I'm not really trying to do anything in particular at the moment, I just thought I'd play around with it since I may use it in the future.

sssssssssss 02-06-2014 03:16 AM

PHP Code:

str.substring(start[,length]) - extracts a substring out of str 

the second parameter is how long you want to grab for the substring. -1 for the length will go to the end of the string.

Also
PHP Code:

function ChatBar.onAction() 

is the same as
PHP Code:

function onPlayerChats() 

From what I understand it's recommended to use ChatBar. I've even had issues with playerchats here and there, but not with chatbar. ChatBar is the Gui default where you type in the text.

and
PHP Code:

ChatBar.text 

is the same as
PHP Code:

player.chat 

when using the ChatBar function instead.

so:
PHP Code:

function ChatBar.onAction() {
  if (
ChatBar.substring(04) == "/set") { //honestly i cant remember if it starts at 0 or 1, I believe its 0. If not, you'd do 1, 4
    
temp.tokens ChatBar.text.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
  }
}
// i believe you could dynamically set it with substrings, but since it's already in tokens, it's better to just use the tokens. 


iDigzy 02-07-2014 07:23 PM

@sssssssssss thanks for the response :)

sssssssssss 02-08-2014 12:34 AM

I saw an error in my code. :x sry

PHP Code:

function ChatBar.onAction() {
  if (
ChatBar.text.substring(04) == "/set") { //honestly i cant remember if it starts at 0 or 1, I believe its 0. If not, you'd do 1, 4
    
temp.tokens ChatBar.text.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
  }
}
// i believe you could dynamically set it with substrings, but since it's already in tokens, it's better to just use the tokens. 


iDigzy 02-09-2014 04:12 PM

Would anyone be able to link me to some guides on databases/some good examples :)?

cyan3 02-09-2014 06:48 PM

Quote:

Originally Posted by iDigzy (Post 1725994)
Would anyone be able to link me to some guides on databases/some good examples :)?

The Graal wiki has a good page on the use of SQLite in GScript.

http://wiki.graal.net/index.php/Crea...t/Using_SQLite

cbk1994 02-09-2014 09:28 PM

Quote:

Originally Posted by cyan3 (Post 1725998)
The Graal wiki has a good page on the use of SQLite in GScript.

http://wiki.graal.net/index.php/Crea...t/Using_SQLite

I wouldn't really call it a good page. A lot of the explanation is not very clear and I didn't have a very good understanding of SQLite when I wrote it.

My advice would probably be to learn SQL/SQLite outside of Graal first. Using it in Graal will then be pretty easy.

callimuc 02-10-2014 10:11 PM

Quote:

Originally Posted by sssssssssss (Post 1725963)
I saw an error in my code. :x sry

PHP Code:

function ChatBar.onAction() {
  if (
ChatBar.text.substring(04) == "/set") { //honestly i cant remember if it starts at 0 or 1, I believe its 0. If not, you'd do 1, 4
    
temp.tokens ChatBar.text.tokenize(); //as previously mentioned, SPACES become separators
  
if (tokens[1] == "shoes"){
    
player.colors[2] = tokens[2];
  }
}
// i believe you could dynamically set it with substrings, but since it's already in tokens, it's better to just use the tokens. 


now if there isnt some kind of error then ill restart scripting and learn it all from the beginning :p

sssssssssss 02-11-2014 01:49 PM

:x

iDigzy 02-11-2014 11:10 PM

@ cyan3 thanks for the link, but I should have made myself more clear, I'm trying to practice/learn database npc more at the moment, I will be learning or starting SQL whenever I am more advanced
@cbk1994 I'll remember that for when I start thanks

I'm really stuck on database/database npc's though. Are there many guides/information on them? Also, how would you go about making for example a simple spar stat database to keep information on player spar wins? Also, could someone possibly explain why/when you would use them more often, as it would probably make more seance to just use clientr to record spar stats for example?

Torankusu 02-11-2014 11:42 PM

I can't help much with this, but I can give you an example in relation to the shop stuff you were working on previously.

full script: http://forums.graalonline.com/forums...highlight=shop

In a Database NPC, such as: DB_Prices, put the following:
PHP Code:

function onCreated() 

  
// Format: 
  // this.item_id = price 
   
  
this.item_100 3// 3 gralats in this case 
  
this.item_200 5// 5 gralats in this case, etc...


You can access it in other scripts such as this:

PHP Code:

  this.price DB_Prices.("item_" this.item); //could also be temp.price if you just wanted to store it temporarily 

It adds a bit more security behind transactions as the prices between certain items (ex: this.item_100) cannot be manipulated when purchasing an item in a client menu, as it gathers the price data on the serverside from the Database (DB_Prices).

That is just one example. I do hope someone else can chime in because I would like to learn a bit more when a Database NPC might be more plausible than just a regular level NPC, etc...

iDigzy 02-13-2014 06:07 PM

Thanks for the reply, but I'm still having trouble with them. I tried to make a simple npc where when the player touchs it, it will chat the databases flag. In the database I have
PHP Code:

function onCreated()
{

  
this.item_100 "test";


inside the npc on serverside is
PHP Code:

function onPlayerTouchsMe() {
  
this.chat DB_test.("item_100" this.item);


this ends up not setting the chat to test and ends up making it 0, so I assume I identified the flag wrong?

Torankusu 02-13-2014 06:37 PM

Quote:

Originally Posted by iDigzy (Post 1726037)
Thanks for the reply, but I'm still having trouble with them. I tried to make a simple npc where when the player touchs it, it will chat the databases flag. In the database I have
PHP Code:

function onCreated()
{

  
this.item_100 "test";


inside the npc on serverside is
PHP Code:

function onPlayerTouchsMe() {
  
this.chat DB_test.("item_100" this.item);


this ends up not setting the chat to test and ends up making it 0, so I assume I identified the flag wrong?


Right. What is the name of your database? Your script says its DB_test

Also, you need to indicate the item id in the npc you're touching somewhere: ex:
this.item = 100;

Then reference it like this:
this.chat = DB_test.("item_" @ this.item);

Tim_Rocks 02-13-2014 06:48 PM

Maybe this is what you're looking for.

DB_test:
PHP Code:

function onCreated() {
  
this.item_100 "test";
}

public function 
findItem(temp.id) {
  return 
this.(@ "item_" temp.id);


Script:
PHP Code:

function onCreated() {
  
this.id 100;
}

function 
onPlayerTouchsMe() { 
  
player.chat DB_test.findItem(this.id);



iDigzy 02-15-2014 05:14 AM

Quote:

Originally Posted by Tim_Rocks (Post 1726040)
Maybe this is what you're looking for.

DB_test:
PHP Code:

function onCreated() {
  
this.item_100 "test";
}

public function 
findItem(temp.id) {
  return 
this.(@ "item_" temp.id);


Script:
PHP Code:

function onCreated() {
  
this.id 100;
}

function 
onPlayerTouchsMe() { 
  
player.chat DB_test.findItem(this.id);



Thanks for the reply, but I still can't get anything to work. Does it matter what level the npc database is in? It keeps making the chat 0, I have tried altering it a bit still can't figure it out :(.

Torankusu 02-15-2014 06:08 AM

Quote:

Originally Posted by iDigzy (Post 1726057)
Thanks for the reply, but I still can't get anything to work. Does it matter what level the npc database is in? It keeps making the chat 0, I have tried altering it a bit still can't figure it out :(.

i understand you are trying to learn how to use DBNPCs properly, but it would help us troubleshoot if you gave us an idea on exactly what you are trying to do.

I understand you might be trying to go off of my previous examples, but could you give us some code examples ?

iDigzy 02-15-2014 05:26 PM

This may be really off, but I tried to make it so when a player touches the npc it adds 1 to the item_playersname in the databse. Can someone explain what is wrong here and how to fix please?

In NPC:
PHP Code:

function onPlayerTouchsMe() {
  
this.playername player.account;
  
this.ida stats_(this.playername);
  
DB_test.addstats(this.ida) += 1;


In Database:
PHP Code:

function onCreated() {
  
this.item_Graal1059025 =1;
}

public function 
addstats(this.ida) {
  return 
this.(@ "item_" this.ida) += 1;



Tim_Rocks 02-16-2014 05:06 AM

Yeah, seems like you didn't format things properly..

wrong: this.ida = stats_(this.playername);
right: this.ida = (@ "stats_" @ this.playername);

wrong: DB_test.addstats(this.ida) += 1;
right: DB_test.addstats(this.ida);

Although the way you set this up was odd, here's how I would of done it.

NPC:
PHP Code:

function onPlayerTouchsMe() {
  
temp.amt DB_test.addstats(); //You could specify another amount in the parentheses. 

  
player.chat "I've touched this NPC " temp.amt " time(s).";


DB_test:
PHP Code:

function onCreated() { 
  
//this.stats_Graal1059025 =1; 
  //You really don't need the line above unless you want the stats being reset.
}

public function 
addstats(temp.amt) {
  if (
temp.amt null) {
    return 
null//We don't want negatives.
  
}

  if (
temp.amt == null) {
    
temp.amt 1;
  }
  
  return 
temp.stats this.(@ "stats_" player.account) += temp.amt;


I did notice you were mixing "stats" and "item" together. Hopefully this example works, I didn't have a chance to test it.

iDigzy 02-18-2014 03:51 PM

Thanks tim and torankusu for the help. I finally get how to set it up :)

iDigzy 02-23-2014 03:58 PM

I started to take a look at sql and I am pretty stuck on some basic things :(. I wanted to try to make a simple login database for practice, but I couldn't get it to work at all. I used the SQL explorer and put in :

PHP Code:

CREATE TABLE 'login list' 
player TEXT
 


This worked great until I wanted to add information to it from an npc. Is it possible to do the following/if so what would I be doing wrong?

The script in the npc is - http://pastebin.com/2s1HeB2L

(The forums were giving me an error so I just pasted the scripts on pastebin instead)

callimuc 02-23-2014 05:55 PM

I think you should stick to the other scripting stuff before jumping over to sql

Jakov_the_Jakovasaur 02-23-2014 06:53 PM

callimuc is correct, it is not a good idea to delve into sql while not being completely familiar with the language syntax

there are at least 4 problems with what you are attempting to do -
  • for creating the table, the table name does not need to be within quotes and there is no primary key (index) which is a really good idea to include, it is also not a good idea to use spaces within table or column names, a correct example would be - CREATE TABLE loginList (pID INTEGER PRIMARY KEY, account VARCHAR NOT NULL)
  • the players account isnt being concatenated into the insert query string correctly, in gs2 this is what '@' is for, for example - temp.string = "test_" @ player.account @ "_test2";
  • you have player.account wrapped within " " quotes when it is a variable, which if the concatenation was correct it would literally use the text 'player.account' as opposed to the actual account of the player object
  • the table column name is not being set within ( ) brackets

if you ever encounter sql within a live environment you should never tamper with it unless you are completely sure about how it works and how to use it

iDigzy 02-23-2014 11:54 PM

Thanks for the replies, I guess I'll just stick with learning some other things for now than

iDigzy 03-22-2014 12:55 AM

I am working on making a custom chat system, and I wanted to have a gui to display previous chat from the player and other players. I managed to get most of it to work, but I am stuck on getting it to send to other players gui and have it display others text. Can someone explain what is wrong and possibly if there is a better way to find the players than by if they are in the same level?

trigger:
PHP Code:

function onPlayerChats() {
 
triggerserver("gui"this.name"sendchat"player.accountplayer.chatplayer.account);


serverside:
PHP Code:

function onActionServerSide() {
  if (
params[0] == "sendchat") {
    for (
pl allplayers) {
      if (
pl.level == findplayer(params[3]).level) {
        
triggerclient("gui"this.name"displaychat"params[1], params[2]);
       }
    }
  }


the clientside that is retrieved if play is in same area:
http://pastebin.com/ts8SGipV (forum kept giving me a denial message, so I posted it there)


entire script if it helps to get an idea of what i'm doing:
http://pastebin.com/Fm0CMqGb

cbk1994 03-22-2014 02:29 AM

You probably want to do pl.triggerClient so you're triggering on that player, not on whoever the current player happens to be.

iDigzy 03-22-2014 03:47 AM

Quote:

Originally Posted by cbk1994 (Post 1726429)
You probably want to do pl.triggerClient so you're triggering on that player, not on whoever the current player happens to be.

ahh that didn't occur to me, thanks I got it to work now :)


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

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