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 


if/then loop to check if value has increased or decreased

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

Joined: 16 Apr 2013
Posts: 97

PostPosted: Mon Apr 18, 2022 7:30 pm    Post subject: if/then loop to check if value has increased or decreased Reply with quote

I'm trying to make an if/then loop that monitors the players health and constantly checks if the value has increased or decreased from the previous value. If it decreases, I want to shrink my player by a certain amount. If it increases, grow my player. I can get it to work some of the time, but not consistently. Also, sometimes it does the opposite - grows when it should shrink. I think I'm getting confused on where to put the health variables. In case you're wondering why I used the for loop, it's so the player grows/shrinks smoothly. Any help would be greatly appreciated.

Code:
[ENABLE]
{$lua}

if syntaxcheck then return end

test = getAddress("[scale]+20C")
test1 = getAddress("[scale]+210")
test2 = getAddress("[scale]+214")
aHealth = readInteger"[phealth]"
bHealth = readInteger"[phealth]"

function fc_loop(thr_obj)
  while fc_loop_running == true
  do
    aHealth = readInteger"[phealth]"
    bHealth = readInteger"[phealth]"
    if bHealth > aHealth then
       xscale = readFloat"[scale]+20C"
       yscale = readFloat"[scale]+210"
       zscale = readFloat"[scale]+214"
       for i = 0.1,0.5,0.0008
       do
       writeFloat(test,xscale+i)
       writeFloat(test1,yscale+i)
       writeFloat(test2,zscale+i)
       --if i > 0.5 then break end
       --sleep(10)
       aHealth = readInteger"[phealth]"
       bHealth = readInteger"[phealth]"
       end
    else
    if bHealth < aHealth then
       xscale = readFloat"[scale]+20C"
       yscale = readFloat"[scale]+210"
       zscale = readFloat"[scale]+214"
       for i = 0.1,0.4,0.0008
       do
       writeFloat(test,xscale+i*-1)
       writeFloat(test1,yscale+i*-1)
       writeFloat(test2,zscale+i*-1)
       --if i > 0.5 then break end
       --sleep(10)
       aHealth = readInteger"[phealth]"
       bHealth = readInteger"[phealth]"
       end
    end
    end
    bHealth = readInteger"[phealth]"
  end
end


fc_loop_running = true
fc_thread = createThread(fc_loop)


[DISABLE]
{$lua}
fc_loop_running = false
fc_thread = nil
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Tue Apr 19, 2022 1:03 am    Post subject: Reply with quote

Just for a different idea;

Code:
[ENABLE]
{$lua}

if syntaxcheck then return end

test = getAddress("[scale]+20C")
test1 = getAddress("[scale]+210")
test2 = getAddress("[scale]+214")
aHealth = readInteger"[phealth]"
bHealth = readInteger"[phealth]"

function fc_loop(thr_obj)
  while fc_loop_running == true
  do
    aHealth = readInteger"[phealth]"
    bHealth = readInteger"[phealth]"
    if bHealth > aHealth then
       xscale = readFloat"[scale]+20C"
       yscale = readFloat"[scale]+210"
       zscale = readFloat"[scale]+214"
       i1 = 0.1
       i2 = 0.5
       i3 = 0.0008

       writeFloat(test,xscale+i1)
       writeFloat(test1,yscale+i2)
       writeFloat(test2,zscale+i3)
       --if i > 0.5 then break end
       --sleep(10)
       aHealth = readInteger"[phealth]"
       bHealth = readInteger"[phealth]"
    end
    --else
    if bHealth < aHealth then
       xscale = readFloat"[scale]+20C"
       yscale = readFloat"[scale]+210"
       zscale = readFloat"[scale]+214"
       i1 = 0.1
       i2 = 0.4
       i3 = 0.0008
       writeFloat(test,xscale+i1*-1)
       writeFloat(test1,yscale+i2*-1)
       writeFloat(test2,zscale+i3*-1)
       --if i > 0.5 then break end
       --sleep(10)
       aHealth = readInteger"[phealth]"
       bHealth = readInteger"[phealth]"
       end
    end
    bHealth = readInteger"[phealth]"
end



fc_loop_running = true
fc_thread = createThread(fc_loop)


{$asm}

[DISABLE]
{$lua}
fc_loop_running = false
fc_thread = nil

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Tue Apr 19, 2022 1:23 pm    Post subject: Reply with quote

Thanks! With this solution, looks as though the scales won't be scaled proportionally. xyz equates to height width depth of the character. My variable naming may have made that confusing.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Tue Apr 19, 2022 2:47 pm    Post subject: Reply with quote

I just gave an example of "if" in the code.

Because there are too many undefined in the code
Code:
[scale] --undefined!
[phealth] --undefined!


And it's like comparing the same query;
Code:
    aHealth = readInteger"[phealth]"
    bHealth = readInteger"[phealth]"
    if bHealth > aHealth then


I assumed they fixed them and just focused on the test code.

The code will not test in its current state.
Because you are comparing two same (equal) values.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Drivium
Advanced Cheater
Reputation: 0

Joined: 16 Apr 2013
Posts: 97

PostPosted: Tue Apr 19, 2022 4:04 pm    Post subject: Reply with quote

I was thinking I needed to capture and store the value so the current value can compare against the previous value. I'm thinking my variables may be incorrect. Your method of breaking the if statement into 2 parts as opposed to a single if may help.
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