SpiritShard.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. end
  14. function recovershard(NPC, Spawn)
  15. local charid = GetShardCharID(NPC)
  16. if GetCharacterID(Spawn) == charid then
  17. local DebtToRemovePct = GetRuleFlagFloat("R_Combat", "ShardDebtRecoveryPercent")
  18. local DeathXPDebt = GetRuleFlagFloat("R_Combat", "DeathExperienceDebt")
  19. local debt = GetInfoStructFloat(Spawn, "xp_debt")
  20. local DebtToRemove = (DebtToRemovePct/100.0)*(DeathXPDebt/100.0);
  21. if debt > DebtToRemove then
  22. SetInfoStructFloat(Spawn, "xp_debt", debt - DebtToRemove)
  23. else
  24. SetInfoStructFloat(Spawn, "xp_debt", 0.0)
  25. end
  26. PlaySound(Spawn,"sounds/ui/shard_absorb.wav", GetX(NPC), GetY(NPC), GetZ(NPC))
  27. SendMessage(Spawn, "You recover a spirit shard and recovered some experience debt.", "white")
  28. SetCharSheetChanged(Spawn, true)
  29. local shardid = GetShardID(NPC)
  30. DeleteDBShardID(shardid)
  31. Despawn(NPC)
  32. end
  33. end