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 


Help with detection in a radius

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

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

PostPosted: Thu Jul 07, 2016 3:43 pm    Post subject: Help with detection in a radius Reply with quote

Hello, i've been trying to get a lua script to work that looks for if an object comes into an invisible area around the player, then when it does, it would attack, however I get no errors when injecting the script, but it doesn't do anything in game. (2d game) Also, I already have the pointers for p1x & ballx
Code:
bally = readInteger(getAddress("[ballcoords]+1c"))
ballx = readInteger(getAddress("[ballcoords]+18"))
p1y = readInteger(getAddress("[p1coords]+1c"))
p1x = readInteger(getAddress("[p1coords]+18"))
end
if isKeyPressed(VK_V) and ballx >= p1x-1000000 and ballx <= p1x+1000000 then
doKeyPress(VK_Z)
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4722

PostPosted: Thu Jul 07, 2016 4:03 pm    Post subject: Reply with quote

That first end should be an error if that's your entire code.

Use a timer if you want that code to be periodically run.

That call to getAddress isn't needed.

Also note that if the coordinate is a float, you should be using readFloat instead.

_________________
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: Thu Jul 07, 2016 4:07 pm    Post subject: Reply with quote

ParkourPenguin wrote:
That first end should be an error if that's your entire code.

Use a timer if you want that code to be periodically run.

That call to getAddress isn't needed.

Also note that if the coordinate is a float, you should be using readFloat instead.

It's not my entire code

Already run it in a timer, just didn't post cause so long

thnx

It's 4 byte
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4722

PostPosted: Thu Jul 07, 2016 4:24 pm    Post subject: Reply with quote

Forgot to mention this, but you should use both coordinates if you're checking for a radius (not just the x coordinate).
Code:
distance = math.sqrt((ballx-p1x)*(ballx-p1x)+(bally-p1y)*(bally-p1y))

You may want to use a hotkey instead.
Code:
createHotkey(function(hk)
    local dx = readInteger("[ballcoords]+18")-readInteger("[p1coords]+18")
    local dy = readInteger("[ballcoords]+1c")-readInteger("[p1coords]+1c")

    if math.sqrt(dx*dx+dy*dy) <= 1000000 then
      doKeyPress(VK_Z)
    end
  end, VK_V)

If nothing works, you should post more of your code, as there's nothing wrong with just that section AFAIK.

_________________
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: Fri Jul 08, 2016 2:17 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Forgot to mention this, but you should use both coordinates if you're checking for a radius (not just the x coordinate).
Code:
distance = math.sqrt((ballx-p1x)*(ballx-p1x)+(bally-p1y)*(bally-p1y))

You may want to use a hotkey instead.
Code:
createHotkey(function(hk)
    local dx = readInteger("[ballcoords]+18")-readInteger("[p1coords]+18")
    local dy = readInteger("[ballcoords]+1c")-readInteger("[p1coords]+1c")

    if math.sqrt(dx*dx+dy*dy) <= 1000000 then
      doKeyPress(VK_Z)
    end
  end, VK_V)

If nothing works, you should post more of your code, as there's nothing wrong with just that section AFAIK.

It works somewhat, but sadly in game since it checks for a radius it's checking both sides of the player.

Is there a way to make it automatically change directions (I have an address for direction of ball and player)

Is there a way for it to predict if it will come in contact with the radius? The ball can regularly (most of the time) move at speeds which make it impossible to see if the ball has moved into the radius, but there is a slight delay between the ball hitting a wall and bouncing back, so if you predict that it will come into contact, when it comes out of the delay from the wall you'll detect it.

It seems to be a bit laggy, not sure if it's just the game or something else (probably doesn't matter)

Is there somewhere I can learn this for myself? I don't want to trouble you constantly for instructions.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4722

PostPosted: Fri Jul 08, 2016 3:23 pm    Post subject: Reply with quote

Given a closed system, you can predict where the ball will be at any point in time. Unfortunately, any opponents could be an outside interference, but you should still be able to predict the ball's path in advance of it hitting you.

Lua isn't an incredibly fast language. If you need this script to run at something like 60 frames per second, you might not be able to hit the target if you're doing computationally expensive stuff (not to mention the resolution of a TTimer object). It seems like you aren't doing anything with regards to CE directly, so it may be better to do this in assembly by creating your own thread or hooking some instruction in the game executed every frame. If you really want to use Lua, don't use a timer or a hotkey. Instead, create a native thread, and call sleep from within it.

