Hey all,
Been working on scripting with lua but for some odd reason anytime I use a timer and disable it via timer.destroy() the script keeps running until I logout of win10 or restart the system... Any ideas on why this is happening or how I can fix it??
Lua script timer doesn't stop after the timer is destroyed
-
- Expert Cheater
- Posts: 852
- Joined: Fri Oct 12, 2018 10:25 pm
- Reputation: 896
Re: Lua script timer doesn't stop after the timer is destroyed
Make sure that you're not creating another timer with the same name while one is already active. As when you try to destroy it, you'll destroy the new one, but not the old one which will keep running.
Re: Lua script timer doesn't stop after the timer is destroyed
I like to use a global variable, say
This way it will always kills any running timers created using the same on timer function.
KILL_SOME_TIMER
, and if it's set then kill the timer in the OnTimer
function.
Code: Select all
local function someTimer_OnTimer(timer)
if KILL_SOME_TIMER then
timer.destroy()
return
end
-- body
end
Re: Lua script timer doesn't stop after the timer is destroyed
Here is the script
As to using the same timer as far as I know they are all unique as to naming.
Here is the script it is a simple health regeneration as the game doesn't have regeneration of any kind.
I would do this in asm if I knew a simpler way lol.
Where would I place the kill timer function?
As to using the same timer as far as I know they are all unique as to naming.
Here is the script it is a simple health regeneration as the game doesn't have regeneration of any kind.
I would do this in asm if I knew a simpler way lol.
when I disable the script I then write a new value to the pointer and the value starts increasing until the max is reached.{$lua}
[ENABLE]
healthRegenTimer = createTimer()
healthRegenTimer.Interval = 1000
local health = '[[[[[Dungeon Siege III.exe+02D8F3F0]+00]+60]+C4]+64]+14'
local maxHealth = '[[["Dungeon Siege III.exe"+02D8F3DC]+30]+64]+18'
local healthRegen = 1
healthRegenTimer.OnTimer = function()
local curHealth = readFloat(health)
local maxHealth = readFloat(maxHealth)
if curHealth and curHealth < maxHealth then
writeFloat(health, curHealth+healthRegen)
end
end
[DISABLE]
healthRegenTimer.destroy()
Where would I place the kill timer function?
Re: Lua script timer doesn't stop after the timer is destroyed
Put it in the OnTimer function.hcapinjr wrote: ↑Thu Jul 22, 2021 9:51 amHere is the script
As to using the same timer as far as I know they are all unique as to naming.
Here is the script it is a simple health regeneration as the game doesn't have regeneration of any kind.
I would do this in asm if I knew a simpler way lol.when I disable the script I then write a new value to the pointer and the value starts increasing until the max is reached.{$lua}
[ENABLE]
healthRegenTimer = createTimer()
healthRegenTimer.Interval = 1000
local health = '[[[[[Dungeon Siege III.exe+02D8F3F0]+00]+60]+C4]+64]+14'
local maxHealth = '[[["Dungeon Siege III.exe"+02D8F3DC]+30]+64]+18'
local healthRegen = 1
healthRegenTimer.OnTimer = function()
local curHealth = readFloat(health)
local maxHealth = readFloat(maxHealth)
if curHealth and curHealth < maxHealth then
writeFloat(health, curHealth+healthRegen)
end
end
[DISABLE]
healthRegenTimer.destroy()
Where would I place the kill timer function?
Code: Select all
{$lua}
[ENABLE]
KILL_HEALTH_REGEN_TIMER = false
healthRegenTimer = createTimer()
healthRegenTimer.Interval = 1000
local health = '[[[[[Dungeon Siege III.exe+02D8F3F0]+00]+60]+C4]+64]+14'
local maxHealth = '[[["Dungeon Siege III.exe"+02D8F3DC]+30]+64]+18'
local healthRegen = 1
healthRegenTimer.OnTimer = function(timer)
if KILL_HEALTH_REGEN_TIMER then
timer.destroy()
end
local curHealth = readFloat(health)
local maxHealth = readFloat(maxHealth)
if curHealth and curHealth < maxHealth then
writeFloat(health, curHealth+healthRegen)
end
end
[DISABLE]
KILL_HEALTH_REGEN_TIMER = true
Re: Lua script timer doesn't stop after the timer is destroyed
Thank you ShyTwig16 for your help and input. It works, I also noted I made and error in the scripting as far as lua scripting oddly myself and CE didn't catch it.. the current health pointer shouldn't have worked that I know of.. Very new to lua scripting here.. Anywho, the pointer is missing "
local health = '[[[[[Dungeon Siege III.exe+02D8F3F0]+00]+60]+C4]+64]+14'
and should have been local health = '[[[[["Dungeon Siege III.exe"+02D8F3F0]+00]+60]+C4]+64]+14' because that seemed to as well have fixed the issue.
Again thank you all for your input it is highly appreciated !
local health = '[[[[[Dungeon Siege III.exe+02D8F3F0]+00]+60]+C4]+64]+14'
and should have been local health = '[[[[["Dungeon Siege III.exe"+02D8F3F0]+00]+60]+C4]+64]+14' because that seemed to as well have fixed the issue.
Again thank you all for your input it is highly appreciated !
Who is online
Users browsing this forum: No registered users