Page 1 of 1
New Spell Script LUA Function: precast
Posted: Tue Aug 06, 2013 10:38 pm
by Jabantiz
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.
Re: New Spell Script LUA Function: precast
Posted: Wed Aug 07, 2013 6:41 pm
by John Adams
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?)
Re: New Spell Script LUA Function: precast
Posted: Fri Aug 09, 2013 12:04 pm
by John Adams
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?
Re: New Spell Script LUA Function: precast
Posted: Fri Aug 09, 2013 12:15 pm
by Jabantiz
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.
Re: New Spell Script LUA Function: precast
Posted: Fri Aug 09, 2013 12:55 pm
by John Adams
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
Re: New Spell Script LUA Function: precast
Posted: Fri Aug 09, 2013 1:11 pm
by Jabantiz
yes that will work
Re: New Spell Script LUA Function: precast
Posted: Mon Sep 09, 2013 3:52 pm
by Jabantiz
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?
Re: New Spell Script LUA Function: precast
Posted: Thu Nov 21, 2013 11:34 pm
by John Adams
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.
Re: New Spell Script LUA Function: precast
Posted: Fri Nov 22, 2013 12:27 am
by Jabantiz
0 would be no error's returned so it is "true" that the spell can cast
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.
Re: New Spell Script LUA Function: precast
Posted: Fri Nov 22, 2013 7:46 am
by John Adams
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.
Re: New Spell Script LUA Function: precast
Posted: Thu Dec 05, 2013 1:31 am
by Jabantiz
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?
Re: New Spell Script LUA Function: precast
Posted: Thu Dec 05, 2013 8:14 am
by John Adams
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.