mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-10-19 14:13:27 +02:00
Version 0.99 BETA
This commit is contained in:
@@ -10,6 +10,7 @@ walkLock = 0
|
||||
lastWalk = 0
|
||||
lastTurn = 0
|
||||
lastTurnDirection = 0
|
||||
turnKeys = {}
|
||||
|
||||
function init()
|
||||
connect(LocalPlayer, {
|
||||
@@ -147,6 +148,7 @@ function unbindWalkKey(key)
|
||||
end
|
||||
|
||||
function bindTurnKey(key, dir)
|
||||
turnKeys[key] = dir
|
||||
local gameRootPanel = modules.game_interface.getRootPanel()
|
||||
g_keyboard.bindKeyDown(key, function() turn(dir, false) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress(key, function() turn(dir, true) end, gameRootPanel)
|
||||
@@ -154,6 +156,7 @@ function bindTurnKey(key, dir)
|
||||
end
|
||||
|
||||
function unbindTurnKey(key)
|
||||
turnKeys[key] = nil
|
||||
local gameRootPanel = modules.game_interface.getRootPanel()
|
||||
g_keyboard.unbindKeyDown(key, gameRootPanel)
|
||||
g_keyboard.unbindKeyPress(key, gameRootPanel)
|
||||
@@ -197,12 +200,14 @@ function changeWalkDir(dir, pop)
|
||||
end
|
||||
|
||||
function smartWalk(dir)
|
||||
if g_keyboard.getModifiers() == KeyboardNoModifier then
|
||||
local direction = smartWalkDir or dir
|
||||
walk(direction)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
scheduleEvent(function()
|
||||
if g_keyboard.getModifiers() == KeyboardNoModifier then
|
||||
local direction = smartWalkDir or dir
|
||||
walk(direction)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end, 20)
|
||||
end
|
||||
|
||||
function canChangeFloorDown(pos)
|
||||
@@ -265,6 +270,7 @@ function walk(dir)
|
||||
end
|
||||
|
||||
if player:isWalkLocked() then
|
||||
nextWalkDir = nil
|
||||
return
|
||||
end
|
||||
|
||||
@@ -273,11 +279,16 @@ function walk(dir)
|
||||
if ticksToNextWalk < 500 and lastWalkDir ~= dir then
|
||||
nextWalkDir = dir
|
||||
end
|
||||
if ticksToNextWalk < 20 and lastFinishedStep + 400 > g_clock.millis() and nextWalkDir == nil then -- clicked walk 20 ms too early, try to execute again as soon possible to keep smooth walking
|
||||
if ticksToNextWalk < 30 and lastFinishedStep + 400 > g_clock.millis() and nextWalkDir == nil then -- clicked walk 20 ms too early, try to execute again as soon possible to keep smooth walking
|
||||
nextWalkDir = dir
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
--if nextWalkDir ~= nil and lastFinishedStep + 200 < g_clock.millis() then
|
||||
-- print("Cancel " .. nextWalkDir)
|
||||
-- nextWalkDir = nil
|
||||
--end
|
||||
|
||||
if nextWalkDir ~= nil and nextWalkDir ~= lastWalkDir then
|
||||
dir = nextWalkDir
|
||||
@@ -308,6 +319,7 @@ function walk(dir)
|
||||
local toTile = g_map.getTile(toPos)
|
||||
|
||||
if walkLock >= g_clock.millis() and lastWalkDir == dir then
|
||||
nextWalkDir = nil
|
||||
return
|
||||
end
|
||||
|
||||
@@ -346,13 +358,28 @@ function walk(dir)
|
||||
end
|
||||
|
||||
function turn(dir, repeated)
|
||||
if not repeated or (lastTurnDirection == dir and lastTurn + 50 < g_clock.millis()) then
|
||||
local player = g_game.getLocalPlayer()
|
||||
if player:isWalking() and player:getWalkDirection() == dir then
|
||||
return
|
||||
end
|
||||
|
||||
if not repeated or (lastTurn + 100 < g_clock.millis()) then
|
||||
g_game.turn(dir)
|
||||
changeWalkDir(dir)
|
||||
lastTurn = g_clock.millis()
|
||||
if not repeated then
|
||||
lastTurn = g_clock.millis() + 200
|
||||
lastTurn = g_clock.millis() + 50
|
||||
end
|
||||
lastTurnDirection = dir
|
||||
nextWalkDir = nil
|
||||
player:lockWalk(150)
|
||||
end
|
||||
end
|
||||
|
||||
function checkTurn()
|
||||
for keys, direction in pairs(turnKeys) do
|
||||
if g_keyboard.areKeysPressed(keys) then
|
||||
turn(direction, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user