This is somewhat noobish, but I really can't figure this out.
I created a database entry in the character table that inserts strings into a field. Whenever you start a quest or progress in a quest it adds another string so that I can check for that on the next part of the quest. So, my problem.
For adding strings/checking it would be:
Code:
user.quests += "sss";
if (user.quests.contains("sss")
but I realize that running multiple if statements checking for values in this on an npc won't work, as it can only run one if-statement with a certain value and several strings will still be in the database that it has checked for before, so I have to have a way of removing or replacing it.
I tried:
Code:
user.quests -=(which doesn't work for strings), user.quest.remove("sss") // doesnt do anything
user.quest.replace("sss", "aaa") // doesn't do anything either.
.replace could probably work if i deleted text from a certain index(), but that wont work as people wont do the quests in the same order, so I cant set it to a certain index without it being replaced at some point.
Any ideas? At the moment I can only add strings to it, but not remove.
I cannot think of any more inefficient way to handle it to be honest (not to be rude... just a fact)
String comparisons are quite costly operations and scale horrendously poorly (might be 'acceptable' with a user having 5 quests but what if they have 100?)
A more scalable system would be a quests table following a structure somewhere along the line of...
PlayerID
QuestID
var1
var2
var3
CompletionEnum
That way you can do something like
SELECT * FROM QUESTS WHERE PlayerID=X AND CompletionEnum=Active
UPDATE QUESTS var1=mobKills WHERE PlayerID=X
Simple updates like that.
You then can do a QuestType table which links quest id to further information (times available, description, rewards, etc).
Break tables into their most simple yet functional format is generally the right course of action.
I do appreciate the feedback, but I wasn't actually going to use this. I was doing this solely for learning. So I'd still like to have an answer from anyone who can bother.
All of the string logic (adding new quests, removing old quests, checking if quest exists) should be done source side and the database value should only be referenced when loading the character and when saving to the database (when user logs out or server shuts down)
Keep in mind that such a string system is not only more computationally expensive the longer the string is (more characters to check) but you're also required to give quests a unique name.
EG:
QuestString = "PheasantHunting1PheasantHunting10"
These are two stages to one quest (lets assume you have 10 quests. just an example) but using
if(user.QuestString.Conatains("PheasantHunting1") will return quest even if you do not current have the first stage of the quest because PheasantHunting10 contains the string PheasantHunting1.
shouldnt you be using a enumeration like pro says. its cheaper for the CPU to process and its easier to handle...
Code:
Switch (user.Quest)
{
case UserQuest.PheasantHunting:
{
//code block here
break;
}
}
public enum UserQuest
{
None=0,
PheasantHunting=1,
DragonHunting=2
//etc etc
}
and if you want to store it into the database as a string for easy reading you could do
reading:
Code:
var datareader = new DataReader("SELECT quest FROM QUESTS WHERE PlayerID=X AND CompletionEnum=Active")
user.Quest = (UserQuest)Enum.parse(datareader["Quest"],typeof(UserQuest);
writing
Code:
sql.execute(string.format("Update Quests Set Quest='{0}' where PlayerID={1}",user.Quest.ToString(),User.ID);
Something like that
and in the database the value for PlayerID XXX should be the Enum Name.. i.e PheasantHunting
if you wanted each quest type to have different steps.. like stage1, stage2, stage 3 have another
[REQUEST]/[RELEASE] Database Game.exe Editing 07/30/2011 - Shaiya - 3 Replies First off want to point out the rules
Do you need Shaiya Hacks, Bots, Cheats or anything else?
Take a look here
Ok So this is not a Question it is a Request.
Also for This
I won't post a question or other non-releases in this forum.
Database strings 07/17/2011 - Rappelz - 7 Replies I got a question about strings stored in the database. I was trying to insert new places into the teleport npcs and also tried to correct those "empty string" shop npcs, that are in the latest server release.
First lets start off with the teleporter.
I edited "NPC Teleport Town (2455194ffb3cb3515526cb9e195a8371).lua"
and inserted new location in the Asura Katan teleporter. I tried these 4:
dlg_menu( "@90700000", 'RunTeleport( 100000 , 219257 , 15681 )' ) --Lost Mine 1
dlg_menu(...
[Help] account mysql database 07/03/2009 - CO2 Private Server - 2 Replies i was wondering if anyone could help me i have tq binarys database jsut curious
Account Table= 8146
Char Table=4448
how do i delete the 4k unused accounts?
[HELP] MySql Database 12/09/2008 - CO2 Private Server - 0 Replies Mysql database keeps giving an error:
PHPMYADMIN ERROR, The server isn't reacting.
What should i do lol, i've re-installed it like 3 times still doesn't work. Hm...
Ciao!
'' MySQL database '' 11/10/2008 - Conquer Online 2 - 8 Replies How do i let my friend connect to my MYSQL database so he can also be a hoster and create accounts.
Any 1 idea's post em here
Regards Memos ,