Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- http://stackoverflow.com/questions/20325332/how-to-check-if-two-tablesobjects-have-the-same-value-in-lua
- local function is_table_equal(t1,t2,ignore_mt)
- local ty1 = type(t1)
- local ty2 = type(t2)
- if ty1 ~= ty2 then return false end
- -- non-table types can be directly compared
- if ty1 ~= 'table' and ty2 ~= 'table' then return t1 == t2 end
- -- as well as tables which have the metamethod __eq
- local mt = getmetatable(t1)
- if not ignore_mt and mt and mt.__eq then return t1 == t2 end
- for k1,v1 in pairs(t1) do
- local v2 = t2[k1]
- if v2 == nil or not is_table_equal(v1,v2) then return false end
- end
- for k2,v2 in pairs(t2) do
- local v1 = t1[k2]
- if v1 == nil or not is_table_equal(v1,v2) then return false end
- end
- return true
- end
- function SavePartyToFile(party)
- local party_string = "{\"party\":["
- for k,v in ipairs(party) do
- party_string = party_string .. string.format("{\"id\":\"%s\",\"level\":\"%s\"}",party[k]['id'],party[k]['level']) .. ','
- end
- party_string = party_string:sub(1,-2)
- party_string = party_string .. "]}"
- local file = io.open("pokemon.json", "w")
- file:write(party_string)
- file:close()
- print("Party Saved.")
- end
- local party = {}
- -- http://datacrystal.romhacking.net/wiki/Pok%C3%A9mon_Red/Blue:RAM_map#Player
- local memory_addresses = {
- [1] = {["id"] = 0xD164, ["level"] = 0xD18C},
- [2] = {["id"] = 0xD165, ["level"] = 0xD1B8},
- [3] = {["id"] = 0xD166, ["level"] = 0xD1E4},
- [4] = {["id"] = 0xD167, ["level"] = 0xD210},
- [5] = {["id"] = 0xD168, ["level"] = 0xD23C},
- [6] = {["id"] = 0xD169, ["level"] = 0xD268}
- }
- -- http://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_index_number_(Generation_I)
- while true do
- local temp_party = {}
- for i = 1,6 do
- pokemon_id = memory.readbyte(memory_addresses[i]["id"])
- pokemon_level = memory.readbyte(memory_addresses[i]["level"])
- table.insert(temp_party, {["id"] = pokemon_id, ["level"] = pokemon_level})
- end
- if is_table_equal(party, temp_party) == false then
- party = temp_party
- print("Party changed: ")
- print(party)
- SavePartyToFile(party)
- end
- vba.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement