Lua Click To Move Example menu

User Tag List

Results 1 to 2 of 2
  1. #1
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lua Click To Move Example

    This is how I've been sending clicks. The next step would be to have the waypoints in it's own file, but you get the idea. See my previous posts for more details about every/after because C_Timer functions will likely be in a different address space than your custom functions (Access Violation).

    Code:
    local arriveDist = 10
    local clicked = false
    
    function posToVector2()
    	local x, y, z = getPosition()
    	return {x = x, y = y}
    end
    
    function distance(x1, y1, x2, y2)
    	local dx = x1 - x2
    	local dy = y1 - y2
    	return math.sqrt(dx  * dx + dy * dy)
    end
    
    function checkDistance(dest)
    	local pos = posToVector2(getPosition())
    	return distance(dest.x, dest.y, pos.x, pos.y) < arriveDist
    end
    
    local i = 1
    
    local dests = {{x = -8951, y -905}, {x = -8979, y = -888}, {x = -9005, y = -883}}
    
    function moveNext()
    	print(checkDistance(dests[i]))
    	if not clicked then
    		clicked = true
    		ctm(dests[i].x, dests[i].y, 0)
    	elseif checkDistance(dests[i]) then
    		i = i + 1
    		clicked = false
    	end
    end
    
    every(500, 'moveNext')
    Register Handler
    Code:
    void LuaScript::RegisterHandler(string commandName, GameMethods::LuaCallback callback)
    {
    	GameMethods::Register(commandName.c_str(), LuaScript::WriteCallback(callback));
    }
    
    // not ideal but works
    GameMethods::LuaCallback LuaScript::WriteCallback(GameMethods::LuaCallback callback)
    {
    	static auto runOnce = true;
    
    	if (!runOnce)
    		return callback;
    
    	runOnce = false;
    
    	uintptr_t invalidPtrCheckMax = Offsets::Base + Offsets::InvalidPtrCheckMax;
    	uintptr_t invalidPtrCheckMin = Offsets::Base + Offsets::InvalidPtrCheckMin;
    	*reinterpret_cast<uintptr_t*>(invalidPtrCheckMax) = uintptr_t(callback) + 0x1000;  // doesn't have to be 1000 just enough space
    	*reinterpret_cast<uintptr_t*>(invalidPtrCheckMin) = 2;
    
    	return callback;
    }
    Click To Move
    Code:
    int LuaScript::ClickToMove(int64_t luaState)
    {
    	if (!Player)
    		return 1;
    
    	int x = GameMethods::ToNumber(luaState, 1);
    	int y = GameMethods::ToNumber(luaState, 2);
    	int z = GameMethods::ToNumber(luaState, 3);
    
    	Vector3 position = Vector3(x, y, z);
    
    	GameMethods::ClickToMove(Player->Ptr(), position);
    
    	SetHardwareEvent();
    
    	return 1;
    }
    After and Every (tick After)
    Code:
    int LuaScript::ExecuteAfterMS(int64_t luaState)
    {
    	auto delay = GameMethods::ToNumber(luaState, 1);
    	auto function = GameMethods::ToLString(luaState, 2, nullptr) + "()";
    
    	if (delay <= 0)
    		return 1;
    
    	LuaBase::Input(function, delay);
    
    	return 1;
    }
    
    int LuaScript::ExecuteEveryMS(int64_t luaState)
    {
    	auto sleepTime = GameMethods::ToNumber(luaState, 1);
    	auto function = GameMethods::ToLString(luaState, 2, nullptr);
    
    	string functionRepeater = "function " + function + "Repeater() " + function + "() after(" + to_string(sleepTime) + ", '" + function + "Repeater') end " + function + "Repeater()";
    
    	LuaBase::Input(functionRepeater, 0);
    
    	return 1;
    }
    Get Position
    Code:
    int LuaScript::GetPlayerPosition(int64_t luaState)
    {
    	SetPlayer();
    
    	GameMethods::PushNumber(luaState, Player->GetUnitPosition(0, 0).X);
    	GameMethods::PushNumber(luaState, Player->GetUnitPosition(0, 0).Y);
    	GameMethods::PushNumber(luaState, Player->GetUnitPosition(0, 0).Z);
    
    	return 3;
    }

    Lua Click To Move Example
  2. Thanks Augury13, Valldex (2 members gave Thanks to GlittPrizes for this useful post)
  3. #2
    GlittPrizes's Avatar Active Member CoreCoins Purchaser Authenticator enabled
    Reputation
    58
    Join Date
    Nov 2019
    Posts
    104
    Thanks G/R
    53/33
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update

    You can do this without all the duplication, but I like to just do it meticulously for a dungeon.

    Code:
    local LOAD_SCREEN_TIME = 6.0    -- or monitor the game flag instead
    
    local IDLE = 0
    local ATTACKING = 1
    local BUSY = 2
    
    local AOE = 1
    local MOUNT = 3
    
    local State = IDLE
    local Debug = true
    local step = 1
    
    local arriveDist = 2
    
    function moveNext(x, y)
    	Cpp(CLICK_TO_MOVE, x, y, -50)
    	if Debug and checkDistance(x, y) then
    		print(step)
    		step = step + 1
    		return true
    	end
    	return false
    end
    
    function checkDistance(x, y)
    	local pos = posToVector2()
    	return distance(x, y, pos.x, pos.y) < arriveDist
    end
    
    function distance(x1, y1, x2, y2)
    	local dx = x1 - x2
    	local dy = y1 - y2
    	return math.sqrt(dx  * dx + dy * dy)
    end
    
    function posToVector2()
    	local x, y, z = Cpp(GET_POSITION)
    	return {x = x, y = y}
    end
    
    function aoe()
    	UseAction(AOE)
    end
    
    function attack()
    	State = ATTACKING
    	aoe()
    	C_Timer.After(1.1, aoe)
    	C_Timer.After(2.2, aoe)
    	C_Timer.After(3.1, stopAction)
    end
    
    function doLoot()
    	State = BUSY
    	moveStop()
    	C_Timer.After(1.3, loot)
    	C_Timer.After(4.5, loot)
    	C_Timer.After(5.9, stopAction)
    end
    
    function loot()
    	UseAction(BUSY)
    end
    
    function mount()
    	UseAction(MOUNT)
    end
    
    function moveStop()
    	x, y, z = Cpp(GET_POSITION)
    	Cpp(CLICK_TO_MOVE, x, y, z)
    end
    
    function stopAction()
    	State = IDLE
    end
    
    function sell()
    	local englishFaction, localizedFaction = UnitFactionGroup('player')
    	if englishFaction == "Alliance" then
    		InteractUnit('Gnimo')
    	else
    		InteractUnit('Drix Blackwrench')
    	end
    end
    
    function shouldVendor()
    	local numFreeSlotsBackpack, bagType = GetContainerNumFreeSlots(0)
    	local numFreeSlotsBag1, bagType = GetContainerNumFreeSlots(1)
    	local numFreeSlotsBag2, bagType = GetContainerNumFreeSlots(2)
    	local numFreeSlotsBag3, bagType = GetContainerNumFreeSlots(3)
    	local numFreeSlotsBag4, bagType = GetContainerNumFreeSlots(4)
    	return (numFreeSlotsBackpack + numFreeSlotsBag1 + numFreeSlotsBag2 + numFreeSlotsBag3 + numFreeSlotsBag4) < 30
    end
    
    function profile()
    	while RUN do
    		while RUN and not moveNext(-237.33, 59.56) do coroutine.yield() end
                    -- ...
    
    		attack()
    
    		while State == ATTACKING do
    			coroutine.yield()
    		end
    
    		doLoot()
    
    		while State == BUSY do
    			coroutine.yield()
    		end
    
    		while RUN and not moveNext(-228.31, 197.90) do coroutine.yield() end 
                   -- more ctm nav
    
    		C_Timer.After(6.0, JumpOrAscendStart)
    
                  -- rinse and repeat on a C_Timer ticker.

Similar Threads

  1. [Hack] Guardians CTM Teleporter (Click to move)
    By The-Guardian in forum WoW EMU Programs
    Replies: 95
    Last Post: 06-09-2020, 02:50 PM
  2. Click to Move - Explained
    By Apoc in forum WoW Memory Editing
    Replies: 33
    Last Post: 01-19-2010, 07:28 AM
  3. [3.2] Click To Move
    By Kamuuk in forum WoW Memory Editing
    Replies: 25
    Last Post: 08-22-2009, 10:59 AM
  4. Click to move?
    By ashleyww in forum WoW Memory Editing
    Replies: 32
    Last Post: 07-18-2009, 08:48 PM
  5. Click to Move Problem
    By Rival-Fr in forum WoW Memory Editing
    Replies: 5
    Last Post: 07-03-2009, 09:27 AM
All times are GMT -5. The time now is 12:29 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search