mirror of
https://github.com/araxiaonline/RandomScriptsforAzerothCore.git
synced 2026-06-13 10:22:22 -04:00
Add files via upload
Was originally intended to fix dynamic issue but still figuring it out. Here's a variation though!
This commit is contained in:
@@ -1,28 +1,54 @@
|
||||
-- Table to store NPC IDs and original levels
|
||||
local npcOrigLevels = {
|
||||
[400013] = 55,
|
||||
[400014] = 56,
|
||||
[68] = 57,
|
||||
[1976] = 58,
|
||||
[466] = 59,
|
||||
--[[
|
||||
This script reduces the level of selected NPCs and adjusts their healthpool accordingly. This is a variation of the other script.
|
||||
]]--
|
||||
|
||||
local npcIds = {
|
||||
-- An array of NPC IDs that will have their level and health adjusted.
|
||||
400013,
|
||||
400014,
|
||||
68,
|
||||
1976,
|
||||
466,
|
||||
}
|
||||
|
||||
-- Function to cast spell ID 100133 on the creature and update its level and health pool
|
||||
local function CastSpellOnSpawn(event, creature)
|
||||
local npcId = creature:GetEntry()
|
||||
local originalLevel = npcOrigLevels[npcId]
|
||||
local newLevel = math.random(25, 30)
|
||||
local levelDifference = originalLevel - newLevel
|
||||
creature:SetLevel(newLevel)
|
||||
-- The function that will be called when an NPC with an ID in npcIds is spawned.
|
||||
|
||||
local originalHealth = creature:GetMaxHealth()
|
||||
local newHealth = originalHealth - (originalHealth * (levelDifference * 0.03))
|
||||
creature:SetMaxHealth(newHealth)
|
||||
creature:SetHealth(newHealth)
|
||||
creature:CastSpell(creature, 100133, true) --teleport visual. This is a custom spell so change it.
|
||||
if not creature then
|
||||
-- Check if a creature was passed to the function.
|
||||
print("Error: creature was not set!")
|
||||
return
|
||||
end
|
||||
|
||||
-- Register the function to be called on creature spawn event for each NPC ID
|
||||
for npcId, originalLevel in pairs(npcOrigLevels) do
|
||||
RegisterCreatureEvent(npcId, 5, CastSpellOnSpawn)
|
||||
end
|
||||
local originalLevel = creature:GetLevel()
|
||||
-- Get the original level of the spawned NPC.
|
||||
|
||||
local randomLevel = math.random(originalLevel - 34, originalLevel -30)
|
||||
-- Choose a random level between the original level minus 34 and minus 30.
|
||||
|
||||
local levelDiff = originalLevel - randomLevel
|
||||
-- Calculate the difference between the original level and the new, random level.
|
||||
|
||||
creature:SetLevel(randomLevel)
|
||||
-- Set the NPC's level to the random level.
|
||||
|
||||
creature:SetMaxHealth(creature:GetMaxHealth() * (1 - levelDiff * 0.03))
|
||||
-- Adjust the NPC's healthpool by reducing it by 3% for each level difference.
|
||||
|
||||
creature:SetHealth(creature:GetMaxHealth())
|
||||
-- Set the NPC's current health to its maximum health.
|
||||
|
||||
creature:CastSpell(creature, 100133, true)
|
||||
-- Cast the teleport visual spell on the NPC.
|
||||
end
|
||||
|
||||
for _, npcId in ipairs(npcIds) do
|
||||
-- Loop through all the NPC IDs in the npcIds array.
|
||||
|
||||
RegisterCreatureEvent(npcId, 5, CastSpellOnSpawn)
|
||||
-- Register the CastSpellOnSpawn function to be called when an NPC with the current ID is spawned.
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user