Page 1 of 1

Defense, table issue

Posted: Tue Jul 22, 2014 3:03 pm
by icesteruk
I seem to be having an issue with my defense table, some skills require certain things like 5 spark, 10 devotion etc which I track from gmcp but I am at a lost on how to put that into the defup.
Code: [show] | [select all] lua
class.def.Priest = {
fireblock = {
action = "evoke fireblock",
need = "5 spark",
balance = "needbalance",
},
nightsight = {
action = "nightsight",
need = "nothing",
balance = "none",
},
inspiration = {
action = "perform inspiration strength",
balance = "balance",
need = "none",
	},
}
Any one have an idea?

I thought maybe I could use something like..

reqs = function() tonumber(gmcp.Char.Vitals.spark > 5) then return true end,

in my defense tracking but im unsure how to put that into my defup :/

Re: Defense, table issue

Posted: Tue Jul 22, 2014 7:47 pm
by demonnic
Code: [show] | [select all] lua
-- assuming defToPutUp = class.def.Priest.<something>. Also assumes you used class.def.Priest.<something>.req for the
-- dependency check and that the dependency check returns true if the needed dependencies are in place, and false otherwise, and .action is able to be fed into your queuing mechanism. You'll certainly have to adjust this code 
-- to your individual situation
local dependencyMet = false
if defToPutUp.req == nil then 
  dependencyMet = true
else 
  dependencyMet = defToPutUp.req()
end
if dependencyMet then
  --queue() here just stands in for however you want to queue up the defense to be put up... it's not a real function I'm aware of
  queue(defToPutUp.action)
end
I have not tested this, but something similar to the above should do it for you.

Re: Defense, table issue

Posted: Tue Jul 22, 2014 9:32 pm
by icesteruk
icesteruk wrote:reqs = function() tonumber(gmcp.Char.Vitals.spark > 5) then return true end,
can I use that in the code?? and just run deftoputup.reqs() like I would a script?

If so, thank you so much I didnt now that

Re: Defense, table issue

Posted: Tue Jul 22, 2014 9:35 pm
by demonnic
You forgot the leading if part but in general yes

Re: Defense, table issue

Posted: Tue Jul 22, 2014 11:57 pm
by icesteruk
yeah if deftop.reqs() then .. ?


Thanks dude your the best - not told you in months :P lol

Re: Defense, table issue

Posted: Wed Jul 23, 2014 2:12 am
by demonnic
No in the function declaration.
Though I would just do
Code: [show] | [select all] lua
req = function() return (tonumber(gmcp.Char.Vitals.spark) > 5) end

Re: Defense, table issue

Posted: Thu Jul 24, 2014 10:03 pm
by icesteruk
soo, Having a huge issue, this suppose to be coming back false but its coming back true

reqs = function() return hasSkill("ReflexiveDiversion") and hasSkill("Dodging") end,

doing lua hasSkill("ReflexiveDiversion") and same for dodging, both return false, but it keeps putting it up :/
Code: [show] | [select all] lua
for skill, avoid in pairs(defenses.avoidance) do
if CanDef(skill) and not my.defenses[skill] then
send(avoid.action)
end
end -- end of avoidance
Code: [show] | [select all] lua
function CanDef(name)

if type(name.reqs) == "function" and not name.reqs() then return false end

return true
end

Re: Defense, table issue

Posted: Thu Jul 24, 2014 10:15 pm
by demonnic
use reqs = function() return ( hasSkill("ReflexiveDiversion") and hasSkill("Dodging") ) end

Tested using lua REPL:
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> myTable={}
> myTable.reqs = function() return (hasSkill("ReflexiveDiversion") and hasSkill("Dodging") ) end
> function hasSkill(str)
>> return false
>> end
> print(myTable.reqs())
false
>