--Prevent standalone execution: if not TRAINSPORTED then print("To prevent players from harm, this file may only be executed by the trAInsported game.") return end --AI by MindingData: --[[table1 = {} table.insert(table1, 'test') table.insert(table1, 'test2') table.remove(table1, 1) print(#table1) print(table1['test']) print(table1[1])]]-- passengerList = {} function ai.init(map, money) buyTrain(3,1) end function ai.foundPassengers(train, passengers) if train.passenger == nil then --print('Train ' .. train.name .. ' has picked up ' .. passengers[1].name) if #passengerList > 0 then removePassenger(passengers[1].name) --passengerList[passengers[1].name] = nil end return passengers[1] end end function ai.chooseDirection(train, directions) if train.passenger == nil and #passengerList > 0 then if passengerList[1].x < train.x and directions['W'] == true then return 'W' end if passengerList[1].x > train.x and directions['E'] == true then return 'E' end if passengerList[1].y < train.y and directions['N'] == true then return 'N' end if passengerList[1].y > train.x and directions['S'] == true then return 'S' end end if train.passenger ~= nil then if train.passenger.destX < train.x and directions['W'] == true then return 'W' end if train.passenger.destX > train.x and directions['E'] == true then return 'E' end if train.passenger.destY < train.y and directions['N'] == true then return 'N' end if train.passenger.destY > train.x and directions['S'] == true then return 'S' end end end function ai.newPassenger(name, x, y, destX, destY, vipTime) --print('New passenger found ' .. name) local passenger = {name = name, x=x, y=y, destX=destX, destY=destY} table.insert(passengerList, passenger) --print(#passengerList) end function ai.foundDestination(train) dropPassenger(train) end function ai.enoughMoney() buyTrain(1, 3) end function removePassenger(passengerName) for index = 1,#passengerList do if passengerName == passengerList[index].name then table.remove(passengerList, index) break end end end