View previous topic :: View next topic |
Author |
Message |
sgsgwv$6263 Advanced Cheater Reputation: 0
Joined: 05 Aug 2020 Posts: 82
|
Posted: Tue Jan 14, 2025 2:38 am Post subject: lua code works only when I use print() |
|
|
Here is my code:
Code: |
{$lua}
[ENABLE]
local mov_speed=25
local jumpSpeed=20
x=getAddressList().getMemoryRecordByDescription("player x speed")
y=getAddressList().getMemoryRecordByDescription("player y speed")
z=getAddressList().getMemoryRecordByDescription("player z speed")
xd=getAddressList().getMemoryRecordByDescription("x speed down")
yd=getAddressList().getMemoryRecordByDescription("y speed down")
zd=getAddressList().getMemoryRecordByDescription("z speed down")
local upSpeed=jumpSpeed
function getUpSpeed(val,direction)
if direction == "up" then
if val>0 then
val=val*2
else
if val>-1 and val<0 then
val=1
else
val=val/2
end
end
else
if val<0 then
val=val*2
else
if val<1 then
val=-1
else
val=val/2
end
end
end
return val
end
hk=createHotkey(function()
r=(((x.Value)^2)+((y.Value)^2))^0.5
if r==0 then return end
ratio=mov_speed/r
x.Value=x.Value*ratio
y.Value=y.Value*ratio
end,0x26,0x10) -- up and shift at the same time
jump=createHotkey(function()
while not isKeyPressed(0x53) do
local xval=tonumber(x.Value)
local yval=tonumber(y.Value)
local zval=tonumber(z.Value)
local xdval=tonumber(xd.Value)
local ydval=tonumber(yd.Value)
local zdval=tonumber(zd.Value)
if tonumber(xval)==nil or tonumber(yval)==nil or tonumber(zval)==nil then
break
end
r=(((xval)^2)+((yval)^2))^0.5
if r==0 then return end
ratio=mov_speed/r
x.Value=xval*ratio
y.Value=yval*ratio
z.Value=upSpeed
-- below if works only when I insert print(xdval) here
if xdval~=nil then
local r=(((xdval)^2)+((ydval)^2))^0.5
if r==0 then return end
ratio=mov_speed/r
xd.Value=xdval*ratio
yd.Value=ydval*ratio
zd.Value=upSpeed
end
if isKeyPressed(0x55) then -- U
upSpeed=getUpSpeed(upSpeed,"up")
keyUp(0x55)
end
if isKeyPressed(0x44) then -- D
upSpeed=getUpSpeed(upSpeed,"down")
keyUp(0x44)
end
end
upSpeed=jumpSpeed
x.Value=0
y.Value=0
end,0x26,0x20) -- up and space at the same time
[DISABLE]
hk.destroy()
jump.destroy()
|
Here, it looks like `if xdval~=nil then` doesnot get executed at all. But surprisingly when I insert `print(xdval)` before that line, the same if condition gets executed perfecltly. This is wierd. I am not sure why is it happening? Can you some help me on this?
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 34
Joined: 16 Feb 2017 Posts: 1442
|
Posted: Wed Jan 15, 2025 8:16 am Post subject: |
|
|
Try this.
I also found it odd that you assigned the "r" below but used it independently above.
Code: | if xdval==nil then
print("'xdval' not found!")
print("'xdval' redefined!")
xdval=tonumber(xd.Value)
end
local r=(((xdval)^2)+((ydval)^2))^0.5
if r==0 then return end
ratio=mov_speed/r
xd.Value=xdval*ratio
yd.Value=ydval*ratio
zd.Value=upSpeed
--end |
_________________
|
|
Back to top |
|
|
sgsgwv$6263 Advanced Cheater Reputation: 0
Joined: 05 Aug 2020 Posts: 82
|
Posted: Sat Jan 18, 2025 12:18 am Post subject: |
|
|
Sorry, I forgot about this question.
Unfortunately that didn't solve the problem. Its hard to idemtify the issue because when you are trying to debug only then its working lol. I have faced this problem before in reactjs where request promise completed only when i debug it turns out the server sent the request first then did what it was supposed to do. It might be concurrency related issue but still at some point that xd.Value should be numeric string. I can tell you that it gets modifed but to a value that is unexpected.
Also r doesnot matter too much here.
I kinda solved the problem by using timers instead of loops inside hotkeys. That is my lesson from now on. Don't do long running tasks on hotkeys. Better to create timers and use hotkeys to enable or disable the timer.
|
|
Back to top |
|
|
daspamer Grandmaster Cheater Supreme Reputation: 54
Joined: 13 Sep 2011 Posts: 1584
|
Posted: Tue Jan 21, 2025 7:27 pm Post subject: |
|
|
Can you upload a table?
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
|
sgsgwv$6263 Advanced Cheater Reputation: 0
Joined: 05 Aug 2020 Posts: 82
|
Posted: Wed Jan 22, 2025 7:04 am Post subject: |
|
|
Hi daspamer, this is the cheat table.
Last edited by sgsgwv$6263 on Thu Jan 23, 2025 6:35 am; edited 1 time in total |
|
Back to top |
|
|
daspamer Grandmaster Cheater Supreme Reputation: 54
Joined: 13 Sep 2011 Posts: 1584
|
Posted: Wed Jan 22, 2025 3:13 pm Post subject: |
|
|
xdval is unknown.
Add local xdval above, or define xdval as local or with anything like nil or some value.
Did not test, but can remove the url.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
|
|