Journal & quest persistence
Journal & quest persistence
This commit is contained in:
@@ -5,14 +5,20 @@
|
||||
//:: Created By: Script Wizard
|
||||
//:: Created On: 9/1/2005 3:40:56 PM
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
#include "nw_i0_tool"
|
||||
|
||||
void main()
|
||||
{
|
||||
// Give the speaker some XP
|
||||
RewardPartyXP(2000, GetPCSpeaker());
|
||||
//:: Give the speaker some XP
|
||||
RewardPartyXP(2000, GetPCSpeaker());
|
||||
|
||||
//:: Give the speaker the items
|
||||
CreateItemOnObject("nw_it_gem005", GetPCSpeaker(), 1);
|
||||
|
||||
//:: Set Quest stage & update DB.
|
||||
AddPersistentJournalQuestEntry("husband", 3, GetPCSpeaker());
|
||||
|
||||
// Give the speaker the items
|
||||
CreateItemOnObject("nw_it_gem005", GetPCSpeaker(), 1);
|
||||
|
||||
}
|
||||
|
@@ -5,11 +5,17 @@
|
||||
//:: Created By: Script Wizard
|
||||
//:: Created On: 9/1/2005 3:44:44 PM
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
#include "nw_i0_tool"
|
||||
|
||||
void main()
|
||||
{
|
||||
// Give the speaker some XP
|
||||
RewardPartyXP(50, GetPCSpeaker());
|
||||
|
||||
//:: Give the speaker some XP
|
||||
RewardPartyXP(50, GetPCSpeaker());
|
||||
|
||||
//:: Set Quest stage & update DB.
|
||||
AddPersistentJournalQuestEntry("husband", 3, GetPCSpeaker());
|
||||
|
||||
}
|
||||
|
@@ -5,14 +5,19 @@
|
||||
//:: Created By: Script Wizard
|
||||
//:: Created On: 9/1/2005 5:07:09 PM
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
#include "nw_i0_tool"
|
||||
|
||||
void main()
|
||||
{
|
||||
// Give the speaker some gold
|
||||
GiveGoldToCreature(GetPCSpeaker(), 10000);
|
||||
//:: Give the speaker some gold
|
||||
GiveGoldToCreature(GetPCSpeaker(), 10000);
|
||||
|
||||
// Give the speaker some XP
|
||||
RewardPartyXP(3000, GetPCSpeaker());
|
||||
//:: Give the speaker some XP
|
||||
RewardPartyXP(3000, GetPCSpeaker());
|
||||
|
||||
//:: Finish he quest, update the DB
|
||||
AddJournalQuestEntry("NW_JOURNAL_ENTRYkupra", 2, GetPCSpeaker());
|
||||
|
||||
}
|
||||
|
@@ -5,9 +5,15 @@
|
||||
//:: Created By: Script Wizard
|
||||
//:: Created On: 9/2/2005 2:54:24 AM
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
void main()
|
||||
{
|
||||
// Give the speaker the items
|
||||
CreateItemOnObject("scrollofteleport", GetPCSpeaker(), 1);
|
||||
//:: Set the Quest state
|
||||
AddJournalQuestEntry("NW_JOURNAL_ENTRYkupra", 1, GetPCSpeaker());
|
||||
|
||||
//:: Give the speaker the items
|
||||
CreateItemOnObject("scrollofteleport", GetPCSpeaker(), 1);
|
||||
|
||||
}
|
||||
|
@@ -7,10 +7,10 @@
|
||||
//:://////////////////////////////////////////////
|
||||
void main()
|
||||
{
|
||||
// Give the speaker some gold
|
||||
GiveGoldToCreature(GetPCSpeaker(), 2700);
|
||||
// Give the speaker some gold
|
||||
GiveGoldToCreature(GetPCSpeaker(), 1000);
|
||||
|
||||
// Give the speaker some XP
|
||||
GiveXPToCreature(GetPCSpeaker(), 3000);
|
||||
// Give the speaker some XP
|
||||
GiveXPToCreature(GetPCSpeaker(), 3000);
|
||||
|
||||
}
|
||||
|
@@ -25,4 +25,7 @@ oTarget = oPC;
|
||||
|
||||
AssignCommand(oCaster, ActionCastSpellAtObject(SPELL_FIREBALL, oTarget, METAMAGIC_ANY, TRUE, 6, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
|
||||
|
||||
//:: Grants Experiance to Killer
|
||||
ExecuteScript("pwfxp", OBJECT_SELF);
|
||||
|
||||
}
|
||||
|
@@ -1,17 +1,27 @@
|
||||
/* Script generated by
|
||||
Lilac Soul's NWN Script Generator, v. 2.1
|
||||
//::///////////////////////////////////////////////
|
||||
//:: jchusb1.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
For download info, please visit:
|
||||
http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625 */
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
int nInt;
|
||||
nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
//nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
|
||||
if (nInt >= 1)
|
||||
nInt = RetrieveQuestState("husband", oPC);
|
||||
|
||||
if (nInt = 1)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
28
_module/nss/jchusb2.nss
Normal file
28
_module/nss/jchusb2.nss
Normal file
@@ -0,0 +1,28 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: jchusb2.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
int nInt;
|
||||
//nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
|
||||
nInt = RetrieveQuestState("husband", oPC);
|
||||
|
||||
if (nInt = 2)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
@@ -1,15 +1,24 @@
|
||||
/* Script generated by
|
||||
Lilac Soul's NWN Script Generator, v. 2.1
|
||||
//::///////////////////////////////////////////////
|
||||
//:: jchusband.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
For download info, please visit:
|
||||
http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625 */
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
int nInt;
|
||||
nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
//nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
nInt = RetrieveQuestState("husband", oPC);
|
||||
|
||||
if (nInt >= 1)
|
||||
return FALSE;
|
||||
|
@@ -1,15 +1,24 @@
|
||||
/* Script generated by
|
||||
Lilac Soul's NWN Script Generator, v. 2.1
|
||||
//::///////////////////////////////////////////////
|
||||
//:: jchusband2.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
For download info, please visit:
|
||||
http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625 */
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
int nInt;
|
||||
nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
//nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
nInt = RetrieveQuestState("husband", oPC);
|
||||
|
||||
if (nInt >= 2)
|
||||
return TRUE;
|
||||
|
27
_module/nss/jchusband3.nss
Normal file
27
_module/nss/jchusband3.nss
Normal file
@@ -0,0 +1,27 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: jchusband3.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
int nInt;
|
||||
//nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYhusband");
|
||||
nInt = RetrieveQuestState("husband", oPC);
|
||||
|
||||
if (nInt >= 3)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
@@ -1,15 +1,25 @@
|
||||
/* Script generated by
|
||||
Lilac Soul's NWN Script Generator, v. 2.1
|
||||
//::///////////////////////////////////////////////
|
||||
//:: jckupra1.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
For download info, please visit:
|
||||
http://nwvault.ign.com/View.php?view=Other.Detail&id=4683&id=625 */
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
|
||||
int nInt;
|
||||
nInt=GetLocalInt(oPC, "NW_JOURNAL_ENTRYkupra");
|
||||
// nInt = GetLocalInt(oPC, "NW_JOURNAL_ENTRYkupra");
|
||||
nInt = RetrieveQuestState("NW_JOURNAL_ENTRYkupra", oPC);
|
||||
|
||||
if (nInt >= 1)
|
||||
return FALSE;
|
||||
|
@@ -1,23 +1,23 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: x2_con-chp1or2n1
|
||||
//:: Copyright (c) 2003 Bioware Corp.
|
||||
//:: npcrecognew.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
First time talked to in either Chapter 1 or
|
||||
Chapter 2.
|
||||
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Brent
|
||||
//:: Created On:
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
// * first time spoken to
|
||||
if (GetLocalInt(OBJECT_SELF,"NW_L_TALKTIMES") == 0)
|
||||
{
|
||||
return TRUE;
|
||||
object oPC = GetPCSpeaker();
|
||||
//:: first time spoken to
|
||||
if (GetLocalInt(oPC,"Spoke2Greeter") == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@@ -1,19 +1,26 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: x2_con_notfirst
|
||||
//:: Copyright (c) 2003 Bioware Corp.
|
||||
//:: npcrecgnknows.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
Returns true if this is not the first time
|
||||
you've spoken to this character
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By:
|
||||
//:: Created On:
|
||||
/*
|
||||
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
int StartingConditional()
|
||||
{
|
||||
if (GetLocalInt(OBJECT_SELF,"NW_L_TALKTIMES") > 0)
|
||||
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
if (GetLocalInt(oPC,"Spoke2Greeter") > 0)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
245
_module/nss/pqj_inc.nss
Normal file
245
_module/nss/pqj_inc.nss
Normal file
@@ -0,0 +1,245 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: Persistent Quests & Journal Entries / Beta
|
||||
//:: pqj_inc
|
||||
//:: Copyright (c) 2001 Bioware Corp.
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
|
||||
Persistent Quests and Journal Entries
|
||||
|
||||
This is a compact set of scripts (4 public functions, 2 private functions) to help you get
|
||||
a persistent journal and to generally manage quests without much overhead.
|
||||
|
||||
it works like this:
|
||||
|
||||
you prepare your journal in the toolbox, assigning proper tags/ids, then you normally use
|
||||
AddJournalQuestEntry() and RemoveJournalQuestEntry() to manage them via scripting.
|
||||
|
||||
now, you just have to use AddPersistentJournalQuestEntry() and RemovePersistentJournalQuestEntry()
|
||||
with exact the same parameters (bAllPlayer, bAllPartyMembers and bAllowOverrideHigher still work like
|
||||
in the original bioware functions). this means no restrictions, it's fully transparent.
|
||||
|
||||
now add the following line of code to your Module OnClientEnter script (don't forget to include this script):
|
||||
RebuildJournalQuestEntries(GetEnteringObject());
|
||||
|
||||
that's all, now you have a persistent journal... you can basically use CTRL-R to find/replace the
|
||||
original functions with the persistent ones and add the OnClientEnter code.
|
||||
|
||||
furthermore, you can use RetrieveQuestState() to get the current state of a
|
||||
quest for the specified player/quest-tag. this means you can manage your conversations with
|
||||
this function and control quest-flow. you won't need to store additional LocalInts somewhere, just
|
||||
use the DB information.
|
||||
|
||||
technical blabla:
|
||||
|
||||
minimized DB usage: stores all quest states in a single string
|
||||
|
||||
i'm using a combo of tokenized + padded string to get maximum parsing efficiency.
|
||||
tokenized: i can find & change a single quest entry with only a few string commands
|
||||
padded: i can browse through a large string (100+ quest entries) with minimal need of string manipulation
|
||||
so this won't slow down your server during journal rebuilds even with tons of quests
|
||||
|
||||
this is beta code and pretty much un-optimized ..still needs some bug hunting
|
||||
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Knat
|
||||
//:: Created On: 19.06.2003
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
// database filename
|
||||
const string PQJ_DATABASE = "JOURNALS";
|
||||
// database fieldname
|
||||
const string PQJ_PLAYER_VARNAME = "QUESTJOURNAL";
|
||||
|
||||
// transparent wrapper to AddJournalQuestEntry
|
||||
// use this function instead of the original one to store quest/journal data
|
||||
// persistently using the bio DB. all function parameters work similar to the original function
|
||||
//
|
||||
// Add a journal quest entry to oCreature.
|
||||
// - szPlotID: the plot identifier used in the toolset's Journal Editor
|
||||
// - nState: the state of the plot as seen in the toolset's Journal Editor
|
||||
// - oCreature
|
||||
// - bAllPartyMembers: If this is TRUE, the entry will show up in the journal of
|
||||
// everyone in the party
|
||||
// - bAllPlayers: If this is TRUE, the entry will show up in the journal of
|
||||
// everyone in the world
|
||||
// - bAllowOverrideHigher: If this is TRUE, you can set the state to a lower
|
||||
// number than the one it is currently on
|
||||
void AddPersistentJournalQuestEntry(string szPlotID, int nState, object oCreature, int bAllPartyMembers=TRUE, int bAllPlayers=FALSE, int bAllowOverrideHigher=FALSE);
|
||||
|
||||
// transparent wrapper to RemoveJournalQuestEntry()
|
||||
// use this function instead of the original one to remove quest/journal data
|
||||
// persistently using the bio DB. all function parameters work similar to the original function
|
||||
//
|
||||
// Remove a journal quest entry from oCreature.
|
||||
// - szPlotID: the plot identifier used in the toolset's Journal Editor
|
||||
// - oCreature
|
||||
// - bAllPartyMembers: If this is TRUE, the entry will be removed from the
|
||||
// journal of everyone in the party
|
||||
// - bAllPlayers: If this is TRUE, the entry will be removed from the journal of
|
||||
// everyone in the world
|
||||
void RemovePersistentJournalQuestEntry(string szPlotID, object oCreature, int bAllPartyMembers=TRUE, int bAllPlayers=FALSE);
|
||||
|
||||
// use this function to rebuild the journal on oCreature using the bio DB
|
||||
// a good place is the Module OnClientEnter() event
|
||||
void RebuildJournalQuestEntries(object oCreature);
|
||||
|
||||
// retrieve persistent quest state from the DB
|
||||
// - szPlotID: the plot identifier used in the toolset's Journal Editor
|
||||
int RetrieveQuestState(string szPlotID, object oCreature);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void RebuildJournalQuestEntries(object oCreature)
|
||||
{
|
||||
if(GetIsPC(oCreature))
|
||||
{
|
||||
string sEntries = GetCampaignString(PQJ_DATABASE,PQJ_PLAYER_VARNAME,oCreature);
|
||||
int i, nCount = GetStringLength(sEntries) / 44;
|
||||
|
||||
string sQuest;
|
||||
for(i=0;i < nCount;i++)
|
||||
{
|
||||
// get quest
|
||||
sQuest = GetSubString(sEntries,(i*44),32);
|
||||
// remove padding
|
||||
sQuest = GetStringLeft(sQuest, FindSubString(sQuest, " "));
|
||||
// add journal entry
|
||||
AddJournalQuestEntry(sQuest, StringToInt(GetSubString(sEntries,(i*44) + 33,8)), oCreature, FALSE, FALSE, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int RetrieveQuestState(string szPlotID, object oCreature)
|
||||
{
|
||||
// retrieve all quest entries
|
||||
string sEntries = GetCampaignString(PQJ_DATABASE,PQJ_PLAYER_VARNAME,oCreature);
|
||||
// get quest we search for and add padding
|
||||
string sQuest = (GetStringLength(szPlotID) < 32) ? szPlotID + GetStringLeft(" ",32 - GetStringLength(szPlotID)) : GetStringLeft(szPlotID,32);
|
||||
|
||||
// find target quest
|
||||
int nPos = FindSubString(sEntries, sQuest + ">");
|
||||
|
||||
if( nPos != -1) // success ?? get & return value
|
||||
return StringToInt(GetStringLeft(GetStringRight(sEntries,GetStringLength(sEntries)-nPos-GetStringLength(sQuest)-1),10));
|
||||
|
||||
// quest not started yet
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StoreQuestEntry(string szPlotID, int nState, object oCreature, int bAllowOverrideHigher=FALSE)
|
||||
{
|
||||
// retrieve all quest entries
|
||||
string sEntries = GetCampaignString(PQJ_DATABASE,PQJ_PLAYER_VARNAME,oCreature);
|
||||
|
||||
// pad quest
|
||||
string sQuest = (GetStringLength(szPlotID) < 32) ? szPlotID + GetStringLeft(" ",32 - GetStringLength(szPlotID)) : GetStringLeft(szPlotID,32);
|
||||
// pad state
|
||||
string sState = IntToString(nState);
|
||||
sState = (GetStringLength(sState) < 10) ? sState + GetStringLeft(" ",10 - GetStringLength(sState)) : GetStringLeft(sState,10);
|
||||
|
||||
// find target quest
|
||||
int nPos = FindSubString(sEntries, sQuest + ">");
|
||||
|
||||
if( nPos != -1) // success ?
|
||||
{
|
||||
|
||||
// check for override flag
|
||||
if(!bAllowOverrideHigher) // new state < old state ? return
|
||||
if(nState < StringToInt(GetStringRight(sEntries,GetStringLength(sEntries)-nPos-GetStringLength(sQuest)-1)))
|
||||
return;
|
||||
|
||||
// replace old quest state with new one
|
||||
string sL = GetStringLeft(sEntries, nPos + GetStringLength(sQuest) + 1);
|
||||
sEntries = sL + sState + GetStringRight(sEntries, GetStringLength(sEntries) - GetStringLength(sL) - 10);
|
||||
}
|
||||
else // add quest
|
||||
sEntries += sQuest + ">" + sState + "|";
|
||||
|
||||
// store quest entries
|
||||
SetCampaignString(PQJ_DATABASE,PQJ_PLAYER_VARNAME,sEntries,oCreature);
|
||||
}
|
||||
|
||||
void DeleteQuestEntry(string szPlotID, object oCreature)
|
||||
{
|
||||
// retrieve all quest entries
|
||||
string sEntries = GetCampaignString(PQJ_DATABASE,PQJ_PLAYER_VARNAME,oCreature);
|
||||
// pad quest
|
||||
string sQuest = (GetStringLength(szPlotID) < 32) ? szPlotID + GetStringLeft(" ",32 - GetStringLength(szPlotID)) : GetStringLeft(szPlotID,32);
|
||||
// find target quest
|
||||
int nPos = FindSubString(sEntries, sQuest + ">");
|
||||
|
||||
if( nPos != -1) // success ?
|
||||
{
|
||||
|
||||
// replace old quest state with new one
|
||||
string sL = GetStringLeft(sEntries, nPos);
|
||||
sEntries = sL + GetStringRight(sEntries, GetStringLength(sEntries) - GetStringLength(sL) - 44);
|
||||
|
||||
// store quest entries
|
||||
SetCampaignString(PQJ_DATABASE,PQJ_PLAYER_VARNAME,sEntries,oCreature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RemovePersistentJournalQuestEntry(string szPlotID, object oCreature, int bAllPartyMembers=TRUE, int bAllPlayers=FALSE)
|
||||
{
|
||||
RemoveJournalQuestEntry(szPlotID, oCreature, bAllPartyMembers, bAllPlayers);
|
||||
// store data
|
||||
if(bAllPlayers)
|
||||
{
|
||||
// all players
|
||||
object oPC = GetFirstPC();
|
||||
while(GetIsObjectValid(oPC))
|
||||
{
|
||||
if(GetIsPC(oPC)) DeleteQuestEntry(szPlotID, oPC);
|
||||
oPC = GetNextPC();
|
||||
}
|
||||
}
|
||||
else if(bAllPartyMembers)
|
||||
{
|
||||
// whole group
|
||||
object oPartyMember = GetFirstFactionMember(oCreature, TRUE);
|
||||
while (GetIsObjectValid(oPartyMember))
|
||||
{
|
||||
DeleteQuestEntry(szPlotID, oPartyMember);
|
||||
oPartyMember = GetNextFactionMember(oCreature, TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// player only
|
||||
DeleteQuestEntry(szPlotID, oCreature);
|
||||
}
|
||||
}
|
||||
|
||||
void AddPersistentJournalQuestEntry(string szPlotID, int nState, object oCreature, int bAllPartyMembers=TRUE, int bAllPlayers=FALSE, int bAllowOverrideHigher=FALSE)
|
||||
{
|
||||
AddJournalQuestEntry(szPlotID, nState, oCreature, bAllPartyMembers, bAllPlayers, bAllowOverrideHigher);
|
||||
// store data
|
||||
if(bAllPlayers)
|
||||
{
|
||||
// all players
|
||||
object oPC = GetFirstPC();
|
||||
while(GetIsObjectValid(oPC))
|
||||
{
|
||||
if(GetIsPC(oPC)) StoreQuestEntry(szPlotID, nState, oPC, bAllowOverrideHigher);
|
||||
oPC = GetNextPC();
|
||||
}
|
||||
}
|
||||
else if(bAllPartyMembers)
|
||||
{
|
||||
//SendMessageToPC(oCreature, "PARTY");
|
||||
object oPartyMember = GetFirstFactionMember(oCreature, TRUE);
|
||||
while (GetIsObjectValid(oPartyMember))
|
||||
{
|
||||
StoreQuestEntry(szPlotID, nState, oPartyMember, bAllowOverrideHigher);
|
||||
oPartyMember = GetNextFactionMember(oCreature, TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StoreQuestEntry(szPlotID, nState, oCreature, bAllowOverrideHigher);
|
||||
}
|
||||
}
|
25
_module/nss/qst_losthubby01.nss
Normal file
25
_module/nss/qst_losthubby01.nss
Normal file
@@ -0,0 +1,25 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: qst_losthubby01.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
Set quest stage 1 for the Lost Husband quest
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
void main()
|
||||
{
|
||||
//:: Declare Major variables
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
//:: Set Quest stage & update DB.
|
||||
AddPersistentJournalQuestEntry("husband", 1, oPC);
|
||||
|
||||
//SetPersistantLocalInt(oPC, "husband", 1);
|
||||
|
||||
}
|
23
_module/nss/qst_losthubby02.nss
Normal file
23
_module/nss/qst_losthubby02.nss
Normal file
@@ -0,0 +1,23 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: qst_losthubby02.nss
|
||||
//:: Copyright (c) 2022 Rappan Athuk
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
Set quest stage 2 for the Lost Husband quest
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
void main()
|
||||
{
|
||||
//:: Declare Major Variables
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
//:: Set Quest stage & update DB.
|
||||
AddPersistentJournalQuestEntry("husband", 2, oPC);
|
||||
|
||||
}
|
23
_module/nss/ra_greet_new_pc.nss
Normal file
23
_module/nss/ra_greet_new_pc.nss
Normal file
@@ -0,0 +1,23 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//::
|
||||
//:: ra_greet_new_pc
|
||||
//:: Copyright (c) 2022 Project RATDOG
|
||||
//::
|
||||
//::
|
||||
//:://////////////////////////////////////////////
|
||||
//::
|
||||
//:: PC has had the "newbie" convo & free money
|
||||
//::
|
||||
//:://////////////////////////////////////////////
|
||||
//::
|
||||
//:: Created By: Jaysyn
|
||||
//:: Created On: 20220617
|
||||
//::
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
void main()
|
||||
{
|
||||
object oPC = GetPCSpeaker();
|
||||
|
||||
SetLocalInt(oPC,"Spoke2Greeter",GetLocalInt(oPC,"Spoke2Greeter") + 1);
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
#include "journal_include"
|
||||
//#include "journal_include"
|
||||
#include "pqj_inc"
|
||||
|
||||
void GivePCWands(object oPC)
|
||||
{
|
||||
@@ -125,9 +126,11 @@ void GiveLangTokens(object oPC)
|
||||
|
||||
void main()
|
||||
{
|
||||
//:: Set Major Variables
|
||||
object oPC = GetEnteringObject();
|
||||
|
||||
dhLoadJournalQuestStates(GetEnteringObject());
|
||||
|
||||
//:: Restore jounral entries
|
||||
RebuildJournalQuestEntries(GetEnteringObject());
|
||||
|
||||
// Make sure PC isn't set to Plot, for reasons
|
||||
SetPlotFlag(oPC, FALSE);
|
||||
|
@@ -1,4 +1,6 @@
|
||||
|
||||
#include "pqj_inc"
|
||||
|
||||
//Checks to see if the player has been in the current area and
|
||||
//if they have not, sends description and awards XP.
|
||||
//oPC = Player nReveal: 1 = Reveals whole map - 0 = Does not - 2 Hides Map
|
||||
@@ -23,7 +25,7 @@ void PlayerExplore(object oPC, int nReveal)
|
||||
if (sArea == "ALT_ALTARUK")//THE VARIABLE USED IS THE TAG OF THE AREA
|
||||
{
|
||||
//EDIT THE XP GIVEN AND JOURNAL ENTRY ID NUMBER TO SUIT
|
||||
AddJournalQuestEntry("Exploring Athas", 1, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
AddPersistentJournalQuestEntry("Exploring Athas", 1, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
GiveXPToCreature(oPC, 20);//DEFAULT IS 10 XP
|
||||
SetCampaignInt("Exploring Athas", sArea, 1, oPC);//DO NOT CHANGE THIS NUMBER
|
||||
return;
|
||||
@@ -32,7 +34,7 @@ void PlayerExplore(object oPC, int nReveal)
|
||||
if (sArea == "KLED_VILLAGE")//THE VARIABLE USED IS THE TAG OF THE AREA
|
||||
{
|
||||
//EDIT THE XP GIVEN AND JOURNAL ENTRY ID NUMBER TO SUIT
|
||||
AddJournalQuestEntry("Exploring Athas", 2, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
AddPersistentJournalQuestEntry("Exploring Athas", 2, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
GiveXPToCreature(oPC, 20);//DEFAULT IS 10 XP
|
||||
SetCampaignInt("Exploring Athas", sArea, 1, oPC);//DO NOT CHANGE THIS NUMBER
|
||||
return;
|
||||
@@ -41,7 +43,7 @@ void PlayerExplore(object oPC, int nReveal)
|
||||
if (sArea == "TYR_CARAVANWAY")//THE VARIABLE USED IS THE TAG OF THE AREA
|
||||
{
|
||||
//EDIT THE XP GIVEN AND JOURNAL ENTRY ID NUMBER TO SUIT
|
||||
AddJournalQuestEntry("Exploring Athas", 3, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
AddPersistentJournalQuestEntry("Exploring Athas", 3, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
GiveXPToCreature(oPC, 10);//DEFAULT IS 10 XP
|
||||
SetCampaignInt("Exploring Athas", sArea, 1, oPC);//DO NOT CHANGE THIS NUMBER
|
||||
return;
|
||||
@@ -50,7 +52,7 @@ void PlayerExplore(object oPC, int nReveal)
|
||||
if (sArea == "URIK_OBSIDGATE")//THE VARIABLE USED IS THE TAG OF THE AREA
|
||||
{
|
||||
//EDIT THE XP GIVEN AND JOURNAL ENTRY ID NUMBER TO SUIT
|
||||
AddJournalQuestEntry("Exploring Athas", 4, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
AddPersistentJournalQuestEntry("Exploring Athas", 4, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
GiveXPToCreature(oPC, 30);//DEFAULT IS 10 XP
|
||||
SetCampaignInt("Exploring Athas", sArea, 1, oPC);//DO NOT CHANGE THIS NUMBER
|
||||
return;
|
||||
@@ -59,7 +61,7 @@ void PlayerExplore(object oPC, int nReveal)
|
||||
if (sArea == "SilverSpringsOasis")//THE VARIABLE USED IS THE TAG OF THE AREA
|
||||
{
|
||||
//EDIT THE XP GIVEN AND JOURNAL ENTRY ID NUMBER TO SUIT
|
||||
AddJournalQuestEntry("Exploring Athas", 5, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
AddPersistentJournalQuestEntry("Exploring Athas", 5, oPC, FALSE, FALSE);//ONLY CHANGE THE ID NUMBER
|
||||
GiveXPToCreature(oPC, 40);//DEFAULT IS 10 XP
|
||||
SetCampaignInt("Exploring Athas", sArea, 1, oPC);//DO NOT CHANGE THIS NUMBER
|
||||
return;
|
||||
|
689
_module/nss/utl_i_sqlplayer.nss
Normal file
689
_module/nss/utl_i_sqlplayer.nss
Normal file
@@ -0,0 +1,689 @@
|
||||
//::///////////////////////////////////////////////
|
||||
//:: Utility Include: SQLocalsPlayer
|
||||
//:: utl_i_sqlplayer.nss
|
||||
//:://////////////////////////////////////////////
|
||||
/*
|
||||
Daz wrote these library functions to act as replacements for the usual local
|
||||
functions:
|
||||
* GetLocalInt / SetLocalInt / DeleteLocalInt
|
||||
* GetLocalFloat / SetLocalFloat / DeleteLocalFloat
|
||||
* GetLocalString / SetLocalString / DeleteLocalString
|
||||
* GetLocalObject / SetLocalObject / DeleteLocalObject (NB: remember these are references NOT serialised objects)
|
||||
* GetLocalLocation / SetLocalLocation / DeleteLocalLocation
|
||||
* Plus a new function for saving just a vector by itself.
|
||||
|
||||
Since sometimes iterating over many locals is slow, this might be an excellent way to
|
||||
speed up large amounts of access, or for debugging, or using regex or whatever else.
|
||||
|
||||
These are functions for PC Object persistence only. See utl_i_sqlocals.nss for
|
||||
the module saved version.
|
||||
*/
|
||||
//:://////////////////////////////////////////////
|
||||
//:: Based off of the nwscript_utility_scripts project; see for dates/creator info
|
||||
//:: https://github.com/Finaldeath/nwscript_utility_scripts
|
||||
//:://////////////////////////////////////////////
|
||||
|
||||
const string SQLOCALSPLAYER_TABLE_NAME = "sqlocalsplayer_table";
|
||||
|
||||
const int SQLOCALSPLAYER_TYPE_ALL = 0;
|
||||
const int SQLOCALSPLAYER_TYPE_INT = 1;
|
||||
const int SQLOCALSPLAYER_TYPE_FLOAT = 2;
|
||||
const int SQLOCALSPLAYER_TYPE_STRING = 4;
|
||||
const int SQLOCALSPLAYER_TYPE_OBJECT = 8;
|
||||
const int SQLOCALSPLAYER_TYPE_VECTOR = 16;
|
||||
const int SQLOCALSPLAYER_TYPE_LOCATION = 32;
|
||||
|
||||
// Returns an integer stored on oPlayer, or 0 on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
int SQLocalsPlayer_GetInt(object oPlayer, string sVarName);
|
||||
// Sets an integer stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nValue - Value to store
|
||||
void SQLocalsPlayer_SetInt(object oPlayer, string sVarName, int nValue);
|
||||
// Deletes an integer stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteInt(object oPlayer, string sVarName);
|
||||
|
||||
// Returns a float stored on oPlayer, or 0.0 on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
float SQLocalsPlayer_GetFloat(object oPlayer, string sVarName);
|
||||
// Sets a float stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * fValue - Value to store
|
||||
void SQLocalsPlayer_SetFloat(object oPlayer, string sVarName, float fValue);
|
||||
// Deletes a float stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteFloat(object oPlayer, string sVarName);
|
||||
|
||||
// Returns an string stored on oPlayer, or "" on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
string SQLocalsPlayer_GetString(object oPlayer, string sVarName);
|
||||
// Sets a string stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * sValue - Value to store
|
||||
void SQLocalsPlayer_SetString(object oPlayer, string sVarName, string sValue);
|
||||
// Deletes a string stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteString(object oPlayer, string sVarName);
|
||||
|
||||
// Returns an object identifier stored on oPlayer
|
||||
// If this is used on a player it might return a "once valid" OID, so check
|
||||
// with GetIsObjectValid, do not compare to OBJECT_INVALID.
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
object SQLocalsPlayer_GetObject(object oPlayer, string sVarName);
|
||||
// Sets an object identifier stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * oValue - Value to store
|
||||
void SQLocalsPlayer_SetObject(object oPlayer, string sVarName, object oValue);
|
||||
// Deletes an object identifier stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteObject(object oPlayer, string sVarName);
|
||||
|
||||
// Returns a vector stored on oPlayer, or [0.0, 0.0, 0.0] on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
vector SQLocalsPlayer_GetVector(object oPlayer, string sVarName);
|
||||
// Sets a vector stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * vValue - Value to store
|
||||
void SQLocalsPlayer_SetVector(object oPlayer, string sVarName, vector vValue);
|
||||
// Deletes a vector stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteVector(object oPlayer, string sVarName);
|
||||
|
||||
// Returns a location stored on oPlayer, or the starting location of the module on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
location SQLocalsPlayer_GetLocation(object oPlayer, string sVarName);
|
||||
// Sets a location stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * lValue - Value to store
|
||||
void SQLocalsPlayer_SetLocation(object oPlayer, string sVarName, location lValue);
|
||||
// Deletes a location stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteLocation(object oPlayer, string sVarName);
|
||||
|
||||
// Deletes a set of locals stored on oPlayer matching the given criteria
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to remove (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
// * sLike - The string to compare with the SQL "like" comparison
|
||||
// * sEscape - The escape character to use with the SQL "escape" keyword
|
||||
void SQLocalsPlayer_Delete(object oPlayer, int nType = SQLOCALSPLAYER_TYPE_ALL, string sLike = "", string sEscape = "");
|
||||
// Counts a set of locals stored on oPlayer matching the given criteria
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to count (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
// * sLike - The string to compare with the SQL "like" comparison
|
||||
// * sEscape - The escape character to use with the SQL "escape" keyword
|
||||
int SQLocalsPlayer_Count(object oPlayer, int nType = SQLOCALSPLAYER_TYPE_ALL, string sLike = "", string sEscape = "");
|
||||
// Checks a locals stored on oPlayer is set
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to check
|
||||
int SQLocalsPlayer_IsSet(object oPlayer, string sVarName, int nType);
|
||||
// Returns the last Unix time the given variable was updated
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to check
|
||||
int SQLocalsPlayer_GetLastUpdated_UnixEpoch(object oPlayer, string sVarName, int nType);
|
||||
// Returns the last UTC time the given variable was updated
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to check
|
||||
string SQLocalsPlayer_GetLastUpdated_UTC(object oPlayer, string sVarName, int nType);
|
||||
|
||||
|
||||
/* INTERNAL */
|
||||
void SQLocalsPlayer_CreateTable(object oPlayer)
|
||||
{
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"CREATE TABLE IF NOT EXISTS " + SQLOCALSPLAYER_TABLE_NAME + " (" +
|
||||
"type INTEGER, " +
|
||||
"varname TEXT, " +
|
||||
"value TEXT, " +
|
||||
"timestamp INTEGER, " +
|
||||
"PRIMARY KEY(type, varname));");
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
sqlquery SQLocalsPlayer_PrepareSelect(object oPlayer, int nType, string sVarName)
|
||||
{
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT value FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE type = @type AND varname = @varname;");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@varname", sVarName);
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
sqlquery SQLocalsPlayer_PrepareInsert(object oPlayer, int nType, string sVarName)
|
||||
{
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"INSERT INTO " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"(type, varname, value, timestamp) VALUES (@type, @varname, @value, strftime('%s','now')) " +
|
||||
"ON CONFLICT (type, varname) DO UPDATE SET value = @value, timestamp = strftime('%s','now');");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@varname", sVarName);
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
sqlquery SQLocalsPlayer_PrepareDelete(object oPlayer, int nType, string sVarName)
|
||||
{
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"DELETE FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE type = @type AND varname = @varname;");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@varname", sVarName);
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
string SQLocalsPlayer_LocationToString(location locLocation)
|
||||
{
|
||||
string sAreaId = ObjectToString(GetAreaFromLocation(locLocation));
|
||||
vector vPosition = GetPositionFromLocation(locLocation);
|
||||
float fFacing = GetFacingFromLocation(locLocation);
|
||||
|
||||
return "#A#" + sAreaId +
|
||||
"#X#" + FloatToString(vPosition.x, 0, 5) +
|
||||
"#Y#" + FloatToString(vPosition.y, 0, 5) +
|
||||
"#Z#" + FloatToString(vPosition.z, 0, 5) +
|
||||
"#F#" + FloatToString(fFacing, 0, 5) + "#";
|
||||
}
|
||||
|
||||
location SQLocalsPlayer_StringToLocation(string sLocation)
|
||||
{
|
||||
location locLocation;
|
||||
|
||||
int nLength = GetStringLength(sLocation);
|
||||
|
||||
if(nLength > 0)
|
||||
{
|
||||
int nPos, nCount;
|
||||
|
||||
nPos = FindSubString(sLocation, "#A#") + 3;
|
||||
nCount = FindSubString(GetSubString(sLocation, nPos, nLength - nPos), "#");
|
||||
object oArea = StringToObject(GetSubString(sLocation, nPos, nCount));
|
||||
|
||||
nPos = FindSubString(sLocation, "#X#") + 3;
|
||||
nCount = FindSubString(GetSubString(sLocation, nPos, nLength - nPos), "#");
|
||||
float fX = StringToFloat(GetSubString(sLocation, nPos, nCount));
|
||||
|
||||
nPos = FindSubString(sLocation, "#Y#") + 3;
|
||||
nCount = FindSubString(GetSubString(sLocation, nPos, nLength - nPos), "#");
|
||||
float fY = StringToFloat(GetSubString(sLocation, nPos, nCount));
|
||||
|
||||
nPos = FindSubString(sLocation, "#Z#") + 3;
|
||||
nCount = FindSubString(GetSubString(sLocation, nPos, nLength - nPos), "#");
|
||||
float fZ = StringToFloat(GetSubString(sLocation, nPos, nCount));
|
||||
|
||||
vector vPosition = Vector(fX, fY, fZ);
|
||||
|
||||
nPos = FindSubString(sLocation, "#F#") + 3;
|
||||
nCount = FindSubString(GetSubString(sLocation, nPos, nLength - nPos), "#");
|
||||
float fOrientation = StringToFloat(GetSubString(sLocation, nPos, nCount));
|
||||
|
||||
if (GetIsObjectValid(oArea))
|
||||
locLocation = Location(oArea, vPosition, fOrientation);
|
||||
else
|
||||
locLocation = GetStartingLocation();
|
||||
}
|
||||
|
||||
return locLocation;
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* INT */
|
||||
|
||||
// Returns an integer stored on oPlayer, or 0 on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
int SQLocalsPlayer_GetInt(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return 0;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareSelect(oPlayer, SQLOCALSPLAYER_TYPE_INT, sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetInt(sql, 0);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Sets an integer stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nValue - Value to store
|
||||
void SQLocalsPlayer_SetInt(object oPlayer, string sVarName, int nValue)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareInsert(oPlayer, SQLOCALSPLAYER_TYPE_INT, sVarName);
|
||||
SqlBindInt(sql, "@value", nValue);
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Deletes an integer stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteInt(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareDelete(oPlayer, SQLOCALSPLAYER_TYPE_INT, sVarName);
|
||||
SqlStep(sql);
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* FLOAT */
|
||||
|
||||
// Returns a float stored on oPlayer, or 0.0 on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
float SQLocalsPlayer_GetFloat(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return 0.0f;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareSelect(oPlayer, SQLOCALSPLAYER_TYPE_FLOAT, sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetFloat(sql, 0);
|
||||
else
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Sets a float stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * fValue - Value to store
|
||||
void SQLocalsPlayer_SetFloat(object oPlayer, string sVarName, float fValue)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareInsert(oPlayer, SQLOCALSPLAYER_TYPE_FLOAT, sVarName);
|
||||
SqlBindFloat(sql, "@value", fValue);
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Deletes a float stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteFloat(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareDelete(oPlayer, SQLOCALSPLAYER_TYPE_FLOAT, sVarName);
|
||||
SqlStep(sql);
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* STRING */
|
||||
|
||||
// Returns an string stored on oPlayer, or "" on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
string SQLocalsPlayer_GetString(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return "";
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareSelect(oPlayer, SQLOCALSPLAYER_TYPE_STRING, sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetString(sql, 0);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
// Sets a string stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * sValue - Value to store
|
||||
void SQLocalsPlayer_SetString(object oPlayer, string sVarName, string sValue)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareInsert(oPlayer, SQLOCALSPLAYER_TYPE_STRING, sVarName);
|
||||
SqlBindString(sql, "@value", sValue);
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Deletes a string stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteString(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareDelete(oPlayer, SQLOCALSPLAYER_TYPE_STRING, sVarName);
|
||||
SqlStep(sql);
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* OBJECT */
|
||||
|
||||
|
||||
// Returns an object identifier stored on oPlayer
|
||||
// If this is used on a player it might return a "once valid" OID, so check
|
||||
// with GetIsObjectValid, do not compare to OBJECT_INVALID.
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
object SQLocalsPlayer_GetObject(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return OBJECT_INVALID;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareSelect(oPlayer, SQLOCALSPLAYER_TYPE_OBJECT, sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return StringToObject(SqlGetString(sql, 0));
|
||||
else
|
||||
return OBJECT_INVALID;
|
||||
}
|
||||
|
||||
// Sets an object identifier stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * oValue - Value to store
|
||||
void SQLocalsPlayer_SetObject(object oPlayer, string sVarName, object oValue)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareInsert(oPlayer, SQLOCALSPLAYER_TYPE_OBJECT, sVarName);
|
||||
SqlBindString(sql, "@value", ObjectToString(oValue));
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Deletes an object identifier stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteObject(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareDelete(oPlayer, SQLOCALSPLAYER_TYPE_OBJECT, sVarName);
|
||||
SqlStep(sql);
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* VECTOR */
|
||||
|
||||
// Returns a vector stored on oPlayer, or [0.0, 0.0, 0.0] on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
vector SQLocalsPlayer_GetVector(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return [0.0f, 0.0f, 0.0f];
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareSelect(oPlayer, SQLOCALSPLAYER_TYPE_VECTOR, sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetVector(sql, 0);
|
||||
else
|
||||
return [0.0f, 0.0f, 0.0f];
|
||||
}
|
||||
|
||||
// Sets a vector stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * vValue - Value to store
|
||||
void SQLocalsPlayer_SetVector(object oPlayer, string sVarName, vector vValue)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareInsert(oPlayer, SQLOCALSPLAYER_TYPE_VECTOR, sVarName);
|
||||
SqlBindVector(sql, "@value", vValue);
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Deletes a vector stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteVector(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareDelete(oPlayer, SQLOCALSPLAYER_TYPE_VECTOR, sVarName);
|
||||
SqlStep(sql);
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* LOCATION */
|
||||
|
||||
// Returns a location stored on oPlayer, or the starting location of the module on error
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
location SQLocalsPlayer_GetLocation(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return GetStartingLocation();
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareSelect(oPlayer, SQLOCALSPLAYER_TYPE_LOCATION, sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SQLocalsPlayer_StringToLocation(SqlGetString(sql, 0));
|
||||
else
|
||||
return GetStartingLocation();
|
||||
}
|
||||
|
||||
// Sets a location stored on oPlayer to the given value
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * lValue - Value to store
|
||||
void SQLocalsPlayer_SetLocation(object oPlayer, string sVarName, location lValue)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareInsert(oPlayer, SQLOCALSPLAYER_TYPE_LOCATION, sVarName);
|
||||
SqlBindString(sql, "@value", SQLocalsPlayer_LocationToString(lValue));
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Deletes a location stored on oPlayer
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to delete
|
||||
void SQLocalsPlayer_DeleteLocation(object oPlayer, string sVarName)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || sVarName == "") return;
|
||||
|
||||
sqlquery sql = SQLocalsPlayer_PrepareDelete(oPlayer, SQLOCALSPLAYER_TYPE_LOCATION, sVarName);
|
||||
SqlStep(sql);
|
||||
}
|
||||
/* **** */
|
||||
|
||||
/* UTILITY */
|
||||
|
||||
// Deletes a set of locals stored on oPlayer matching the given criteria
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to remove (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
// * sLike - The string to compare with the SQL "like" comparison
|
||||
// * sEscape - The escape character to use with the SQL "escape" keyword
|
||||
// Note if it is TYPE_ALL and sLike is "" then it will delete all values
|
||||
void SQLocalsPlayer_Delete(object oPlayer, int nType = SQLOCALSPLAYER_TYPE_ALL, string sLike = "", string sEscape = "")
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || nType < 0) return;
|
||||
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql;
|
||||
if(nType == SQLOCALSPLAYER_TYPE_ALL && sLike == "")
|
||||
{
|
||||
sql = SqlPrepareQueryObject(oPlayer,
|
||||
"DELETE FROM " + SQLOCALSPLAYER_TABLE_NAME + ";");
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = SqlPrepareQueryObject(oPlayer,
|
||||
"DELETE FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE TRUE " +
|
||||
(nType != SQLOCALSPLAYER_TYPE_ALL ? "AND type & @type " : " ") +
|
||||
(sLike != "" ? "AND varname LIKE @like " + (sEscape != "" ? "ESCAPE @escape" : "") : "") +
|
||||
";");
|
||||
|
||||
|
||||
if (nType != SQLOCALSPLAYER_TYPE_ALL)
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
if (sLike != "")
|
||||
{
|
||||
SqlBindString(sql, "@like", sLike);
|
||||
|
||||
if (sEscape != "")
|
||||
SqlBindString(sql, "@escape", sEscape);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SqlStep(sql);
|
||||
}
|
||||
|
||||
// Counts a set of locals stored on oPlayer matching the given criteria
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to count (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
// * sLike - The string to compare with the SQL "like" comparison
|
||||
// * sEscape - The escape character to use with the SQL "escape" keyword
|
||||
int SQLocalsPlayer_Count(object oPlayer, int nType = SQLOCALSPLAYER_TYPE_ALL, string sLike = "", string sEscape = "")
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || nType < 0) return 0;
|
||||
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql;
|
||||
if(nType == SQLOCALSPLAYER_TYPE_ALL && sLike == "")
|
||||
{
|
||||
sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT COUNT(*) FROM " + SQLOCALSPLAYER_TABLE_NAME + ";");
|
||||
}
|
||||
else if(nType != SQLOCALSPLAYER_TYPE_ALL && sLike == "")
|
||||
{
|
||||
sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT COUNT(*) FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE type & @type;");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
}
|
||||
else if(nType == SQLOCALSPLAYER_TYPE_ALL && sLike != "")
|
||||
{
|
||||
sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT COUNT(*) FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"varname LIKE @like " + (sEscape != "" ? "ESCAPE @escape" : "") +
|
||||
";");
|
||||
|
||||
SqlBindString(sql, "@like", sLike);
|
||||
|
||||
if (sEscape != "")
|
||||
SqlBindString(sql, "@escape", sEscape);
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT COUNT(*) FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE type & @type " +
|
||||
"AND varname LIKE @like " + (sEscape != "" ? "ESCAPE @escape" : "") +
|
||||
";");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@like", sLike);
|
||||
|
||||
if (sEscape != "")
|
||||
SqlBindString(sql, "@escape", sEscape);
|
||||
}
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetInt(sql, 0);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Checks a locals stored on oPlayer is set
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to check (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
int SQLocalsPlayer_IsSet(object oPlayer, string sVarName, int nType)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || nType < 0) return 0;
|
||||
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT * FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE AND varname = @varname" +
|
||||
(nType != SQLOCALSPLAYER_TYPE_ALL ? "AND type & @type " : " ") +
|
||||
";");
|
||||
|
||||
if (nType != SQLOCALSPLAYER_TYPE_ALL)
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@varname", sVarName);
|
||||
|
||||
return SqlStep(sql);
|
||||
}
|
||||
|
||||
// Returns the last Unix time the given variable was updated
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to check (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
int SQLocalsPlayer_GetLastUpdated_UnixEpoch(object oPlayer, string sVarName, int nType)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || nType <= 0) return 0;
|
||||
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT timestamp FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE type = @type " +
|
||||
"AND varname = @varname;");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@varname", sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetInt(sql, 0);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Returns the last UTC time the given variable was updated
|
||||
// * oPlayer - a player object to save the variable on
|
||||
// * sVarName - name of the variable to retrieve
|
||||
// * nType - The SQLOCALSPLAYER_TYPE_* you wish to check (default: SQLOCALSPLAYER_TYPE_ALL)
|
||||
string SQLocalsPlayer_GetLastUpdated_UTC(object oPlayer, string sVarName, int nType)
|
||||
{
|
||||
if (!GetIsPC(oPlayer) || nType <= 0) return "";
|
||||
|
||||
SQLocalsPlayer_CreateTable(oPlayer);
|
||||
|
||||
sqlquery sql = SqlPrepareQueryObject(oPlayer,
|
||||
"SELECT datetime(timestamp, 'unixepoch') FROM " + SQLOCALSPLAYER_TABLE_NAME + " " +
|
||||
"WHERE type = @type " +
|
||||
"AND varname = @varname;");
|
||||
|
||||
SqlBindInt(sql, "@type", nType);
|
||||
SqlBindString(sql, "@varname", sVarName);
|
||||
|
||||
if (SqlStep(sql))
|
||||
return SqlGetString(sql, 0);
|
||||
else
|
||||
return "";
|
||||
}
|
Reference in New Issue
Block a user