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 


How would I add a value?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Sk4terd
How do I cheat?
Reputation: 0

Joined: 05 Nov 2016
Posts: 3
Location: Dust ll

PostPosted: Sat Nov 05, 2016 11:02 pm    Post subject: How would I add a value? Reply with quote

I get an Error for XP on line 7 and I don't know why. I'm not the smartest when it comes to lua though, I also got the base code from somewhere else on this forum.
I am wanting it to give xp while the script is toggled on.

Code:
 timer = createTimer(nil, true)
timer_setInterval(timer, 100)

function XP_Spam()
if (getOpenedProcessID() ~= 0) then
local XP = readInteger('[[[[["Borderlands2.exe"+01EEE798]+6c]+1a8]+668]+19c]+2c')
local AddedXP = XP + 1000
writeInteger('[[[[["Borderlands2.exe"+01EEE798]+6c]+1a8]+668]+19c]+2c', AddedXP)
end
end

timer_onTimer(timer, XP_Spam)
Back to top
View user's profile Send private message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Sun Nov 06, 2016 2:28 am    Post subject: Reply with quote

What does your error message say? (it should specify that something is expected on line 7)

Seems fine to me, I executed your script as it is & no errors were thrown.
Back to top
View user's profile Send private message
Sk4terd
How do I cheat?
Reputation: 0

Joined: 05 Nov 2016
Posts: 3
Location: Dust ll

PostPosted: Sun Nov 06, 2016 2:44 am    Post subject: Reply with quote

Error:[string " timer = createTimer(nil, true)
..."]:7: attempt to perform arithmetic on a nil value (local 'XP')
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Sun Nov 06, 2016 4:58 am    Post subject: Reply with quote

readInteger will return a number if the address is readable, but return nothing when the address is not readable, setting a variable (XP) with nothing will set it as nil.
nil in Lua is not a number, and cannot make arithmetic with other number, so the error.

Try check if the pointer address is valid.

To handle the error in the OnTimer function, try like:
Code:

function XP_Spam()
  if (getOpenedProcessID() ~= 0) then
    local addr = '[[[[["Borderlands2.exe"+01EEE798]+6c]+1a8]+668]+19c]+2c'
    local XP = readInteger(addr)
    if XP~=nil then
      local AddedXP = XP + 1000
      writeInteger(addr, AddedXP)
      GetMainForm().Caption = "xp now:"..AddedXP
    else
      GetMainForm().Caption = addr..' Not Readable' -- not print, may be some other ui
    end
  end
end


bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
Sk4terd
How do I cheat?
Reputation: 0

Joined: 05 Nov 2016
Posts: 3
Location: Dust ll

PostPosted: Sun Nov 06, 2016 1:43 pm    Post subject: Reply with quote

I put the offsets in backwards, I didn't know that was a thing, sorry.
Thanks for the code though, it helps.

Code:
 timer = createTimer(nil, true)
timer_setInterval(timer, 1)

function XP_Spam()
  if (getOpenedProcessID() ~= 0) then
    local addr = '[[[[["Borderlands2.exe"+01EEE798]+2c]+19c]+668]+1a8]+6c'
    local XP = readInteger(addr)
    if XP~=nil then
      local AddedXP = XP + 250
      writeInteger(addr, AddedXP)
      GetMainForm().Caption = "xp now:"..AddedXP
    else
      GetMainForm().Caption = addr..' Not Readable' -- not print, may be some other ui
    end
  end
end

timer_onTimer(timer, XP_Spam)
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