Regardless, if you have the direction the player is facing, it should be trivial to see if the player is facing towards the ball.
Code:
local dx = readInteger("[ballcoords]+18")-readInteger("[p1coords]+18")
if playerIsFacingLeft and dx < 0 then
  local dy = readInteger("[ballcoords]+1c")-readInteger("[p1coords]+1c")
  if math.sqrt(dx*dx+dy*dy) <= 1000000 then
    -- hit ball
  end
end


You already seem to have the basics of Lua down; however, you should learn more about the fundamentals behind what you're doing. In this case, that includes basic algebra and geometry. There are some physics concepts in here (i.e. position, speed, and velocity), but nothing too bad.

_________________
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: Sat Jul 09, 2016 12:40 am    Post subject: Reply with quote

ParkourPenguin wrote:
Given a closed system, you can predict where the ball will be at any point in time. Unfortunately, any opponents could be an outside interference, but you should still be able to predict the ball's path in advance of it hitting you.

Lua isn't an incredibly fast language. If you need this script to run at something like 60 frames per second, you might not be able to hit the target if you're doing computationally expensive stuff (not to mention the resolution of a TTimer object). It seems like you aren't doing anything with regards to CE directly, so it may be better to do this in assembly by creating your own thread or hooking some instruction in the game executed every frame. If you really want to use Lua, don't use a timer or a hotkey. Instead, create a native thread, and call sleep from within it.

Regardless, if you have the direction the player is facing, it should be trivial to see if the player is facing towards the ball.
Code:
local dx = readInteger("[ballcoords]+18")-readInteger("[p1coords]+18")
if playerIsFacingLeft and dx < 0 then
  local dy = readInteger("[ballcoords]+1c")-readInteger("[p1coords]+1c")
  if math.sqrt(dx*dx+dy*dy) <= 1000000 then
    -- hit ball
  end
end


You already seem to have the basics of Lua down; however, you should learn more about the fundamentals behind what you're doing. In this case, that includes basic algebra and geometry. There are some physics concepts in here (i.e. position, speed, and velocity), but nothing too bad.

The ball moves so fast to the point that it hits a wall instantly after the delay of hitting another wall, basically moves accross the screen in 1 frame.

I'm needing it to be frame-perfect, but oddly, i've been able to do that with my other scripts, and they've been more than frame perfect, although they only focused on one-two variables.

Not sure what you mean by n"you aren't doing anything with regards to CE directly"

Is there any website I can go to that I can learn more about assembly, i've only ever learned about lua.

Also, how would I code something that will do a key press to change the direction of the player relative to the ball? I'm thinking I could probably scan for if the player is facing left, and the ball is at a coord that is lower than the player, it would change direction to right, then scan for if the ball becomes a greater coord than the player. the direction of the ball is kinda messed so I can't use it, I have to use coords.

Lastly, for a possible prediction method, the ball always moves in at a set angle, each character in the game when they hit the ball, can apply a character specific "down/up" angle and this changes when in the air as well. The forward angle for every character doesn't change, as it's forward and that's it. I'm thinking that maybe when the ball goes into the delay when it hits a wall or when someone hits it (1-3 frames depending on speed of ball) the script could predict where the ball would go next on account of the certain angle applied, that way no matter how fast the ball goes, it will always know where it will be after a delay.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4722

PostPosted: Sat Jul 09, 2016 10:29 am    Post subject: Reply with quote

microsoftv wrote:
The ball moves so fast to the point that it hits a wall instantly after the delay of hitting another wall, basically moves accross the screen in 1 frame.
Here's a link that will help you with that:
http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
microsoftv wrote:
Not sure what you mean by n"you aren't doing anything with regards to CE directly"
It is easy to access CE-related stuff from Lua, but pretty hard to do so from the game. For example, creating a memory record.
microsoftv wrote:
Is there any website I can go to that I can learn more about assembly
Learning assembly is a process. While I did read and watch some tutorials, they didn't teach me everything I know. I learned mostly from trial and error. Any specific information I wanted I looked up in Intel's Software Developer's Manual, but I'm not sure I'd recommend that for a beginner.
microsoftv wrote:
how would I code something that will do a key press to change the direction of the player relative to the ball?
Why not just write to the address that determines which way you're facing?
microsoftv wrote:
Lastly, for a possible prediction method...
You don't need to do any of that. All you need is where the ball is now and where it will be in the next frame. I took a few minutes to look at a flash trial version of lethal league online (I'm assuming this topic is a continuation of this topic), and I found a pointer to exactly that in the same structure as the coordinates. Granted, you might need a code injection to predict it perfectly, but it simply may not be feasible to make a perfect triggerbot only using Lua.
_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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