...

View Full Version : Randomly generated quests



esperance
07-17-2012, 10:50 PM
Hello,

I'm learning php + mysql and my motivation is to host a browsergame.
There is an ready register- and login-system, a character creation wich calculates the attribute points of the class and race of the characters. thats all till now.

The next thing is to have some fun with quests. There are different types of quests (main quests, daily quest, special quest and so on) so i made two tables for that:
`quests`
`quest_types`

How users do the daylie quests? Thats my problem!

The should be able to choose between three quest. So first i need three quests or more to let the script randomly choose three out of them.
Actually there are six daily quests in the table `quests`.

If we say order by rand() limit 3 every time a user opens the daily quest page, he get three random quests again. thats wrong. he should get three quests once, the he has to finish one of them and the generate three new quests.

additional, i didnt saved any reward in the `quests` table, because this should be caluclated randomly too, based on the characters level.

so can you tell me HOW to get three random quests, WHERE to safe them to show them to the user for ever until he finish one of them and WHEN to calculate the reward (gold and xp) to add it to the `characters` table?

this is so hard for me to do at the moment, pls give me hints.

Len Whistler
07-18-2012, 05:22 AM
so can you tell me HOW to get three random quests, WHERE to safe them to show them to the user for ever until he finish one of them and WHEN to calculate the reward (gold and xp) to add it to the `characters` table?

With cookies or a database. If no cookie is set the user would get the 3 random "quests", which also sets the cookie with that info. If the cookie exists he gets the original quests.

Alternative to the cookies would be to enter the info into a database.


--

esperance
07-26-2012, 02:23 PM
Im still trying to get this quests done, but it seems too hard...

In this function we proof, if there are entries in the table `character_quests`.

If no => generate three of them from `quests` and write them in `character_quests` with additional information like reward, characterID, time.

If yes => display the three quests...



$questID = ;
$questTitle = ;
$questDescription = ;
$characterID = ;
$questMoney = getCharacters('levelID') * rand(1,4);
$questExperience = getCharacters('levelID') * rand(50,200);
$questTime = 150 * rand(1,4);

function listRandomQuests() {
global $db, $characterID;

if(mysqli_query($db, "SELECT count(*) FROM character_quests WHERE characterID = $characterID") > 0) {

$sql = "
SELECT
questName,
questDescription,
questGold,
questExperience,
questTime
FROM
character_quests
WHERE
characterID = $characterID
ORDER BY
questTime ASC
";
$result = $db->query($sql);
$rows = array();

while($row = $result->fetch_object()) {
$rows[] = $row;
}

foreach($rows as $row) {
echo "<div>";
echo "<input id='$row->questName' type='radio' name='randomQuest' value='$row->questName' />";
echo "<label for='$row->questName'>";
echo "<span class='yellow'>$row->questName</span>";
echo "<br />";
echo "$row->questDescription";
echo "</label>";
echo "</div>";
}

} else {

$sql = "
INSERT INTO
character_quests(
questID,
questTitle,
questDescription,
characterID,
questMoney,
questExperience,
questTime
)
VALUES
(
?, ?, ?, ?, ?, ?, ?
)
";

$stmt = $db->prepare($sql);
$stmt->bind_param (
'issiiii',
$questID,
$questTitle,
$questDescription,
$characterID,
$questMoney,
$questExperience,
$questTime
);
$stmt->close();

}
}

What i want to know: Is it possible to do like that, or am i going for the wrong way?!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum