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 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


All times are GMT +2. The time now is 01:38 PM.

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