Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-29-2011, 11:39 PM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
How would you implement an item system?

Not asking for code here nor am I asking to be spoon fed. I'm just wondering what the general consensus would be on implementing an item system in GScript?

For example, how would you implement persistence and how would you implement it so that you're not performing disk reads all the time?

I have a fairly good idea in which to do this, using the SQL capabilities and maybe writing some kind of simplistic object-relational mapping for this (if GScript is powerful/fast enough). For behaviour, I'd probably have some common interface which weapons would need to implement. Either that or a way to define callbacks with arbitrary names.

Again, just wondering what you guys would do. I don't even think it matters to much, I'm itching to build something.
Reply With Quote
  #2  
Old 06-29-2011, 11:54 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
You can set player strings equal to objects. So if you make a TStaticVar with the stats of your item and then set a player string to that TStaticVar, you can access it constantly without performing any disk read/writes. Then if you want to change values on the object that's in the player's inventory, you can just access the object directly in memory and change it. When the player logs out, save the TStaticVar object to some file or database on the server probably using TGraalVar.savevarstoarray(bool). On login, you can load the object back up using loadvarsfromarray. That way it's only reading/writing on login/logout.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 06-30-2011, 12:04 AM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by Tigairius View Post
You can set player strings equal to objects. So if you make a TStaticVar with the stats of your item and then set a player string to that TStaticVar, you can access it constantly without performing any disk read/writes. Then if you want to change values on the object that's in the player's inventory, you can just access the object directly in memory and change it. When the player logs out, save the TStaticVar object to some file or database on the server probably using TGraalVar.savevarstoarray(bool). On login, you can load the object back up using loadvarsfromarray. That way it's only reading/writing on login/logout.
Have you had much success with SQL on here? I know it's using SQLite, which isn't the greatest, but yeah.
Reply With Quote
  #4  
Old 06-30-2011, 12:08 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
SQLite is one of the most powerful technologies we have at our disposal with GScript2, and almost anything that can be done with SQL can also be done with SQLite when also mixed with a little GScript2. Sure, there is no automated cleanup or date typedefs, but SQLite serves its intended purpose as a quick retrieval database system. I use it extensively in our development on Kingdoms iPhone and it works well.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
Old 06-30-2011, 12:22 AM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by Tigairius View Post
SQLite is one of the most powerful technologies we have at our disposal with GScript2, and almost anything that can be done with SQL can also be done with SQLite when also mixed with a little GScript2. Sure, there is no automated cleanup or date typedefs, but SQLite serves its intended purpose as a quick retrieval database system. I use it extensively in our development on Kingdoms iPhone and it works well.
Well that's good to know. I've heard a lot of other developers outside of this game complain about SQLite for a few reasons. Mainly one being it's inefficiency when with larger amounts of data (due to the whole database being stored in one file, I believe).

But since you speak of success in production, I'll take your word for it.
Reply With Quote
  #6  
Old 06-30-2011, 12:29 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You can easily get away with storing quantities, and item data in clientr flags.

Just cache your base items in a DB/SQL instead of loading a text file with them every time.

I wrote a simple 'Active Record' implementation for GS2:
http://forums.graalonline.com/forums...hp?t=134262561

GS2 is probably fast enough for what you're planning to do anyway.
__________________
Quote:
Reply With Quote
  #7  
Old 06-30-2011, 12:37 AM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by fowlplay4 View Post
You can easily get away with storing quantities, and item data in clientr flags.

Just cache your base items in a DB/SQL instead of loading a text file with them every time.

I wrote a simple 'Active Record' implementation for GS2:
http://forums.graalonline.com/forums...hp?t=134262561

GS2 is probably fast enough for what you're planning to do anyway.
Thanks for the tip.

Migrations. Nice!
Reply With Quote
  #8  
Old 06-30-2011, 09:07 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Some questions to keep in mind as you make an item system:

Quote:
Originally Posted by cbk1994 View Post
Assuming you go with a MUDLIB a few things to keep in mind:
  • Is it going to be a full MUDLIB? In other words, are you going to have it possible to dynamically create new instances of unique items, or are items static and created once, then players have a quantity of that item?
  • How are you going to store the item data? If you go with a full MUDLIB, your best bet is probably text files, but there are also other options like SQL which may work for you. If you go with a non-MUDLIB and just use text files (or other storage) for items, you will need a way to store the amount of items players have (SQL, client flags both work well)
  • Are you going to cache the item database in memory? This improves performance, but is only really possible when not using a full MUDLIB.
  • If you go with a full MUDLIB, how will you handle stacking? For example, if you create 5 platinum coins, these should technically be 5 unique objects, so they can't stack in your inventory.
  • How will you deal with getting item data clientside? Will you send it all on login or send it as needed and store it clientside then?
