Introducing: Mantis for Lusternia - Beta Release 5.0.1
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
Your understanding of Mantis is pretty right on, good to hear!
I'll explain the curing afflictions function for you, it's actually quite easy.
First, it iterates through the herbCure list, then checks to see if the affliction is located in the herbQueue list, and that your herbBalance is equal to 1 (is true, in this case, apologies for the terrible habit, ixokai). If both of those conditions are met, it will send the appropriate cure, set herbBalance to 0.5, then run a timer that will execute that block of code after two seconds. The block of code basically resets the herbBalance to 1 again, and fires the curing function once again.
Please, take this all apart and post up any feedback, especially what you can see needs fixing. I have Mantis Beta Release 5.0 in the works right now, and all of this is being redone properly. I'll end up posting what I have here soon, to better show everyone, and get some ideas moving on how I can make Mantis work better.
Thanks again for all of the comments and questions!
I'll explain the curing afflictions function for you, it's actually quite easy.
First, it iterates through the herbCure list, then checks to see if the affliction is located in the herbQueue list, and that your herbBalance is equal to 1 (is true, in this case, apologies for the terrible habit, ixokai). If both of those conditions are met, it will send the appropriate cure, set herbBalance to 0.5, then run a timer that will execute that block of code after two seconds. The block of code basically resets the herbBalance to 1 again, and fires the curing function once again.
Please, take this all apart and post up any feedback, especially what you can see needs fixing. I have Mantis Beta Release 5.0 in the works right now, and all of this is being redone properly. I'll end up posting what I have here soon, to better show everyone, and get some ideas moving on how I can make Mantis work better.
Thanks again for all of the comments and questions!
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
Sorry, I'm incredibly dense. I actually need more help understanding the syntax of those lines, especially the 'v.' stuff.
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
Not great with Lua, but from what I understand _,v is basically setting a "name" you can refer to the values by. Your typical table is sort of like,
which, by default, would be k,v or "key, value".
Edit to add: Forgot to note - in the table above, k=a, v=1. k=b, v="second thing". k=c, v=true. and so on. For k=d, the value is used as its own table, so v.a="several", etc.
The tables in Mantis don't really handle items through keys though:
Everything is contained in the value, so _,v means "for the specified table, ignore the key and let me refer to the value as v". After that, "name" and "cure" are handled as table items for the variable v, so v.name, v.cure. If you added a third line - just say you wanted a specific echo to be triggered by the table as well, you might do v.echo or something.
I'm pretty sure this is about right, though I'm not 100% on the technical side of it and it's only recently I've had so much of a basic understanding of tables. Hope it helps though.
Code: Select all
table = {
a = 1,
b = "second thing",
c = true,
d = {a="several", b="possible", c="options"},
}
Edit to add: Forgot to note - in the table above, k=a, v=1. k=b, v="second thing". k=c, v=true. and so on. For k=d, the value is used as its own table, so v.a="several", etc.
The tables in Mantis don't really handle items through keys though:
Code: Select all
herbCure = {
{name = "slickness", cure = "outr calamus; eat calamus"},
}
I'm pretty sure this is about right, though I'm not 100% on the technical side of it and it's only recently I've had so much of a basic understanding of tables. Hope it helps though.
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
This explanation calls for how the Lua FOR loop works... Or, at least how I imagine how all FOR loops should work! FOR loops iterate through tables, going through all of the values stored in the tables. Now, in Lua, tables take the responsibility of holding ALL the data, unlike in other languages where you have arrays (indexed lists, i.e. array = {1, 2, 3}, and the key in this instance is the position of the letters: position 0 has the value 1, position 1 has the value 2, etc...) and dictionaries (same thing as an array, however instead of the keys being numerical values chosen by their relative position in the array, the keys are chosen by the user, i.e dictionary = {apple = "pie", table = "top", beer = "intoxicating"}).
Now, the way that the Lua FOR loop work is thus: for k,v in pairs/ipairs(tableName) do stuff end. The difference between pairs and ipairs is pairs references that tableName is a dictionary-like table, and ipairs is an array-like table. k,v means key,value, however, these are just variable names.
So, you could, in theory (taken from Mantis 5.0) write a FOR loop that looks like:
This is useful both for user readability (because affliction,cure tells you exactly what those key,value pairs are for, better than k,v does!) and is easier to call them in functions elsewhere.
For example, I have a dictionary-like table:
and I want to send to the MUD that I like the values in the table. So, what I could do is make a simple FOR loop to say that I like them.
Does that make sense?
EDIT: When you ever seen an underscore in the k,v pair, it usually means that whichever is being underscored isn't important.
Now, the way that the Lua FOR loop work is thus: for k,v in pairs/ipairs(tableName) do stuff end. The difference between pairs and ipairs is pairs references that tableName is a dictionary-like table, and ipairs is an array-like table. k,v means key,value, however, these are just variable names.
So, you could, in theory (taken from Mantis 5.0) write a FOR loop that looks like:
Code: Select all
for affliction,cure in pairs(mantisAfflictionPriorities) do
stuff
end
For example, I have a dictionary-like table:
Code: Select all
myDictionary = {
apples = "bananas",
potato = "tomato",
}
Code: Select all
for _,whatILike in pairs(myDictionary) do
send("I like "..myDictionary[whatILike])
end
EDIT: When you ever seen an underscore in the k,v pair, it usually means that whichever is being underscored isn't important.
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
This is one common use for for loops, yes. It is often used to iterate through a table. It should also be noted that
a: pairs() does not guaruntee order, unless you are using php-like tables (which is a modified table... there's a post on the forum about them, I believe)
b:ipairs() can be called on a mixed table (IE a = {some = "stuff", "pizza", "blue", organization = "nonexistant"}) but it will only call those items in the table which do not have user specified keys... in the above example "pizza" and "blue" . I'm uncertain, but it may run through those items which have user specified integer keys... I'll have to test that sometime soon.
c: You can also use a for loop in a tradition manner.
a: pairs() does not guaruntee order, unless you are using php-like tables (which is a modified table... there's a post on the forum about them, I believe)
b:ipairs() can be called on a mixed table (IE a = {some = "stuff", "pizza", "blue", organization = "nonexistant"}) but it will only call those items in the table which do not have user specified keys... in the above example "pizza" and "blue" . I'm uncertain, but it may run through those items which have user specified integer keys... I'll have to test that sometime soon.
c: You can also use a for loop in a tradition manner.
would count by 2s, displaying only odd numbers (cuz we started at 1) until i is >= cap. If you want to jump by 1s, you can just do
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
Thanks, guys. That really cleared things up for me. You're the best!
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
This is probably needlessly complicated, but I expanded the Mantis Curing System scripts to accomodate a bit of prioritization. Basically, instead of 1 queue for each type of cure (i.e. herb, salve, elixir, etc.), I have 4 with the highest priority queue denoted by herbQueue1[aff] and the lowest priority queue denoted by herbQueue4[aff]. I'm not sure if the syntax "herbQueue1[nil]" is correct. Basically, what I was going for is that any afflictions in herbQueue1 will be cured first and when herbQueue1 is empty, continue to heal any afflictions in herbQueue2, and if herbQueue1 and herbQueue2 are both empty, continue to heal any afflictions in HerbQueue3, and so on and so forth. Please let me know if I'm on the right track. I love learning from my mistakes!
Add Affliction - Herb Script
Herb Queue Script
Remove Affliction - Herb Script
I appreciate everyone's efforts in guiding me. I hope it doesn't seem futile!
Add Affliction - Herb Script
Code: Select all
function addAff_herb1(aff)
if herbQueue1[aff] ~= true then
herbQueue1[aff] = true
cureAffs_herb1()
end
end
function addAff_herb2(aff)
if herbQueue2[aff] ~= true then
herbQueue2[aff] = true
cureAffs_herb1()
end
end
function addAff_herb3(aff)
if herbQueue3[aff] ~= true then
herbQueue3[aff] = true
cureAffs_herb1()
end
end
function addAff_herb4(aff)
if herbQueue4[aff] ~= true then
herbQueue4[aff] = true
cureAffs_herb1()
end
end
Code: Select all
function cureAffs_herb1()
for _,v in pairs(herbCure) do
if herbQueue1[v.name] and herbBalance == 1 then
send(v.cure)
herbBalance = 0.5
tempTimer(2, [[if mantis_herbBalance == 0.5 then mantis_herbBalance = 1;cureAffs_herb1()]])
end
if herbQueue1[nil] and herbBalance == 1 then
cureAffs_herb2()
end
end
end
function cureAffs_herb2()
for _,v in pairs(herbCure) do
if herbQueue2[v.name] and herbBalance == 1 and herbQueue1[nil] then
send(v.cure)
herbBalance = 0.5
tempTimer(2, [[if mantis_herbBalance == 0.5 then mantis_herbBalance = 1;cureAffs_herb1()]])
end
if herbQueue1[nil] and herbBalance == 1 and herbQueue2[nil] then
cureAffs_herb2()
end
end
end
function cureAffs_herb3()
for _,v in pairs(herbCure) do
if herbQueue3[v.name] and herbBalance == 1 and herbQueue1[nil] and herbQueue2[nil] then
send(v.cure)
herbBalance = 0.5
tempTimer(2, [[if mantis_herbBalance == 0.5 then mantis_herbBalance = 1;cureAffs_herb1()]])
end
if herbQueue1[nil] and herbBalance == 1 and herbQueue2[nil] and herbQueue3[nil] then
cureAffs_herb4()
end
end
end
function cureAffs_herb4()
for _,v in pairs(herbCure) do
if herbQueue4[v.name] and herbBalance == 1 and herbQueue1[nil] and herbQueue2[nil] and herbQueue3[nil] then
send(v.cure)
herbBalance = 0.5
tempTimer(2, [[if mantis_herbBalance == 0.5 then mantis_herbBalance = 1;cureAffs_herb1()]])
end
end
end
herbCure = {
{name = "achromatic_aura", cure = "outr horehound;eat horehound"},
{name = "addiction", cure = "outr galingale;eat galingale"},
{name = "aeon", cure = "outr reishi;eat reishi"},
{name = "agoraphobia", cure = "outr wormwood;eat wormwood"},
{name = "attraction", cure = "outr earwort;eat earwort"},
{name = "aura_warp", cure = "outr reishi;eat reishi"},
{name = "blindness", cure = "outr faeleaf;eat faeleaf"},
{name = "broken_chest", cure = "outr arnica;apply arnica to chest"},
{name = "broken_nose", cure = "outr arnica;apply arnica to head"},
{name = "bloodclot", cure = "outr yarrow;eat yarrow"},
{name = "claustrophobia", cure = "outr wormwood;eat wormwood"},
{name = "clumsiness", cure = "outr kombu;eat kombu"},
{name = "confusion", cure = "outr pennyroyal;eat pennyroyal"},
{name = "crushed_foot", cure = "outr arnica;apply arnica to legs"},
{name = "crushed_windpipe", cure = "outr arnica;apply arnica to head"},
{name = "captivation", cure = "outr earwort;eat earwort"},
{name = "daydreaming", cure = "outr kafe;eat kafe"},
{name = "deadening", cure = "outr kombu;eat kombu"},
{name = "dementia", cure = "outr pennyroyal;eat pennyroyal"},
{name = "dislocated_limb", cure = "outr marjoram;eat marjoram"},
{name = "dizziness", cure = "outr kombu;eat kombu"},
{name = "ego_vice", cure = "outr horehound;eat horehound"},
{name = "epilepsy", cure = "outr kombu;eat kombu"},
{name = "gashed_cheek", cure = "outr marjoram;eat marjoram"},
{name = "generosity", cure = "outr galingale;eat galingale"},
{name = "gluttony", cure = "outr galingale;eat galingale"},
{name = "haemophilia", cure = "outr yarrow;eat yarrow"},
{name = "hallucinations", cure = "outr pennyroyal; eat pennyroyal"},
{name = "healthleech", cure = "outr horehound;eat horehound"},
{name = "hypochondria", cure = "outr wormwood;eat wormwood"},
{name = "jinx", cure = "outr reishi;eat reishi"},
{name = "justice", cure = "outr reishi;eat reishi"},
{name = "lacerated_limb", cure = "outr yarrow;eat yarrow"},
{name = "lethargy", cure = "outr yarrow;eat yarrow"},
{name = "lovers_curse", cure = "outr galingale;eat galingale"},
{name = "manabarbs", cure = "outr horehound; eat horehound"},
{name = "mangled_tongue", cure = "outr marjoram;eat marjoram"},
{name = "narcolepsy", cure = "outr kafe;eat kafe"},
{name = "omniphobia", cure = "outr kombu;eat kombu"},
{name = "open_chest", cure = "outr marjoram;eat marjoram"},
{name = "open_gut", cure = "outr marjoram;eat marjoram"},
{name = "pacification", cure = "outr reishi;eat reishi"},
{name = "paranoia", cure = "outr pennyroyal;eat pennyroyal"},
{name = "peace", cure = "outr reishi;eat reishi"},
{name = "pinched_nerve", cure = "outr marjoram;eat marjoram"},
{name = "power_spikes", cure = "outr horehound;eat horehound"},
{name = "punctured_aura", cure = "outr reishi;eat reishi"},
{name = "punctured_chest", cure = "outr marjoram;eat marjoram"},
{name = "recklessness", cure = "outr horehound;eat horehound"},
{name = "relapse", cure = "outr yarrow;eat yarrow"},
{name = "rigormortis", cure = "outr marjoram;eat marjoram"},
{name = "scrambled", cure = "outr pennyroyal;eat pennyroyal"},
{name = "sensitivity", cure = "outr myrtle;eat myrtle"},
{name = "severed_artery", cure = "outr yarrow;eat yarrow"},
{name = "sliced_bicep", cure = "outr marjoram;eat marjoram"},
{name = "sliced_ear", cure = "outr marjoram;eat marjoram"},
{name = "sliced_forehead", cure = "outr yarrow;eat yarrow"},
{name = "sliced_thigh", cure = "outr marjoram;eat marjoram"},
{name = "slickness", cure = "outr calamus;eat calamus"},
{name = "snapped_rib", cure = "outr arnica;apply arnica to chest"},
{name = "stupidity", cure = "outr pennyroyal;eat pennyroyal"},
{name = "succumb", cure = "outr reishi;eat reishi"},
{name = "vapors", cure = "outr kombu;eat kombu"},
{name = "vertigo", cure = "outr myrtle;eat myrtle"},
{name = "vestiphobia", cure = "outr wormwood;eat wormwood"},
{name = "void", cure = "outr pennyroyal;eat pennyroyal"},
{name = "weakness", cure = "outr marjoram;eat marjoram"}
}
Code: Select all
function remAff_herb1(aff)
herbQueue1[aff] = false
cureAffs_herb1()
end
function remAff_herb2(aff)
herbQueue2[aff] = false
cureAffs_herb1()
end
function remAff_herb3(aff)
herbQueue3[aff] = false
cureAffs_herb1()
end
function remAff_herb4(aff)
herbQueue4[aff] = false
cureAffs_herb1()
end
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
I'm quite impressed with this, good job! This might be, however, a little overly complicated. Instead of running 4 separate queues for each balance (totaling 16 queues over all of the balances), you're pushing quite a bit of overhead just to run this.
The best way that you can go about prioritizing is making an ordered array of all the afflictions, arranged in the order you wish to cure them, then turning them into a phpTable, which can be found on the Lua website, or doing a Google search for "lua phptable". Then, you stick phpTable() around your array, and you're golden!
Next, you'd run a simple FOR loop to iterate over that table, which will send the appropriate cures when necessary, pending the balance is active.
That's the most straight-forward way of doing it, though there are a lot of complications with going about doing so. So good luck!
The best way that you can go about prioritizing is making an ordered array of all the afflictions, arranged in the order you wish to cure them, then turning them into a phpTable, which can be found on the Lua website, or doing a Google search for "lua phptable". Then, you stick phpTable() around your array, and you're golden!
Next, you'd run a simple FOR loop to iterate over that table, which will send the appropriate cures when necessary, pending the balance is active.
That's the most straight-forward way of doing it, though there are a lot of complications with going about doing so. So good luck!
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
Um, wow. Yeah, that would be -way- simpler! Thanks for pointing me in the right direction! I'll look into the php tables and show you what I come up with!
Re: Introducing: Mantis for Lusternia - Beta Release 4.2
Since this thread is getting a bit more face-time for Mantis than my Lusternian Forums one, and because I like seeing Ilithyia grow as a programmer, I'll post up what I have written so far. Mind you, this hasn't been quite tested yet, but I'd like to see if my programming logic works in this case.
I've simplified pretty much EVERYTHING compared to what I posted up on the Lusternian forums. It no longer has an explicit function to "flag" balances to be used, but rather does it implicitly from within the script.
Also, a big on-going change that I want to implement is to combine all of the system variables into a table called "mantis", which would be organized from there. It adds some length to the variables, but refactoring them into one place will make for an easier time organizing, methinks.
Anyhow, onwards to the scripts!
Here are my two major lists (which I'm thinking of refactoring, but I'm not quite sure if I really need to or not).
The Affliction Priority List, which is the list of afflictions ordered by balance, and their associated cures.
The Affliction Balances List, which is the same thing as the affliction priority list, except that it lists out all of the balances that each affliction is cured by. Notice that it's not an ordered list, because it doesn't necessarily need to be.
Next, my curing script:
First, the function iterates through the list of afflictions that I currently have (mantisAfflictedWith), then searches through the balance priorities list (mantisBalancePriorities). Next, it checks to make sure that the balance is active (true), then iterates through the affliction priorities list in the associated balance, to see if it contains said affliction. If it does, it sends the cure. If not, it restarts the search.
The function to reset balances is pretty simple to follow, so no explanation is necessary.
Finally, I'll post up my table of system afflictions, since I think that this deserves some face time.
I've simplified pretty much EVERYTHING compared to what I posted up on the Lusternian forums. It no longer has an explicit function to "flag" balances to be used, but rather does it implicitly from within the script.
Also, a big on-going change that I want to implement is to combine all of the system variables into a table called "mantis", which would be organized from there. It adds some length to the variables, but refactoring them into one place will make for an easier time organizing, methinks.
Anyhow, onwards to the scripts!
Here are my two major lists (which I'm thinking of refactoring, but I'm not quite sure if I really need to or not).
The Affliction Priority List, which is the list of afflictions ordered by balance, and their associated cures.
The Affliction Balances List, which is the same thing as the affliction priority list, except that it lists out all of the balances that each affliction is cured by. Notice that it's not an ordered list, because it doesn't necessarily need to be.
Next, my curing script:
Code: Select all
function MantisCureAfflictions()
for _,affliction in ipairs(mantisAfflictedWith) do
for _,balance in ipairs(mantisBalancePriorities) do
if mantis.healingBalances[balance] == true then
for _,cure in pairs(mantisAfflictionPriorities[balance]) do
if table.contains(mantisAfflictedWith, affliction) then
send(affliction[cure])
mantis.healingBalances[balance] = false
MantisResetBalance(balance)
end
end
end
end
end
end
The function to reset balances is pretty simple to follow, so no explanation is necessary.
Code: Select all
function MantisResetBalance(balance)
if mantis.healingBalances[balance] == false then
tempTimer(2, [[mantis.healingBalances[balance] = true]])
end
end
Code: Select all
mantis = {
healingBalances = {
Herb = true,
Purgative = true,
Salve = true,
Balance = true,
Focus = true,
},
autosipper = {
balance = true,
sipAt = 0.5,
},
balances = {
balance = true,
equilibrium = true,
leftArmBalance = true,
rightArmBalance = true,
id = true,
sub = true,
super = true,
},
stats = {
currentHealth = nil,
maxHealth = nil,
currentMana = nil,
maxMana = nil,
currentEgo = nil,
maxEgo = nil,
currentEndurance = nil,
maxEndurance = nil,
currentWillpower = nil,
momentum = nil,
},
abilities = {
gliding = true,
sprinting = true,
},
}