WoR_PRC8/_module/nss/qst_reward_hndlr.nss
Jaysyn904 b5e28e52f4 Initial commit
Initial commit [1.18]
2025-04-03 11:49:34 -04:00

63 lines
2.8 KiB
Plaintext

//Quest Giver Script - Rewards are dynamic based on locally stored variables on the NPC himself.
void main()
{
object oQuestGiver = OBJECT_SELF;
object oPC = GetPCSpeaker();
object oParty = GetFirstFactionMember(oPC);
string sVarName = GetLocalString(oQuestGiver,"QUEST_TAG"); // Set this as a variable on the quest giver in toolset (the variable name that we are checking for - must match the one specified in the monster death script/variable)
string sRewardRef = GetLocalString(oQuestGiver,"QUEST_REWARD"); // Set this as a variable on the quest giver in toolset (rewarded item)
int iRewardGold = GetLocalInt(oQuestGiver,"REWARD_GOLD"); // Set this as a variable on the quest giver in toolset (rewarded gold)
int iRewardXP = GetLocalInt(oQuestGiver,"REWARD_XP"); // Set this as a variable on the quest giver in toolset (rewarded xp)
string sQuestItemTag = GetLocalString(oQuestGiver,"REQUIRED_ITEM"); // Set this as a variable on the quest giver in toolset (item required to complete quest)
string sConversation = GetLocalString(oQuestGiver, "SPEAK_CONV"); // Set this as a string variable on the quest giver in toolset (use the conversation name as the string)
object oItem = GetItemPossessedBy( oPC,sQuestItemTag);
if(oItem == OBJECT_INVALID)
{
//If the player has not got the item, surely we dont want to grant any reward.
ActionStartConversation(oPC, sConversation); // This allows you to stipulate the conversation used
return; // Return statements basically tell the script to exit out of the current itteration of that function. They can also be used to return objects, or data values to another function, but in this instance, we are just using it to exit because the quest object has not been found.
}
//If the script has got this far, it means that the quest object was found.
//Putting this code down here, because we dont want to give the reward item, unless the player has fulfilled the above criteria.
if(GetLocalInt(oPC, sVarName )==1)
{
CreateItemOnObject(sRewardRef , oPC);
}
while(oItem != OBJECT_INVALID)
{
DestroyObject(oItem);
oItem = GetItemPossessedBy( oPC,sQuestItemTag);
}
//After this point, all instances of the quest object will be gone from the players inventory.
while(GetIsObjectValid(oParty))
{
if(GetArea(oPC)==GetArea(oParty))
{
object oDatabase = GetItemPossessedBy(oParty,"Database");
if (GetLocalInt(oDatabase, sVarName)==1)
// if(GetLocalInt(oParty, sVarName ) ==1)
{
GiveGoldToCreature(oParty, iRewardGold );
GiveXPToCreature(oParty,iRewardXP);
SetLocalInt(oParty, sVarName, 0);
}
}
oParty = GetNextFactionMember(oPC);
}
}