Posts: 4
Threads: 1
Joined: Jun 2024
Reputation:
0
Can you help me with the following Lua script? I want to rewrite it for the bot. Its function is to save and count the time it takes to increase a skill by 1% and then give you an estimated time for how long it will take to level up a skill. In my case, I would like it to tell me how long it will take to level up 'Fishing' on the SOE server. with the HUD.
-- Initialize variables
local startTime = os.time()
local startSkill = getFishingSkill() -- Function to get current fishing skill percentage
local targetSkill = startSkill + 1 -- Target skill percentage increase
local currentSkill = startSkill
-- Function to calculate estimated time to level up
local function calculateEstimatedTime(elapsedTime, skillIncrease)
local skillPercentRemaining = 100 - startSkill
local estimatedTotalTime = (elapsedTime / skillIncrease) * skillPercentRemaining
return estimatedTotalTime
end
-- Main loop
while currentSkill < targetSkill do
-- Wait for skill to increase by 1%
currentSkill = getFishingSkill()
if currentSkill >= targetSkill then
local endTime = os.time()
local elapsedTime = endTime - startTime
local estimatedTime = calculateEstimatedTime(elapsedTime, 1)
print("Time taken to increase fishing skill by 1%: " .. elapsedTime .. " seconds")
print("Estimated time to reach 100% skill: " .. estimatedTime .. " seconds")
-- Reset for the next 1% increase
startTime = os.time()
startSkill = currentSkill
targetSkill = startSkill + 1
end
end
Posts: 2,948
Threads: 492
Joined: Jul 2018
Reputation:
84
06-15-2024, 03:53 AM
(This post was last modified: 06-16-2024, 03:26 PM by Arkilys.)
I think that you just need to replace getFishingSkill() on line #3 and #17 with one of our LUA functions that returns skill points.
Example:
mlevel() [number]
axe() [number]
You can find all here: |Only Registered members can see download links. | Click here to buy subscription or here to register.
For some reason i never added fishing() or fishingpc() to Bot, so i just did it. Please, redownload and reinstall Kasteria OTBot: |Only Registered members can see download links. | Click here to buy subscription or here to register.
Using the code you posted, just applying changes i told you above:
-- Initialize variables
local startTime = os.time()
local startSkill = fishing() -- Function to get current fishing skill percentage
local targetSkill = startSkill + 1 -- Target skill percentage increase
local currentSkill = startSkill
-- Function to calculate estimated time to level up
local function calculateEstimatedTime(elapsedTime, skillIncrease)
local skillPercentRemaining = 100 - startSkill
local estimatedTotalTime = (elapsedTime / skillIncrease) * skillPercentRemaining
return estimatedTotalTime
end
-- Main loop
while currentSkill < targetSkill do
-- Wait for skill to increase by 1%
currentSkill = fishing()
if currentSkill >= targetSkill then
local endTime = os.time()
local elapsedTime = endTime - startTime
local estimatedTime = calculateEstimatedTime(elapsedTime, 1)
addtext("Time taken to increase fishing skill by 1%: " .. elapsedTime .. " seconds", 100, 100)
addtext("Estimated time to reach 100% skill: " .. estimatedTime .. " seconds", 100, 125)
-- Reset for the next 1% increase
startTime = os.time()
startSkill = currentSkill
targetSkill = startSkill + 1
end
end
Posts: 4
Threads: 1
Joined: Jun 2024
Reputation:
0
I have added the Lua code in Huds and I don't think it is working, or at least no information is appearing on the screen. Could you help me?
Posts: 2,948
Threads: 492
Joined: Jul 2018
Reputation:
84
My bad, i didn't noticed you mention that was supposed to be on HUD. I just changed it and you should run it on HUDs tab.
Posts: 4
Threads: 1
Joined: Jun 2024
Reputation:
0
dosn't work, i edit and dosn't work too jajajaja and idk what is wrong, nothing is showing on the screen
-- Initialize variables
local startTime = runningtime()
local startSkill = fishing() -- Function to get current fishing skill percentage
local targetSkill = startSkill + 1 -- Target skill percentage increase
local currentSkill = startSkill
-- Function to calculate estimated time to level up
local function calculateEstimatedTime(elapsedTime, skillIncrease)
local skillPercentRemaining = 100 - startSkill
local estimatedTotalTime = (elapsedTime / skillIncrease) * skillPercentRemaining
return estimatedTotalTime
end
-- Main loop
while currentSkill < targetSkill do
-- Wait for skill to increase by 1%
currentSkill = fishing()
-- Check if skill has increased by 1%
if currentSkill >= targetSkill then
local endTime = runningtime()
local elapsedTime = endTime - startTime
local estimatedTime = calculateEstimatedTime(elapsedTime, 1)
-- Display information on HUD
addtextstroke("Time taken to increase fishing skill by 1%: " .. elapsedTime .. " seconds", clientwindow.left + 15, 150)
addtextstroke("Estimated time to reach 100% skill: " .. estimatedTime .. " seconds", clientwindow.left + 15, 175)
-- Reset for the next 1% increase
startTime = runningtime()
startSkill = currentSkill
targetSkill = startSkill + 1
end
wait(1000) -- Wait for 1 second before checking skill increase again
end
Posts: 2,948
Threads: 492
Joined: Jul 2018
Reputation:
84
06-18-2024, 10:42 PM
(This post was last modified: 06-18-2024, 10:43 PM by Arkilys.)
Try this code:
-- Function to calculate estimated time to level up
local function calculateEstimatedTime(elapsedTime, currentSkillPc, skillIncrease)
local skillPercentRemaining = 100 - currentSkillPc
local estimatedTotalTime = (elapsedTime / skillIncrease) * skillPercentRemaining
return estimatedTotalTime
end
START_TIME = START_TIME or os.time()
LAST_SKILL_PC = LAST_SKILL_PC or fishingpc()
local currentSkillPc = fishingpc()
if currentSkillPc > LAST_SKILL_PC then
local elapsedTime = os.time() - START_TIME
LAST_PREDICT = {
ELAPSED_TIME = elapsedTime,
ESTIMATED_TIME = calculateEstimatedTime(elapsedTime, currentSkillPc, currentSkillPc - LAST_SKILL_PC)
}
START_TIME = os.time()
LAST_SKILL_PC = fishingpc()
end
if LAST_PREDICT then
addtext("Time taken to increase fishing skill by 1%: " .. LAST_PREDICT.ELAPSED_TIME .. " seconds", 100, 100)
addtext("Estimated time to reach 100% skill: " .. LAST_PREDICT.ESTIMATED_TIME .. " seconds", 100, 125)
end
Posts: 7
Threads: 3
Joined: May 2024
Reputation:
0
06-22-2024, 04:29 PM
(This post was last modified: 06-22-2024, 04:34 PM by Yetoduiburit.)
I mixed this with some of your Hunting HUD code because I thought it looked better. I ended up with this:
--------------- START VARS ---------------
local clientwindow = { left = 350, top = 0 }
setfontcolor('white')
setpen('black', 2)
local yPos = 65
-- Calculates time to level
local function calculateEstimatedTime(elapsedTime, currentSkillPc, skillIncrease)
local skillPercentRemaining = 100 - currentSkillPc
local estimatedTotalTime = (elapsedTime / skillIncrease) * skillPercentRemaining
return estimatedTotalTime
end
-- Converts time in hours, minutes, seconds
local function formatTime(seconds)
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local secs = seconds % 60
return string.format("%02dh %02dm %02ds", hours, minutes, secs)
end
START_TIME = START_TIME or os.time()
LAST_SKILL_PC = LAST_SKILL_PC or swordpc()
local currentSkillPc = swordpc()
if currentSkillPc > LAST_SKILL_PC then
local elapsedTime = os.time() - START_TIME
LAST_PREDICT = {
ELAPSED_TIME = elapsedTime,
ESTIMATED_TIME = calculateEstimatedTime(elapsedTime, currentSkillPc, currentSkillPc - LAST_SKILL_PC)
}
START_TIME = os.time()
LAST_SKILL_PC = swordpc()
end
setfillcolor('#3d79b2')
addrect(clientwindow.left + 5, yPos, 190, 20)
addtextstroke('Skill Info', clientwindow.left + 45, yPos + 2)
yPos = yPos + 24
if LAST_PREDICT then
addtextstroke("Sword skill 1%: " .. formatTime(LAST_PREDICT.ELAPSED_TIME), clientwindow.left + 10, yPos)
yPos = yPos + 20
addtextstroke("Time for 100%: " .. formatTime(LAST_PREDICT.ESTIMATED_TIME), clientwindow.left + 10, yPos)
end
I also added a converter to show as hours, minutes, seconds. I was able to run this code and it worked fine, but now I restarted bot and it throws this error on console 03:25:03 - LUA Script -> Skills Info: 44: attempt to index a nil value (global 'LAST_PREDICT')
Any idea why?
--EDIT--
I analyzed your response and my code is missing the [if LAST_PREDICT then] before adding text. I added it to my code and its fixed, Ill leave the code here in case anyone wants to use it.
|