Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Random writeFloat problem

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Wed Aug 02, 2017 12:35 am    Post subject: Random writeFloat problem Reply with quote

Fairly straight forward script that I was sure to fix to my best ability:
Code:
[ENABLE]
{$lua}
--For negative integers, in lua,I used 4294967296-(value) in the calculations (4 bytes)
setGlobalKeyPollInterval(10)
setGlobalDelayBetweenHotkeyActivation(10)

if hk
   then hk.destroy()
end

local hk = createHotkey(function()

      player_xMouse = readFloat("[engine.dll+495468]")
      player_yMouse = readFloat("[engine.dll+495464]")
      player_xPos = readFloat("engine.CreateInterface+1AF8A8")
      player_yPos = readFloat("engine.CreateInterface+1AF8B0")
      player_zPos = readFloat("engine.CreateInterface+1AF8AC")
      rocket_xPos = readFloat("engine.CreateInterface+19D298")
      rocket_yPos = readFloat("engine.CreateInterface+19D2A0")
      rocket_zPos = readFloat("engine.CreateInterface+19D29C")

      Get3dDistance = math.sqrt(((player_xPos - rocket_xPos) * (player_xPos - rocket_xPos)) + ((player_yPos - rocket_yPos) * (player_yPos - rocket_yPos)) + ((player_zPos - rocket_zPos) * (player_zPos - rocket_zPos)))

      --Use the well known 3d distance formula to see how far 2 players are from each other
      --Almost every 3D game uses this formula. 2D games use a simpler variation
      function AimAtRocket(r_xPos, p_xPos, r_yPos, p_yPos, r_zPos, p_zPos, p_xMouse, p_yMouse)

               pitchX = math.asin((r_zPos - p_zPos) / Get3dDistance) * 180 / math.pi

               yawY = -(math.atan2(r_xPos - p_xPos, r_yPos - p_yPos) / math.pi * 180 + 180)

               --Set our  mouse values with our new YAW and PITCH
               print("yawY: " .. yawY .. " pitchX: " .. pitchX)
               writeFloat(p_xMouse, yawY) --Actually does nothing, however manually changing them produces correct effect
               writeFloat(p_yMouse, pitchX) --Actually does nothing, however manually changing them produces correct effect
      end

      AimAtRocket(rocket_xPos, player_xPos, rocket_yPos, player_yPos, rocket_zPos, player_zPos, player_xMouse, player_yMouse)

end, VK_SHIFT) --End of Hotkey Function, and assign d to activate the function.

-- If you don't want to affect all other hotkeys, just change this hotkey:
hk.DelayBetweenActivate = 1

{$asm}
//Start of Assembly Script
[DISABLE]
//End of  Assembly Script

Now, the unsolvable part is in the AimAtRocket function, which is supposed to set my player's aim to the desired aim, however, it does not, even though I can print the yawY and pitchX as correct Floats. I tried putting those lines outside the function, or replacing p_xMouse and p_yMouse with their corresponding actual address (replaced it with the origion xMouse), but to no avail.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Wed Aug 02, 2017 7:09 am    Post subject: Reply with quote

Code:
writeFloat(p_xMouse, yawY) --Actually does nothing, however manually changing them produces correct effect

Ok, what p_xMouse is? Looks like this variable doesn't hold an address.

_________________
Back to top
View user's profile Send private message MSN Messenger
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Wed Aug 02, 2017 2:11 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
Code:
writeFloat(p_xMouse, yawY) --Actually does nothing, however manually changing them produces correct effect

Ok, what p_xMouse is? Looks like this variable doesn't hold an address.

It's a parameter in the function, the parameter should be replaced by what is put in
Code:
AimAtTarget(parameter1,parameter2,parameter3,etc)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Aug 02, 2017 2:46 pm    Post subject: Reply with quote

Look at your code again.
Code:
-- player_xMouse is a float
player_xMouse = readFloat("[engine.dll+495468]")

-- player_xMouse passed as 7th parameter to function AimAtRocket
AimAtRocket(rocket_xPos, player_xPos, rocket_yPos, player_yPos, rocket_zPos, player_zPos, player_xMouse, player_yMouse)

-- 7th parameter is named p_xMouse
function AimAtRocket(r_xPos, p_xPos, r_yPos, p_yPos, r_zPos, p_zPos, p_xMouse, p_yMouse)

-- p_xMouse actually contains a float, not a pointer, so this fails
writeFloat(p_xMouse, yawY)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Wed Aug 02, 2017 2:58 pm    Post subject: Reply with quote

I don't understand what you mean, both p_xMouse and player_xMouse are floats, same with every other variable assigned like player_xMouse, so why would p_xMouse need to be a pointer if yawY is also a float? Unless writeFloat requires an address not a number.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Aug 02, 2017 3:09 pm    Post subject: Reply with quote

I take it you just copied and pasted that code from somewhere else without knowing what it does.

This documentation in celua.txt might help you:
Code:
writeFloat(address,value) : Writes a single precision floating point to the specified address.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Wed Aug 02, 2017 3:29 pm    Post subject: Reply with quote

ParkourPenguin wrote:
I take it you just copied and pasted that code from somewhere else without knowing what it does.

This documentation in celua.txt might help you:
Code:
writeFloat(address,value) : Writes a single precision floating point to the specified address.

Changed:
Code:
player_xMouse = "engine.dll+xxxx"
and now it works.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites