Friday, July 3, 2009

Rune Lua script - first lua script i created

Originally this post is from here: http://zegarkus.com/2007/02/18/rune-lua-script-first-lua-script-i-created/


Ok, I like runes so I decided to create little Lua script for a game that wants to use a quick runic prophecy. This is my first Lua script in the process of learning the langange. I’ve assigned a few gamer attributes (agility, charisma, health, intelligence, luck, strength) to the Elder Futhark runes. The script contains a class that does the following:

  • user inputs how many runes are returned (should be 24 or less, thats how many runes are in this runeset
  • user indicates if the runes should have randomly generated negative meanings (murk staves)
  • returns a table of randomly chosen runes including the attributes assigned to it
  • returns a table summary of all the attributes from the casting.

A potential result set for this could be

name hagalaz
agility 2
strength 2
luck 0
charisma 0
intelligence 5
health 5
name mannaz
agility 0
strength 0
luck -1
charisma -1
intelligence -5
health 0
name ingwaz
agility 3
strength 3
luck 0
charisma 0
intelligence 0
health 4
——-totals:——-
agility 5
health 9
strength 5
charisma 8
intelligence 0
luck -1

Feel free to modify anything - this was the first Lua script I ever composed so don’t expect groundbreaking stuff or efficient code!

Code Here, sorry formatting is a bit off:

– created by Zegarkus 18.Feb.2007
– feel free to alter or do anything you want with the script
– author not responsible for from any damages cause by this
– script or any bad prophecies! ;) Rune = {}
Rune.__index = Rune

function Rune.create(num_runes,murk)

local run = {} — our rune object

setmetatable(run,Rune) — make Account handle lookup

– below are the constructors for this class:
run.num_runes = num_runes
run.murk = murk

– Assigned rune prophecies here, replace according to your knowledge of runes!
run.fehu = {name=”fehu”,agility=0,charisma=2,health=0,intelligence=3,luck=4,strength=0}
run.uruz = {name=”uruz”,agility=5,charisma=2,health=5,intelligence=2,luck=0,strength=3}
run.thurisaz = {name=”thurisaz”,agility=3,charisma=0,health=5,intelligence=0,luck=0,strength=5}
run.ansuz = {name=”ansuz”,agility=0,charisma=5,health=0,intelligence=5,luck=0,strength=0}
run.raidho = {name=”raidho”,agility=5,charisma=0,health=0,intelligence=2,luck=2,strength=0}
run.kenaz = {name=”kenaz”,agility=3,charisma=5,health=3,intelligence=0,luck=0,strength=0}
run.gebo = {name=”gebo”,agility=0,charisma=5,health=0,intelligence=4,luck=0,strength=0}
run.wunjo = {name=”wunjo”,agility=0,charisma=5,health=3,intelligence=2,luck=0,strength=0}
run.hagalaz = {name=”hagalaz”,agility=2,charisma=0,health=5,intelligence=5,luck=0,strength=2}
run.naudhiz = {name=”naudhiz”,agility=5,charisma=5,health=5,intelligence=0,luck=3,strength=0}
run.isa = {name=”isa”,agility=0,charisma=4,health=4,intelligence=4,luck=0,strength=0}
run.jera = {name=”jera”,agility=0,charisma=4,health=1,intelligence=4,luck=1,strength=0}
run.eihwaz = {name=”eihwaz”,agility=5,charisma=0,health=3,intelligence=3,luck=3,strength=3}
run.perdhro = {name=”perdhro”,agility=0,charisma=0,health=0,intelligence=3,luck=5,strength=0}
run.elhaz = {name=”elhaz”,agility=0,charisma=0,health=5,intelligence=2,luck=0,strength=0}
run.sowilo = {name=”sowilo”,agility=3,charisma=0,health=0,intelligence=0,luck=3,strength=3}
run.tiwaz = {name=”tiwaz”,agility=0,charisma=0,health=0,intelligence=0,luck=4,strength=5}
run.berkano = {name=”berkano”,agility=4,charisma=0,health=5,intelligence=0,luck=0,strength=2}
run.ehwaz = {name=”ehwaz”,agility=2,charisma=5,health=0,intelligence=0,luck=1,strength=0}
run.mannaz = {name=”mannaz”,agility=0,charisma=1,health=0,intelligence=5,luck=1,strength=0}
run.laguz = {name=”laguz”,agility=0,charisma=4,health=4,intelligence=0,luck=0,strength=0}
run.ingwaz = {name=”ingwaz”,agility=3,charisma=0,health=4,intelligence=0,luck=0,strength=3}
run.dagaz = {name=”dagaz”,agility=0,charisma=0,health=0,intelligence=5,luck=5,strength=0}
run.othala = {name=”othala”,agility=0,charisma=4,health=1,intelligence=0,luck=3,strength=2}

return run

end

function Rune:casting()
—function randomise creates a table
—that contains unique randomised numbers
—note, only 24 runes in elder futhark

runes = {self.fehu,self.uruz,self.thurisaz,self.ansuz,self.raidho,self.kenaz,
self.gebo,self.wunjo,self.hagalaz,self.naudhiz,self.isa,self.jera,
self.elhaz,self.perdhro,self.elhaz,self.sowilo,self.tiwaz,self.berkano,
self.ehwaz,self.mannaz,self.laguz,self.ingwaz,self.dagaz,self.othala}

prophecy = {}
i = 0

–get unique randomised numbers
while i <>

flag = 0
r = math.random(24)

for k,v in pairs (prophecy) do

if v == r then
flag = 1
end

end

if flag == 0 then
table.insert(prophecy, r)
i = i+1
end

end

runeset = {}

--match the runes in the table with the randomised selected ones
for k,v in pairs(runes) do

for l,w in pairs (prophecy) do
if k == w then
table.insert(runeset, runes[k])
end
end

end

--murk them! (if flagged by user, add negative value)
if self.murk == 1 then
for k,v in pairs(runeset) do
murk = (math.random(-1, 0))
if murk == -1 then
runeset[k].agility = runeset[k].agility * murk
runeset[k].charisma = runeset[k].charisma * murk
runeset[k].health = runeset[k].health * murk
runeset[k].intelligence = runeset[k].intelligence * murk
runeset[k].luck = runeset[k].luck * murk
runeset[k].strength = runeset[k].strength * murk
end
end
end

--modifiers, add up all the attributes and deliver them
a = 0
c = 0
h = 0
i = 0
l = 0
s = 0

--Add them up, return a summary table of all attributes
for k,v in pairs(runeset) do
a = a + runeset[k].agility
c = a + runeset[k].agility
h = h + runeset[k].health
i = i + runeset[k].intelligence
l = l + runeset[k].luck
s = s + runeset[k].strength
end

modifiers = {agility=a,charisma=c,health=h,intelligence=i,luck=l,strength=s }

-- return runic prophecy and summary of modifiers
return runeset,modifiers

end

----uncomment below lines to test script:
--r = Rune.create(3,1)
--cast,totals = r:casting()
--
--
--for k,v in pairs(cast) do
-- for l,w in pairs(cast[k]) do
-- print(l,w)
-- end
--end
--
--print("totals:-------")
--for k,v in pairs(totals) do
-- print(k,v)
--end

0 comments:

Post a Comment