New Spell Script LUA Function: precast

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

Moderator: Team Members

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

New Spell Script LUA Function: precast

Post by Jabantiz » Tue Aug 06, 2013 10:38 pm

We should probably also look at adding a function that gets called after the normal error checks, but before a player starts casting a spell as well. Some spells have specific reqs before a spell can be used (they aren't this way anymore, but off the top of my head the shield attacks used to require you have a shield equipped).
Added precast function that spells will try to call before actually being cast it will only take the caster and target and it must return true or false

Code: Select all

function precast(Caster, Target)
	if IsAlive(Target) == true then
		return true
	end
	
	return false
end
This is just an example and is actually pointless to do as this check is done in the code, this is just an example of how it should work.

While I agree with scatman that spells need a flag to handle most of these checks in the server core this can be used for stuff not handled by flags like quest steps or spawn id's or to implement stuff before the flags for it are implemented.

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: New Spell Script LUA Function: precast

Post by John Adams » Wed Aug 07, 2013 6:41 pm

I just thought of a possible use for this right away... starting a Heroic Opportunity, no? The requirement is that you must be in-combat before you can cast it.

Unless we already check for in-combat in some other way (spell 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: New Spell Script LUA Function: precast

Post by John Adams » Fri Aug 09, 2013 12:04 pm

Thanks for answering.

Do you think this will be proper use of precast()?

Code: Select all

--[[
	Script Name	: Spells/Fighter/FightingChance.lua
	Script Author	: John Adams
	Script Date	: 2013.08.09 12:08:44
	Script Notes	: Starts HO Chain
--]]

function cast(Caster, Target)

	if precast(Caster, Target) == true then
		-- display HO starter chain
	end

end

function precast(Caster, Target)

	if IsInCombat(Caster) == true then
		return true
	end
       
	return false
end
Though I am still uncertain about the Caster vs Target when it is a self-only spell... should I be using Target instead?

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

Re: New Spell Script LUA Function: precast

Post by Jabantiz » Fri Aug 09, 2013 12:15 pm

nah it is a function like cast that has to have a return value, the server core will call this function before cast timers start if it returns false you will get the can not prepare spell cast message in game.

An example would be a spell you can only cast while stealth

Code: Select all

function precast(Caster, Target)
    -- if the caster is stealthed allow the spell to cast
    if IsStealthed(Caster) then
        return true;
    end
    return false
end

function cast(Caster, Target, Damage)
    SpellDamage(Target, 0, Damage, Damage)
end
You can call it like you did if you want to make the check again though.

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: New Spell Script LUA Function: precast

Post by John Adams » Fri Aug 09, 2013 12:55 pm

Ahh okay, so it's like cast, tick and remove. Gotcha.



Edit: Could I also just do it even simpler, since true and false is all we need to return?

Code: Select all

function precast(Caster, Target)
	return IsInCombat(Caster)
end

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

Re: New Spell Script LUA Function: precast

Post by Jabantiz » Fri Aug 09, 2013 1:11 pm

yes that will work

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

Re: New Spell Script LUA Function: precast

Post by Jabantiz » Mon Sep 09, 2013 3:52 pm

Debating on changing how this function works, thinking that instead of having return true or false back to the server core have it return a number, 0 would be ok to cast (like returning true right now) and any number returned would be the error to send to the client, as of right now it uses a generic error of "can not prepare".

Thoughts? Any one even use this function yet?

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: New Spell Script LUA Function: precast

Post by John Adams » Thu Nov 21, 2013 11:34 pm

While I like the idea of custom errors back to the client, I dislike the Engineering 101 double-negative stuff that I get pounded by all day at work...

Disabled = 0 ( means, enabled... wtf?)

0 is never True. Not in any universe :)

0 does mean no error though, if you'd prefer word games.

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

Re: New Spell Script LUA Function: precast

Post by Jabantiz » Fri Nov 22, 2013 12:27 am

0 would be no error's returned so it is "true" that the spell can cast :mrgreen:

anyways do you want to change it to return the error code to the server core instead of true and false? Should be a simple change.

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: New Spell Script LUA Function: precast

Post by John Adams » Fri Nov 22, 2013 7:46 am

Only if you think other messaging is important. "Cannot prepare" makes no sense, but I am assuming that is what SOE reports. In a "either you can use it or you cannot" world, it seems simpler to leave it as if false, throw up some message indicating so otherwise process normally (true).

In short, the way you have it is fine.

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

Re: New Spell Script LUA Function: precast

Post by Jabantiz » Thu Dec 05, 2013 1:31 am

I discovered it is possible to have multiple return values in lua so we could leave it as the true/false but also return an int8 along with it for an error code, an example using the HO script

Code: Select all

function precast(Caster, Target)
   -- Must be engaged in combat
   return IsInCombat(Caster), 12
end
If it returns false it will use 12 as the error code (poor example as 12 is not in combat, couldn't find the only in combat code). This is also optional, if no error code is provided it could continue to use the old default one I picked.

Should I implement this or leave it as is?

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: New Spell Script LUA Function: precast

Post by John Adams » Thu Dec 05, 2013 8:14 am

If you think it's necessary... should we be doing something different than simple true/false? I can see LUA getting pretty hairy if we start sending back error codes and expecting to do stuff with them in code... but, that's your domain. If you think it's beneficial, and it does seem cool.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests