Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #61  
Old 02-11-2014, 11:10 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
@ 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?
__________________
Reply With Quote
  #62  
Old 02-11-2014, 11:42 PM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu has a spectacular aura aboutTorankusu has a spectacular aura about
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...
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #63  
Old 02-13-2014, 06:07 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
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?
__________________
Reply With Quote
  #64  
Old 02-13-2014, 06:37 PM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu has a spectacular aura aboutTorankusu has a spectacular aura about
Quote:
Originally Posted by iDigzy View Post
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);
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #65  
Old 02-13-2014, 06:48 PM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
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);

__________________
Reply With Quote
  #66  
Old 02-15-2014, 05:14 AM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Quote:
Originally Posted by Tim_Rocks View Post
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 .
__________________
Reply With Quote
  #67  
Old 02-15-2014, 06:08 AM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu has a spectacular aura aboutTorankusu has a spectacular aura about
Quote:
Originally Posted by iDigzy View Post
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 ?
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #68  
Old 02-15-2014, 05:26 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
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;

__________________
Reply With Quote
  #69  
Old 02-16-2014, 05:06 AM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
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.
__________________
Reply With Quote
  #70  
Old 02-18-2014, 03:51 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Thanks tim and torankusu for the help. I finally get how to set it up
__________________
Reply With Quote
  #71  
Old 02-23-2014, 03:58 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
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)
__________________
Reply With Quote
  #72  
Old 02-23-2014, 05:55 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
I think you should stick to the other scripting stuff before jumping over to sql
__________________
MEEP!
Reply With Quote
  #73  
Old 02-23-2014, 06:53 PM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 354
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
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
__________________
This signature has been deleted by Darlene159.
Reply With Quote
  #74  
Old 02-23-2014, 11:54 PM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
Thanks for the replies, I guess I'll just stick with learning some other things for now than
__________________
Reply With Quote
  #75  
Old 03-22-2014, 12:55 AM
iDigzy iDigzy is offline
Registered User
Join Date: Apr 2013
Posts: 44
iDigzy is on a distinguished road
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
__________________
Reply With Quote
Reply


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 03:18 AM.


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