A Development Tutorial: Chapter 16: Difference between revisions
No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
There are many ways to do this - this is only one presentation that works, for experimental purposes: | There are many ways to do this - this is only one presentation that works, for experimental purposes:<br> | ||
( | <code class="bbc_code">//<span style="white-space: pre;"> </span>Demo for Timed Event used for repeatable quests.<br>void r_GetQuest(Critter& player, Critter@ npc)<br>{<br><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "r_GetQuest() called");<br><span style="white-space: pre;"> </span>if (isTimedEventAvailable(player, npc))<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>uint[] values = {player.Id, npc.Id};<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>setTimedEventAvailable(player, npc, false);<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>CreateTimeEvent(AFTER(REAL_SECOND(10)), "e_ResetSpawnLocTimer", values, false);<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>r_SpawnLoc(player, npc);<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>else<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "r_GetQuest() - Quest not available yet.");<br><span style="white-space: pre;"> </span>}<br>}<br><br>//<span style="white-space: pre;"> </span>S<br>uint e_ResetSpawnLocTimer(array<uint>@ values)<br>{<br><span style="white-space: pre;"> </span>Critter@ player = GetCritter(values[0]);<br><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "e_ResetSpawnLocTimer()");<br><span style="white-space: pre;"> </span>Critter@ npc = GetCritter(values[1]);<br><span style="white-space: pre;"> </span>setTimedEventAvailable(player, npc, true);<br><span style="white-space: pre;"> </span>return 0;<br>}<br><br>bool setTimedEventAvailable(Critter& player, Critter@ npc, bool isReady)<br>{<br><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "setTimedEventAvailable()");<br><span style="white-space: pre;"> </span>if(!valid(player) || !valid(npc))<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return false;<br><span style="white-space: pre;"> </span>GameVar@ var = GetUnicumVar(UVAR_q_timedEventAvailable, npc.Id, player.Id);<br><span style="white-space: pre;"> </span>if (!valid(var))<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return false;<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>if (isReady)<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>var = 1;<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "setTimedEventAvailable() - 1");<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>else<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "setTimedEventAvailable() - 0");<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>var = 0;<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>return true;<br>}<br><br><br>bool isTimedEventAvailable(Critter& player, Critter@ npc)<br>{<br><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "isTimedEventAvailable()");<br> if(!valid(player) || !valid(npc))<br> return false;<br><span style="white-space: pre;"> </span>GameVar@ var = GetUnicumVar(UVAR_q_timedEventAvailable, npc.Id, player.Id);<br><span style="white-space: pre;"> </span>if (!valid(var))<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return false;<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>if (var == 0)<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "isTimedEventAvailable() == 0");<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return false;<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>else<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "isTimedEventAvailable() == 1");<span style="white-space: pre;"> </span><br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return true;<br><span style="white-space: pre;"> </span>}<br>}<br></code> | ||
[[Category:Guides]] | [[Category:Guides]] |
Revision as of 07:40, 29 January 2017
A Development Tutorial: Chapter 16 | |
---|---|
Get the developer tools and try building new content for this game! | |
Season | {{{season}}} |
Status | Progress Stopped |
Completion | 75% |
Authors | Slowhand |
This Chapter | 16: Repeatable Locations |
More Chapters | Title Page Development Kit Setup Making Maps The World Map Editor NPC Dialogues Create a 2-Map Zone Monsters, Loot, and Scripts Tracking Quest Progress Scenery Scripts Dialogue-to-Quest Location Chapter 10 The Scripting Environment Understanding Quest Scripts Chapter 13 Dialogue: The "SAY" Menu Chapter 15 Lockpick Cooldown Repeatable Locations Floating FA Text Roulette Game Dialogues vs Scripts Simple Kill Quest Chapter 21 Mysterious Stranger Perk Perk Installation Black Jack Game Black Jack Installation Sound Effects |
Notes | {{{notes}}} |
Making a location spawn (for a daily/weekly quest) repeatable with timer.
There will be no Step-by-Step for this one, as all the elements have been shown previously. Rather, I will just explain and link the script. You need to add the source to the same script file as the one we used previously, because it uses some of it's functions. Remove the lines starting with player.Say.. when you put this to production code, they were just used for debug, and for you to see what is happening.
- r_GetQuest(..)
- This function should be called from the dialog, when the NPC gives the quest.
- If the timed even is available, then it will summon the location, but this is a precaution only, the dialog branching should decide this.
- Try and test this, if the timer is not up, it should say in system window that the quest is not available yet.
- e_ResetSpawnLocTimer(..)
- This is an even function which will be called from r_getQuest(..) and is responsible for resetting the timer.
- All this function does, is to call the setTimedEventAvailable(..) function to allow the retaking of the quest.
- setTimedEventAvailable(..)
- Is used to set the Unique variable for this quest timer.
- isTimedEventAvailable(..)
- Check the value of the timer variable.
There are many ways to do this - this is only one presentation that works, for experimental purposes:
// Demo for Timed Event used for repeatable quests.
void r_GetQuest(Critter& player, Critter@ npc)
{
player.Say(SAY_NETMSG, "r_GetQuest() called");
if (isTimedEventAvailable(player, npc))
{
uint[] values = {player.Id, npc.Id};
setTimedEventAvailable(player, npc, false);
CreateTimeEvent(AFTER(REAL_SECOND(10)), "e_ResetSpawnLocTimer", values, false);
r_SpawnLoc(player, npc);
}
else
{
player.Say(SAY_NETMSG, "r_GetQuest() - Quest not available yet.");
}
}
// S
uint e_ResetSpawnLocTimer(array<uint>@ values)
{
Critter@ player = GetCritter(values[0]);
player.Say(SAY_NETMSG, "e_ResetSpawnLocTimer()");
Critter@ npc = GetCritter(values[1]);
setTimedEventAvailable(player, npc, true);
return 0;
}
bool setTimedEventAvailable(Critter& player, Critter@ npc, bool isReady)
{
player.Say(SAY_NETMSG, "setTimedEventAvailable()");
if(!valid(player) || !valid(npc))
return false;
GameVar@ var = GetUnicumVar(UVAR_q_timedEventAvailable, npc.Id, player.Id);
if (!valid(var))
{
return false;
}
if (isReady)
{
var = 1;
player.Say(SAY_NETMSG, "setTimedEventAvailable() - 1");
}
else
{
player.Say(SAY_NETMSG, "setTimedEventAvailable() - 0");
var = 0;
}
return true;
}
bool isTimedEventAvailable(Critter& player, Critter@ npc)
{
player.Say(SAY_NETMSG, "isTimedEventAvailable()");
if(!valid(player) || !valid(npc))
return false;
GameVar@ var = GetUnicumVar(UVAR_q_timedEventAvailable, npc.Id, player.Id);
if (!valid(var))
{
return false;
}
if (var == 0)
{
player.Say(SAY_NETMSG, "isTimedEventAvailable() == 0");
return false;
}
else
{
player.Say(SAY_NETMSG, "isTimedEventAvailable() == 1");
return true;
}
}