Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw;
- local sg
- local chest
- local AUTO_UPDATE = false
- local SG_WRAP_TRY_SLEEP = 5
- local BAD_ADDRESS_SLEEP = 3
- local SU_RF_CONVERSION = 80
- local BASE_RF = 1000000
- local REDSTONE_PER_BASE_RF = 4
- local PAYMENT_ITEM_NAME = 'redstone'
- local PAYMENT_TIMOUT_SECONDS = 120
- local PAYMENT_CHECK_SLEEP_LOOP = 5
- local TRASH_DIRECTION = 'south'
- local ENDER_CHEST_DIRECTION = 'down'
- local CHEST_WRAP = 'bottom'
- local TIME_VORTEX_ACTIVATION_SECONDS = 12
- local PASTE_CODE = 'rc5RBMYA'
- local FILE_PATH = 'controller'
- -- Free adresses
- local FREE_ADRESSES = {}
- FREE_ADRESSES[#FREE_ADRESSES + 1] = 'CQTA-103-2Q' -- Warp minage
- FREE_ADRESSES[#FREE_ADRESSES + 1] = '0SFE-TCI-SV' -- Spawn
- function is_elem_in_list(list, elem)
- local i
- i = 1
- while i <= #list do
- if list[i] == elem then
- return true
- end
- i = i + 1
- end
- return false
- end
- function get_trash_orientation()
- local addr
- addr = sg.localAddress()
- if addr == '1XABWDJZL' then
- TRASH_DIRECTION = 'south'
- end
- end
- function init()
- if AUTO_UPDATE then
- print('Checking updates...')
- if not update() then
- print('Failed to update.')
- else
- print('Updated successfully.')
- end
- end
- sg = peripheral.find('stargate')
- while not sg do
- print('Stargate not found.')
- sleep(SG_WRAP_TRY_SLEEP)
- sg = peripheral.find('stargate')
- end
- --get_trash_orientation()
- --chest = peripheral.wrap(CHEST_WRAP)
- --[[if not chest then
- print('Error, can\'t wrap chest')
- read()
- os.reboot()
- end]]
- print('Switching to FR language...')
- end
- function update()
- local response
- local sResponse
- local file
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(PASTE_CODE))
- if not response then
- return false
- end
- sResponse = response.readAll()
- response.close()
- file = fs.open(FILE_PATH, "w")
- file.write(sResponse)
- file.close()
- return true
- end
- function check_input(str, type, free)
- if not str then
- return false
- end
- if type == 'address' then
- --[[if true then
- if (sg.localAddress() == '1XABWDJZL' and str == 'THE_REDCRAFT_PRTOX76') or
- (sg.localAddress() == 'CTIPV3SCJ' and str == 'patronus') or
- str == 'HOYOHOYO' then
- if free then
- print('Code deja utilise.')
- return false
- end
- return 1
- end]]
- if not sg.energyToDial(str) or tonumber(sg.energyToDial(str)) <= 4000 then
- print('Adresse invalide.')
- sleep(BAD_ADDRESS_SLEEP)
- return false
- elseif sg.energyAvailable() < tonumber(sg.energyToDial(str)) then
- print('Pas assez d\'energie, (' .. math.floor((sg.energyAvailable() * 100) / tonumber(sg.energyToDial(str))) .. '% de l\'energie requise')
- return false
- end
- elseif type == 'confirmation' then
- str = str:lower()
- if str ~= 'o' and str ~= 'oui' and str ~= 'y' and str ~= 'yes' then
- return false
- end
- end
- return true
- end
- function is_payment_done()
- local slot
- local data
- local amount
- slot = chest.getInventorySize()
- amount = 0
- chest.condenseItems()
- while slot > 0 do
- data = chest.getStackInSlot(slot)
- if data and data.name == PAYMENT_ITEM_NAME then
- amount = amount + data.qty
- elseif data then
- chest.pushItem(TRASH_DIRECTION, slot)
- end
- slot = slot - 1
- end
- return amount
- end
- function push_payment()
- local slot
- local data
- slot = chest.getInventorySize()
- chest.condenseItems()
- while slot > 0 do
- data = chest.getStackInSlot(slot)
- if data and data.name == PAYMENT_ITEM_NAME then
- chest.pushItem(ENDER_CHEST_DIRECTION, slot)
- elseif data then
- chest.pushItem(TRASH_DIRECTION, slot)
- end
- slot = slot - 1
- end
- return amount
- end
- function check_payment(amount)
- local time
- local tmp
- time = 0
- while time < PAYMENT_TIMOUT_SECONDS do
- tmp = is_payment_done()
- if tmp >= amount then
- print('Paiement accepte.')
- return true
- end
- print('Payment: ' .. tmp .. '/' .. amount .. ' ' .. PAYMENT_ITEM_NAME)
- time = time + PAYMENT_CHECK_SLEEP_LOOP
- sleep(PAYMENT_CHECK_SLEEP_LOOP)
- end
- return false
- end
- function trade(address)
- local redstone_amount
- if is_elem_in_list(FREE_ADRESSES, address) then
- return true
- end
- redstone_amount = ((sg.energyToDial(address) * SU_RF_CONVERSION * REDSTONE_PER_BASE_RF)/ BASE_RF)
- if ((sg.energyToDial(address) * SU_RF_CONVERSION * REDSTONE_PER_BASE_RF)) % BASE_RF ~= 0 then
- redstone_amount = redstone_amount + REDSTONE_PER_BASE_RF
- end
- redstone_amount = math.floor(redstone_amount)
- print("10 secondes d'ouverture coutera " .. redstone_amount .. ' redstones.')
- print('Voulez vous continuer ? Oui/non')
- if check_input(read(), 'confirmation') then
- print('Vous avez ' .. PAYMENT_TIMOUT_SECONDS .. ' secondes pour jetter vos redstones dans le dropper.')
- return check_payment(redstone_amount)
- end
- return false
- end
- function secure_opening()
- local engaged
- engaged = 0
- while engaged < 5 do
- sleep(0.5)
- _, engaged, _ = sg.stargateState()
- end
- sg.closeIris()
- engaged = "Dialling"
- while engaged == "Dialling" or engaged == "Opening" do
- sleep(0.5)
- engaged, _, _ = sg.stargateState()
- end
- sg.openIris()
- end
- function dial(address)
- local success
- local reason
- success, reason = sg.dial(address)
- if not success then
- print('')
- print('Impossible d\'etablir un vortex :')
- print(reason)
- print('Vous n\'avez pas ete encaisse, vous pouvez reessayer ou tenter de contacter une autre destination.')
- print('')
- sleep(2)
- return false
- end
- --push_payment()
- secure_opening()
- print("Le vortex se fermera dans " .. TIME_VORTEX_ACTIVATION_SECONDS .. " secondes.")
- sleep(TIME_VORTEX_ACTIVATION_SECONDS)
- sg.disconnect()
- return true
- end
- function event_loop()
- local str
- local arg
- local ret_ci
- --print('Entrez une adresse de portail :')
- --str = read('*')
- --str = read()
- --ret_ci = check_input(str, 'address')
- --if ret_ci then
- -- if ret_ci == 1 then
- print('Entrez une adresse de portail :')
- --str = read('*')
- str = read()
- if check_input(str, 'address', true) then
- dial(str)
- end
- -- elseif trade(str) then
- -- dial(str)
- -- end
- --end
- term.clear()
- term.setCursorPos(1,1)
- end
- function core()
- local state
- local direction
- while true do
- state, _, direction = sg.stargateState()
- if state == 'Connected' and direction == 'Outgoing' then
- sg.disconnect()
- end
- event_loop()
- sleep(1)
- end
- end
- init()
- core()
Add Comment
Please, Sign In to add comment