Heal.lua

Discussions on development of both the EQ2Emulator LUA Script Engine and Script specifications

Moderator: Team Members

Post Reply
User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Heal.lua

Post by alfa » Mon Oct 20, 2008 6:41 pm

Maybe I'm wrong but there is a problem on Heal.lua

Code: Select all

function cast(Caster, Target, PowerCost, HealAmount)
  power_left = GetPower(Caster)
  if (power_left >= PowerCost) then
    SetMaxHP(Target,HealAmount)
  end
end
Should be
For a heal

Code: Select all

function cast(Caster, Target, PowerCost, MinHealAmount, MaxHealAmount)
  power_left = GetPower(Caster)
  if (power_left >= PowerCost) then
    HealAmount = math.random(MinHealAmount, MaxHealAmount)
    SetCurrentHP(Target,(GetCurrentHP(Target) + HealAmount))
  end
end
For a Max HP increase buff

Code: Select all

function cast(Caster, Target, PowerCost, HealthIncAmount)
  power_left = GetPower(Caster)
  if (power_left >= PowerCost) then
    SetMaxHP(Target,(GetMaxHP(Target) + HealthIncAmount))
  end
end
Sorry if I have totaly wrong with the heal.lua, and not sure it is possible to add number with "+"
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."

User avatar
Scatman
Retired
Posts: 1688
Joined: Wed Apr 16, 2008 5:44 am
EQ2Emu Server: Scatman's Word
Characters: Scatman
Location: New Jersey

Post by Scatman » Mon Oct 20, 2008 10:07 pm

No you're right. I don't actually think we're using Heal.lua atm. There is actually a LUA function that lets you modify the current HP called ModifyHP(modifyAmount) that could be used instead of SetMaxHP or SetCurrentHP.

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Post by John Adams » Fri Dec 12, 2008 8:29 pm

Couple things; you do not have to calculate available power, because I believe the World does that before you can even cast the spell - then it takes away power expended. If there is a specific need to subtract even more power, then yes do it in the LUA. Otherwise you shouldn't have to.
All "parameters" are sent from the `spell_data` table. So if you have 3 params in your LUA that you plan to use, set up 3 parameters in spell_data (index_field 0, 1 and 2) with the proper data types you plan to use in the script. In these examples below, you will see 3 - 6 params used. If you need clarification on what the spell_data looks like, just ask.
Here are a couple Heal related scripts I have been using - both seem to work rather well.
Direct Heal:

Code: Select all

--[[
	Script Name	: Heal (Spell Type)
	Script Purpose	: Generic script for healing spells
	Script Author	: John Adams
	Script Date	: 2008.12.03
	Script Note	: 
--]]
function cast(Caster, Target, HealType, HealMinVal, HealMaxVal)
	-- Heal Component
	if HealMinVal < HealMaxVal then
		ModifyHP(Caster, math.random(HealMinVal, HealMaxVal))
	else
		ModifyHP(Caster, HealMinVal)
	end
end
A HoT spell:

Code: Select all

--[[
	Script Name	: HoT (Spell Type)
	Script Purpose	: Generic script for heal-over-time spells
	Script Author	: John Adams
	Script Date	: 2008.12.04
	Script Notes	: JA: Need to determine if HoT's land instantly with the initial heal, or wait til tick()
--]]
function cast(Caster, Target, HealType, HealMinVal, HealMaxVal, HOTType, HOTMinVal, HOTMaxVal)
	-- Heal component
	if HealMinVal < HealMaxVal then
		ModifyHP(Caster, math.random(HealMinVal, HealMaxVal))
	else
		ModifyHP(Caster, HealMinVal)
	end
	-- HoT component
	if HOTType ~= nil then
		-- Determine if there is a range to HoT values
		if HOTMaxVal ~= nil and HOTMinVal < HOTMaxVal then
			ModifyHP(Caster, math.random(HOTMinVal, HOTMaxVal))
		else
			ModifyHP(Caster, HOTMinVal)
		end
	end
end
function tick(Caster, Target, HealType, HealMinVal, HealMaxVal, HOTType, HOTMinVal, HOTMaxVal)
	if HOTMaxVal ~= nil and HOTMinVal < HOTMaxVal then
		ModifyHP(Caster, math.random(HOTMinVal, HOTMaxVal))
	else
		ModifyHP(Caster, HOTMinVal)
	end
end
function remove(Caster, Target)
	-- code to remove the spell
end
And a complete heal (beta heal for testers):

Code: Select all

--[[
	Script Name	: betaheal.lua
	Script Purpose	: Fast / High healing for Beta testers
	Script Author	: John Adams
	Script Date	: 2008.12.03
	Script Note	: This heal has an instand heal + HoT
--]]
function cast(Caster, Target, HealType, HealMinVal, HealMaxVal, EffectType, EffectMinVal, EffectMaxVal)
	if HealType == "complete" then
		ModifyHP(Caster, GetMaxHP(Target))
	else
		if HealMaxVal ~= nil and HealMinVal < HealMaxVal then
			ModifyHP(Caster, math.random(HealMinVal, HealMaxVal))
		else
			ModifyHP(Caster, HealMinVal)
		end
	end
	if EffectType ~= nil then
		if EffectType == "hot" then
			if EffectMaxVal ~= nil and EffectMinVal < EffectMaxVal then
				ModifyHP(Caster, math.random(EffectMinVal, EffectMaxVal))
			else
				ModifyHP(Caster, EffectMinVal)
			end
		end
	end
end
function tick(Caster, Target, HealType, HealMinVal, HealMaxVal, EffectType, EffectMinVal, EffectMaxVal)
	if EffectType ~= nil then
		if EffectType == "hot" then
			if EffectMaxVal ~= nil and EffectMinVal < EffectMaxVal then
				ModifyHP(Caster, math.random(EffectMinVal, EffectMaxVal))
			else
				ModifyHP(Caster, EffectMinVal)
			end
		end
	end
end
You can see how flexible the system is. Scatman was kind enough to add functionality for the "sac"-type heals too, that cause the caster to lose HP to give to another... just set the param for `hp_req` in spell_tiers to achieve that effect.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests