132 lines
3.3 KiB
Plaintext
132 lines
3.3 KiB
Plaintext
#include "mn_i_pwfunctions"
|
|
|
|
void GiveLoot();
|
|
|
|
void GiveLootToPlayer(object oPC, string sLootResRef, string sQuestId = "")
|
|
{
|
|
if (sQuestId != "")
|
|
{
|
|
// TODO Check if quest is completed, if so, return
|
|
if(CheckQuestStatus(oPC, sQuestId, QUEST_COMPLETED))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
CreateItemOnObject(sLootResRef, oPC);
|
|
}
|
|
|
|
void GiveGoldHelper(object oKiller, int iGold, int bRewardEntireParty = FALSE)
|
|
{
|
|
if (iGold <1)
|
|
{
|
|
return;
|
|
}
|
|
if (bRewardEntireParty)
|
|
{
|
|
// Get the first faction member in the PC's party (PC-only)
|
|
object oPartyMember = GetFirstFactionMember(oKiller, TRUE);
|
|
while (GetIsObjectValid(oPartyMember))
|
|
{
|
|
if (GetArea(oKiller) == GetArea(oPartyMember))
|
|
{
|
|
GiveGoldToCreature(oPartyMember, iGold);
|
|
}
|
|
// Get the next faction member in the PC's party (PC-only)
|
|
oPartyMember = GetNextFactionMember(oKiller, TRUE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Only reward the player
|
|
GiveGoldToCreature(oKiller, iGold);
|
|
}
|
|
}
|
|
|
|
void GiveLootHelper(object oKiller, string sLootResRef, int iDropChance = 100, int bRewardEntireParty = FALSE, string sQuestId = "")
|
|
{
|
|
if (sLootResRef == "")
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (iDropChance == 0)
|
|
{
|
|
iDropChance = 100;
|
|
}
|
|
int check = d100();
|
|
if (check>iDropChance)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (bRewardEntireParty)
|
|
{
|
|
// Get the first faction member in the PC's party (PC-only)
|
|
object oPartyMember = GetFirstFactionMember(oKiller, TRUE);
|
|
while (GetIsObjectValid(oPartyMember))
|
|
{
|
|
if (GetArea(oKiller) == GetArea(oPartyMember))
|
|
{
|
|
GiveLootToPlayer(oPartyMember, sLootResRef, sQuestId);
|
|
}
|
|
// Get the next faction member in the PC's party (PC-only)
|
|
oPartyMember = GetNextFactionMember(oKiller, TRUE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Only reward the player
|
|
GiveLootToPlayer(oKiller, sLootResRef, sQuestId);
|
|
}
|
|
}
|
|
|
|
void GiveLoot()
|
|
{
|
|
object oKilled = OBJECT_SELF;
|
|
int iLootGold = GetLocalInt(oKilled, "LOOT_GOLD");
|
|
int bRewardEntireParty = GetLocalInt(oKilled, "LOOT_REWARD_PARTY");
|
|
|
|
string sLootResRef = GetLocalString(oKilled, "LOOT_ITEM_RESREF_1");
|
|
if (sLootResRef == "")
|
|
{
|
|
return;
|
|
}
|
|
|
|
object oKiller = GetLastKiller();
|
|
|
|
// Find top level master
|
|
while (GetIsObjectValid(GetMaster(oKiller)))
|
|
{
|
|
oKiller = GetMaster(oKiller);
|
|
}
|
|
|
|
// Check if PC
|
|
if (GetIsPC(oKiller))
|
|
{
|
|
// Give gold
|
|
GiveGoldHelper(oKiller, iLootGold, bRewardEntireParty);
|
|
|
|
// Give first item
|
|
string sQuestId = GetLocalString(oKilled, "LOOT_ITEM_QUEST_1");
|
|
int iDropChance = GetLocalInt(oKilled, "LOOT_ITEM_CHANCE_1");
|
|
GiveLootHelper(oKiller, sLootResRef, iDropChance, bRewardEntireParty, sQuestId);
|
|
|
|
// Give remaining items
|
|
int count;
|
|
for (count = 2; count<10; count++)
|
|
{
|
|
string countStr = IntToString(count);
|
|
sLootResRef = GetLocalString(oKilled, "LOOT_ITEM_RESREF_"+countStr);
|
|
if (sLootResRef == "")
|
|
{
|
|
break; // Exit loop
|
|
}
|
|
string sQuestId = GetLocalString(oKilled, "LOOT_ITEM_QUEST_"+countStr);
|
|
int iDropChance = GetLocalInt(oKilled, "LOOT_ITEM_CHANCE_"+countStr);
|
|
GiveLootHelper(oKiller, sLootResRef, iDropChance, bRewardEntireParty, sQuestId);
|
|
}
|
|
}
|
|
}
|
|
|
|
//void main(){}
|