SpiritShard.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --[[
  2. Script Name : SpawnScripts/Generic/SpiritShard.lua
  3. Script Purpose : Spirit Shard
  4. --]]
  5. function spawn(NPC)
  6. local DebtToRemovePct = GetRuleFlagFloat("R_Combat", "ShardDebtRecoveryPercent")
  7. if GetRuleFlagBool("R_Combat", "ShardRecoveryByRadius") == true then
  8. SetPlayerProximityFunction(NPC, 10.0, "recovershard")
  9. end
  10. AddPrimaryEntityCommand(nil,NPC,"Recover Spirit Shard",10.0,"recovershard","",0,0,1)
  11. local charID = GetShardCharID(NPC)
  12. SetAccessToEntityCommandByCharID(NPC, charID, "recovershard", true)
  13. CheckShardExpired(NPC) -- update 4/22/2023 to remove long standing shards
  14. end
  15. function recovershard(NPC, Spawn)
  16. local charid = GetShardCharID(NPC)
  17. if GetCharacterID(Spawn) == charid then
  18. local DebtToRemovePct = GetRuleFlagFloat("R_Combat", "ShardDebtRecoveryPercent")
  19. local DeathXPDebt = GetRuleFlagFloat("R_Combat", "DeathExperienceDebt")
  20. local debt = GetInfoStructFloat(Spawn, "xp_debt")
  21. local DebtToRemove = (DebtToRemovePct/100.0)*(DeathXPDebt/100.0);
  22. if debt > DebtToRemove then
  23. SetInfoStructFloat(Spawn, "xp_debt", debt - DebtToRemove)
  24. else
  25. SetInfoStructFloat(Spawn, "xp_debt", 0.0)
  26. end
  27. PlaySound(Spawn,"sounds/ui/shard_absorb.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  28. SendMessage(Spawn, "You recover a spirit shard and recovered some experience debt.", "white")
  29. SetCharSheetChanged(Spawn, true)
  30. local shardid = GetShardID(NPC)
  31. DeleteDBShardID(shardid)
  32. Despawn(NPC)
  33. end
  34. end
  35. function CheckShardExpired(NPC)
  36. local creationStamp = GetShardCreatedTimestamp(NPC)
  37. local year_ = math.floor(string.sub(creationStamp, 0, 4))
  38. local month_ = math.floor(string.sub(creationStamp, 5, 6))
  39. local day_ = math.floor(string.sub(creationStamp, 7, 8))
  40. local hour_ = math.floor(string.sub(creationStamp, 9, 10))
  41. local min_ = math.floor(string.sub(creationStamp, 11, 12))
  42. local sec_ = math.floor(string.sub(creationStamp, 13, 14))
  43. local currentUTCTime = os.time(os.date('!*t'))
  44. local creationTime = os.time{year=year_, month=month_, day=day_, hour=hour_, min=min_,sec=sec_}
  45. local resultDiff = currentUTCTime - creationTime;
  46. local shardLifeTime = GetRuleFlagFloat("R_Combat", "ShardLifetime")
  47. if shardLifeTime > 0 and resultDiff > shardLifeTime then
  48. local shardid = GetShardID(NPC)
  49. DeleteDBShardID(shardid) -- you could alternatively choose to not delete from DB, but for now it only holds XP debt recovery not items
  50. Despawn(NPC)
  51. end
  52. end