If you're not going the MUDLIB route and won't be creating objects on-the-fly, keep it simple. Store the item data in human-readable files, and have a script parse these files and store them as TStaticVar objects on serverside in a cache (in memory). Unless you have a ridiculous amount of items this won't use too much memory, and will limit the amount of disk IO you do.
__________________
Reply With Quote
  #9  
Old 06-30-2011, 09:21 AM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
Some questions to keep in mind as you make an item system:



If you're not going the MUDLIB route and won't be creating objects on-the-fly, keep it simple. Store the item data in human-readable files, and have a script parse these files and store them as TStaticVar objects on serverside in a cache (in memory). Unless you have a ridiculous amount of items this won't use too much memory, and will limit the amount of disk IO you do.
Thanks for the response.

Yeah, I'm thinking of going with SQL for persistence since it offers a good structure for what I need. When ever an item is created, it will be cloned (conceptually anyway). This will allow users enhance and improve their items at free will.

I was thinking this:

Players have characters (max of 3, but potentially more).
Amongst other things characters can have many items.

Items have behaviour (probably set up some interface for behaviour)
Items have stats.

Now to get what I want with regards to unique stats, in the cross reference table when I do the many-many between the items and the players, there will be columns which are basically the stats of the item which can be modified from item to item.

Hopefully from the above, you can make out the relationships between the data because, if you're seeing what I'm seeing, you'll see that a trade could be as trivial as changing the appropriate ID in the many-many XR table.

I just don't think flat files will allow me to do this as effectively. The only thing I'm worried about is having a ridiculously rigid DB schema and aiming for supreme flexibility from the get go is a mistake.

In regards to item stacking, that is yet to be thought of but a simple boolean or some rules should do it. I think the boolean should do it but there's probably a better way. I need to do some more thinking on that.
Reply With Quote
  #10  
Old 07-01-2011, 01:31 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
http://forums.graalonline.com/forums...hp?t=134261963
Might be a good read

And what the hell is a MUDlib here on Graal?
For future reference, FOR ALL YOU SCRIPTERS OUT THERE; DO NOT USE THE TERM MUDLIB FOR ITEM SYSTEMS


Quote:
Originally Posted by Skyld View Post
It seems that the average forum user/scripter on Graal has no real concept as to what a "mudlib" really is.


Quote:
Originally Posted by Wikipedia
A mudlib is a library of interpreted code used to create a MUD. It is interpreted code usually written in the LPC language. The code is interpreted on the fly by a driver.
Quote:
Originally Posted by Wikipedia
In computer gaming, a MUD (Multi-User Dungeon, Domain or Dimension) is a multi-player computer game that combines elements of role-playing games, hack and slash style computer games and social chat rooms.
So, please can we stop using the term "mudlib" to describe your scripts?

Basically the trend to use the term MUDlib back in the days was all about File I/O to store information..

Quote:
Originally Posted by Skyld View Post
Can someone please explain to me what advantages a system that reads and writes from text files for all player or item data really has? I find it difficult to believe that, whatever it is, it justifies the:

  • More CPU cycles going to loss to read and write text files when the gserver is already doing this for Database NPC flags or player attributes;
  • Greater memory usage in caching both player flags and even more text data;
  • Files filling up file manager which are just going to turn into a disorganised mess;
  • More layers of scripting that could potentially go wrong and may need debugging, or more things to confuse someone else who has to work with your systems.
This GST doesn't approve.
__________________
Reply With Quote
  #11  
Old 07-01-2011, 01:36 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
By stealing someone elses!
Reply With Quote
  #12  
Old 07-01-2011, 08:09 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
To clarify, when I use the term MUDLIB as I did above, I use it loosely to mean an item system capable of generating new items dynamically (Kingdoms) rather than one with a fixed set of items that can only be added to by staff (Era).
__________________
Reply With Quote
  #13  
Old 07-01-2011, 09:13 AM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
I don't really care for terminology. When I hear MUDlib, I think of telnet but it's not important.The DBNPC approach seems fine for basic uses but there's not much you can do in the way of:
  • Querying the data
  • Organising the data

With SQL, you can express a lot more about what kind of data you want. It's much suited for this sort of thing than GScript, hence why it was invented.

Anyway, thanks for the information Chompy. The enchanting stuff was golden and I feel inspired.
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 01:02 PM.


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