I am currently working on a plugin (Lua) to make idle time feel more organic when I leave my character sitting in a pub while I go afk for a smoke or to handle household chores. The problem I am having is figuring out how to call a function after the timer sends the action to the game. Pertinent code posted below, please not I am new to LUA but not coding, and any input on streamlining this code is welcome.
--------------------------
havedrink = 0
havesmoke = 0
function Callit ()
RndAct ()
end
function RndAct ()
math.randomseed(os.time())
tmrstg = math.random(15, 150)
tmpact = math.random(1, 25)
if tmpact == 1 then tmract = "gaze"
elseif tmpact == 2 then tmract = "act grabs some peanuts and begins snacking on them"
elseif tmpact == 3 then tmract = "act stretches and adjusts his position on his stool"
elseif tmpact == 4 then tmract = "act taps one of his feet impatiently as a nearby conversation rises into an argument"
elseif tmpact == 5 then tmract = "act cracks his neck as he looks around cautiously"
elseif tmpact == 6 then tmract = "act pushes hat back to scratch his head"
elseif tmpact == 7 then tmract = "act begins humming a few bars of a popular pub song"
elseif tmpact == 8 then tmract = "act inspect the bottles lining the shelves behind the bar"
elseif tmpact == 9 then tmract = "act taps out a rhythm with his fingers on the bar"
elseif tmpact == 10 then
if havedrink = 0 then
tmract = "act points to a random bottle on the shelves and buys a drink"
havedrink = math.random(3, 5)
else
tmract = "act takes a sip of his drink, sighing with satisfaction"
havedrink = havedrink - 1
end
elseif tmpact == 11 then tmract = "act checks to make sure his coin purse, as well as his weapons, are still in place"
elseif tmpact == 12 then
if havesmoke = 0 then
tmract = "act takes a smoke out of his case before returning it to his cloak, and then lights his cigarette"
havesmoke = math.random(8, 14)
elseif havesmoke = 1 then
tmract = "act stubs out his smoke in the ashtray"
havesmoke = havesmoke - 1
else
tmract = "act takes a long drag off of his smoke"
havesmoke = havesmoke - 1
end
elseif tmpact == 13 then tmract = "act rubs his eyes, pulling his hands down his face afterwards in a distracted manner"
elseif tmpact == 14 then tmract = "sigh"
elseif tmpact == 15 then tmract = "act pulls out a coin and rolls it across his knuckles a few times before returning it to his coin pouch"
elseif tmpact == 16 then tmract = "act stands up and walks over to look at the jobs board, sighs at finding nothing of interest, then returns to his stool"
elseif tmpact == 17 then tmract = "act checks his watch, taps the face a couple times and then winds it up"
elseif tmpact == 18 then tmract = "act tries to draw a picture on the bar with some of the spilled drinks"
elseif tmpact == 19 then tmract = "act pulls out his cigarette case and distractedly plays with it for a while before putting it back"
elseif tmpact == 20 then tmract = "stretch"
elseif tmpact == 21 then tmract = "act attempts to clean one of his boots with a bit of his shirt, somehow making both dirtier for his effort"
elseif tmpact == 22 then tmract = "act mutters something about wattered down spirits under his breath"
elseif tmpact == 23 then tmract = "squint"
elseif tmpact == 24 then tmract = "act flips a couple of coins to the barkeep to cover his tab"
elseif tmpact == 25 then tmract = "act rummages through his numerous pockets looking for something, then gives up and shrugs"
end --if
tmin = math.floor(tmrstg/60)
tsec = tmrstg - (60*tmin)
AddTimer ("Alive", 0, tmin, tsec, tmract, timer_flag.Enabled + timer_flag.OneShot, "")
end
What I want to happen is Callit () to be called after the timer added by AddTimer triggers from within the plugin. |