LUA Needs (a list)

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

Moderator: Team Members

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:

Re: LUA Needs (a list)

Post by John Adams » Thu Nov 21, 2013 10:22 pm

How does that tell me it is a Bow?

User avatar
thefoof
Retired
Posts: 630
Joined: Wed Nov 07, 2012 7:36 pm
Location: Florida

Re: LUA Needs (a list)

Post by thefoof » Thu Nov 21, 2013 10:44 pm

I'll make a function to return item type from an item pointer, will that work for you?

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: LUA Needs (a list)

Post by Jabantiz » Thu Nov 21, 2013 10:49 pm

Sorry sleep deprived, figured just grab the range slot but I guess other items could be in that slot...

We will need a new function to determine item type, either a bunch of IsBow(), IsBag(), and so on, or a GetItemType() that returns an int for the item type.

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:

Re: LUA Needs (a list)

Post by John Adams » Fri Nov 22, 2013 3:48 pm

Here's another one. I looked through the LuaFunctions.cpp functions and didn't see anything specific to telling LUA that the Caster (or target?) just got damaged or blocked (maybe other types?)
When damaged this spell has a 50% chance to cast Holding the Line on target's attacker.
-- Increases Threat to target by 27

On a block this spell will cast Holding the Line on target's victim.
-- Increases Threat to target by 27
I'm a little confused by their terminology, so maybe I'm reading this wrong. I see this as, I cast this spell on an NPC, then when the NPC gets damaged, 50% chance of hate towards whomever the NPC currently has targeted (which may not be me?) Doesn't seem very Guardian-like...

OR, if the NPC block's an incoming hit, a 100% chance of that hate towards the NPCs "victim" now, not it's target?


I think the description is poorly written, and it's really about me casting a spell, if I get damaged or block the incoming hit, hate is generated either by chance or certainly.

User avatar
thefoof
Retired
Posts: 630
Joined: Wed Nov 07, 2012 7:36 pm
Location: Florida

Re: LUA Needs (a list)

Post by thefoof » Fri Nov 22, 2013 3:54 pm

The target of that spell is self though, it's a buff. When the target of the spell (the guardian) is attacked there's a 50% chance to increase hate to targets attacker (npc) or on a block it's a 100% chance. But this should probably not be handled through the spell script and instead added on as a proc. Which we don't have yet.

How we will end up handling this in script is probably something like AddProc(proc_type, chance, spell_id) and RemoveProc() when the spell is removed, but I couldn't tell you that for sure because it's not coded yet :wink:

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:

Re: LUA Needs (a list)

Post by John Adams » Fri Nov 22, 2013 4:42 pm

I guess that is why I am adding to this list :)

I forgot to check the Self thing, and that makes much more sense. Thanks.

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:

Re: LUA Needs (a list)

Post by John Adams » Fri Nov 22, 2013 9:57 pm

Question, this is one of the first LUA scripts ever written, back in 2008... wondering, does this still need to be this complex? LUA has changed so much.

Sprint

Code: Select all

function cast(Caster, Target, PowerCost, SpeedValue)
	power_left = GetPower(Caster)
	total_power = GetMaxPower(Caster)
	if (total_power * PowerCost) < power_left then
		speed = GetSpeed(Caster)
		if speed < SpeedValue then
			SetSpeed(Caster, SpeedValue)
		end
		new_power =  GetPower(Caster) - (total_power * PowerCost)
		if new_power > 0 and HasMoved(Caster) == true then
			SetPower(Caster, new_power)
		elseif new_power <= 0 then
			SetSpeed(Caster, 0)
		end
	else
		SetSpeed(Caster, 0)
	end
	return
end

function tick(Caster, Target, PowerCost, SpeedValue)
	cast(Caster, Target, PowerCost, SpeedValue)
end

function remove(Caster, Target)
	SetSpeed(Caster, 0)
end

User avatar
thefoof
Retired
Posts: 630
Joined: Wed Nov 07, 2012 7:36 pm
Location: Florida

Re: LUA Needs (a list)

Post by thefoof » Fri Nov 22, 2013 11:43 pm

We probably need to make a function to check if a spell has already applied a bonus to script this spell properly, but here's one way to script this spell...sprint is a bit tricky since it deals with power percentages and recurring power costs.

Code: Select all

function cast(Caster, Target, PowerCost, SpeedValue)
   --Initial power cost of sprint is 15%
   if GetPower(Caster) >= GetMaxPower(Caster) * .15 then
	   SetPower(Caster, GetPower(Caster) - (GetMaxPower(Caster) * .15))
	   AddSpellBonus(Caster, 609, SpeedValue)
   end
   SetTempVariable(Caster, "sprint_lastx", GetX(Caster))
   SetTempVariable(Caster, "sprint_lasty", GetY(Caster))
   SetTempVariable(Caster, "sprint_lastz", GetZ(Caster))
end

function tick(Caster, Target, PowerCost, SpeedValue)
   --Recurring tick cost of sprint is 10% of max power, only if the player has moved
   --perform math on a string to convert it to number in lua - not sure if this will work or not
   local lastx = GetTempVariable(Caster, "sprint_lastx") + 0
   local lasty = GetTempVariable(Caster, "sprint_lasty") + 0
   local lastz = GetTempVariable(Caster, "sprint_lastz") + 0
   if lastx ~= GetX(Caster) or lasty ~= GetY(Caster) or lastz ~= GetZ(Caster) then
       if GetPower(Caster) >= GetMaxPower(Caster) * .1 then
	       SetPower(Caster, GetPower(Caster) - (GetMaxPower(Caster) * .1))
	   end
   end
   SetTempVariable(Caster, "sprint_lastx", GetX(Caster))
   SetTempVariable(Caster, "sprint_lasty", GetY(Caster))
   SetTempVariable(Caster, "sprint_lastz", GetZ(Caster))
end

function remove(Caster, Target)
   RemoveSpellBonus(Caster)
   SetTempVariable(Caster, "sprint_lastx", nil)
   SetTempVariable(Caster, "sprint_lasty", nil)
   SetTempVariable(Caster, "sprint_lastz", nil)
end

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:

Re: LUA Needs (a list)

Post by John Adams » Sat Nov 23, 2013 12:28 am

Wow, I'll bet there is simpler code in the Space Shuttle's guidance system.

That looks awesome though :)

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests