Untitled
unknown
plain_text
a year ago
7.0 kB
9
Indexable
local attackDelay=GetModConfigData("Default_attackdelay")
local moveDelay=GetModConfigData("Default_movedelay")
--local ping=0
local function IsDefaultScreen()
local screen = GLOBAL.TheFrontEnd:GetActiveScreen()
local screenName = screen and screen.name or ""
return screenName:find("HUD") ~= nil
end
local function GetTarget(targettype)
local player = GLOBAL.ThePlayer
local playercontroller = player.components.playercontroller
local x, y, z = playercontroller.inst.Transform:GetWorldPosition()
local combat = playercontroller.inst.replica.combat
local attackRange = combat:GetAttackRangeWithWeapon()
local entities=GLOBAL.TheSim:FindEntities(x, y, z, attackRange + 10, {targettype})
GLOBAL.table.sort(entities, function(a, b)
local qeueu={}
local A = qeueu[a.GUID]
local B = qeueu[b.GUID]
return (A and not B) or ((A or not B) and player:GetDistanceSqToInst(a) < player:GetDistanceSqToInst(b))
end)
for _, entity in ipairs(entities) do
if entity and entity:IsValid() and entity.replica.health ~= nil and not entity.replica.health:IsDead() and GLOBAL.ThePlayer.replica.combat:CanTarget(entity) then
return entity
end
end
return nil
end
local function Attack(target)
local playeractionpicker = GLOBAL.ThePlayer.components.playeractionpicker
local playercontroller = GLOBAL.ThePlayer.components.playercontroller
if target == nil or not target:IsValid() or target.replica.health == nil or target.replica.health:IsDead() or not GLOBAL.ThePlayer.replica.combat:CanTarget(target) then
return false
end
local tx,ty,tz = target:GetPosition():Get()
local px,py,pz = GLOBAL.ThePlayer:GetPosition():Get()
if tx==px and tz==pz then
tx=tx+0.1 tz=tz+0.1
end
local distance = GLOBAL.math.sqrt((px-tx)*(px-tx)+(pz-tz)*(pz-tz))
local range = GLOBAL.ThePlayer.components.playercontroller.inst.replica.combat:GetAttackRangeWithWeapon()+target:GetPhysicsRadius(0)
if GLOBAL.ThePlayer.components.playercontroller:CanLocomote() then
if distance > range-0.2 or target:HasTag("butterfly") and distance > 0.5 then
local playercontroller = GLOBAL.ThePlayer.components.playercontroller
local action = GLOBAL.BufferedAction(playercontroller.inst,nil,GLOBAL.ACTIONS.WALKTO,nil,GLOBAL.Vector3(tx,0,tz))
playercontroller:DoAction(action)
GLOBAL.Sleep((20) * 0.001)
return false
end
else
if distance > range or target:HasTag("butterfly") and distance > 1.5 then
GLOBAL.SendRPCToServer(GLOBAL.RPC.LeftClick, GLOBAL.ACTIONS.WALKTO.code, tx,tz, nil, true, nil, nil, nil)
GLOBAL.Sleep((20) * 0.001)
return false
end
end
if GLOBAL.ThePlayer.components.playercontroller:CanLocomote() then
local act = playeractionpicker:GetLeftClickActions(target:GetPosition(), target)[1]
if act == nil then
return false
end
act.preview_cb = function()
GLOBAL.SendRPCToServer(GLOBAL.RPC.PredictWalking, px, pz, true)
GLOBAL.SendRPCToServer(GLOBAL.RPC.LeftClick,GLOBAL.ACTIONS.ATTACK.code,px,pz,target,true,10,nil,nil)
end
playercontroller:DoAction(act)
else
GLOBAL.SendRPCToServer(GLOBAL.RPC.PredictWalking, px, pz, true)
GLOBAL.SendRPCToServer(GLOBAL.RPC.LeftClick,GLOBAL.ACTIONS.ATTACK.code,px,pz,target,true,10,nil,nil)
end
GLOBAL.Sleep((attackDelay) * 0.001)
return true
end
local function Move(target)
local tx,ty,tz = target:GetPosition():Get()
local px,py,pz = GLOBAL.ThePlayer:GetPosition():Get()
if tx==px and tz==pz then
tx=tx+0.1 tz=tz+0.1
end
local distance = GLOBAL.math.sqrt((px-tx)*(px-tx)+(pz-tz)*(pz-tz))
if distance ==0 then distance =0.1 tx= tx+0.1 end
if GLOBAL.ThePlayer.components.playercontroller:CanLocomote() then
local playercontroller = GLOBAL.ThePlayer.components.playercontroller
local action = GLOBAL.BufferedAction(playercontroller.inst,nil,GLOBAL.ACTIONS.WALKTO,nil,GLOBAL.Vector3(px+(px-tx)/distance,0,pz+(pz-tz)/distance))
playercontroller:DoAction(action)
else
GLOBAL.SendRPCToServer(GLOBAL.RPC.PredictWalking, px+(px-tx)/distance, pz+(pz-tz)/distance, true)
GLOBAL.SendRPCToServer(GLOBAL.RPC.LeftClick, GLOBAL.ACTIONS.WALKTO.code, px+(px-tx)/distance,pz+(pz-tz)/distance, nil, true, nil, nil, nil)
end
GLOBAL.Sleep(0.001*moveDelay)
end
local function Start()
if IsDefaultScreen() and GLOBAL.ThePlayer ~= nil and GLOBAL.ThePlayer.Cheatthread == nil then
if GLOBAL.ThePlayer.components.playercontroller.inst.replica.combat:GetWeapon() == nil then
GLOBAL.ThePlayer.components.playercontroller:DoAttackButton()
return
end
GLOBAL.ThePlayer.Cheatthread = GLOBAL.ThePlayer:StartThread(function()
--ping = GLOBAL.TheNet:GetAveragePing()
while true do
GLOBAL.Sleep(0.01)
local target = GetTarget("monster")
if target == nil then
target = GetTarget("_combat")
end
if target == nil then
target = GLOBAL.ThePlayer.components.playercontroller:GetAttackTarget(true,nil,nil)
end
if target ~= nil then
while Attack(target) do
Move(target)
end
end
end
end)
end
end
local function Stop()
if IsDefaultScreen() and GLOBAL.ThePlayer ~= nil and GLOBAL.ThePlayer.Cheatthread ~= nil then
GLOBAL.ThePlayer.Cheatthread:SetList(nil)
GLOBAL.ThePlayer.Cheatthread = nil
end
end
local function GetKeyFromConfig(config)
local key = GetModConfigData(config, true)
if type(key) == "string" and GLOBAL:rawget(key) then
key = GLOBAL[key]
end
return type(key) == "number" and key or -1
end
if GetKeyFromConfig("Addattackdelay_key") then
GLOBAL.TheInput:AddKeyUpHandler(GetKeyFromConfig("Addattackdelay_key"), function()
if IsDefaultScreen() then
attackDelay = attackDelay + 2
GLOBAL.print("attackdelay="..GLOBAL.tostring(attackDelay))
end
end)
end
if GetKeyFromConfig("Reduceattackdelay_key") then
GLOBAL.TheInput:AddKeyUpHandler(GetKeyFromConfig("Reduceattackdelay_key"), function()
if IsDefaultScreen() then
attackDelay = attackDelay - 2
GLOBAL.print("attackdelay="..GLOBAL.tostring(attackDelay))
end
end)
end
if GetKeyFromConfig("Addmovedelay_key") then
GLOBAL.TheInput:AddKeyUpHandler(GetKeyFromConfig("Addmovedelay_key"), function()
if IsDefaultScreen() then
moveDelay = moveDelay + 2
GLOBAL.print("movedelay="..GLOBAL.tostring(moveDelay))
end
end)
end
if GetKeyFromConfig("Reducemovedelay_key") then
GLOBAL.TheInput:AddKeyUpHandler(GetKeyFromConfig("Reducemovedelay_key"), function()
if IsDefaultScreen() then
moveDelay = moveDelay - 2
GLOBAL.print("movedelay="..GLOBAL.tostring(moveDelay))
end
end)
end
if GetKeyFromConfig("Attack_key") then
GLOBAL.TheInput:AddKeyUpHandler(GetKeyFromConfig("Attack_key"), Stop)
GLOBAL.TheInput:AddKeyDownHandler(GetKeyFromConfig("Attack_key"), Start)
endEditor is loading...
Leave a Comment