Untitled

mail@pastecode.io avatar
unknown
lua
a year ago
50 kB
3
Indexable
-- Made by GCodeman --

--configs
startingcash = 20000
bailoutcost = 15000 --Not used unless bailout feature turned on
hospitalbill = 500
recoverycostpercent = 0.80
maxloan = 15000
maxdebt = 15000
debtcap = 15000
fuelcostperliter = 500
debtperday = 0.5
incometax = 0 --Can be positive or negative
islandclaiming = true --Set to false to disable claiming of islands and teleport/spawn/bench permissions
negativetaxdebt = true --Set to false to disable negative tax adding debt. If player cannot pay, it'll just set them to $0 bank

--[[
g_savedata = {}
playertable {{player name, bank, debt, lastvehicle, lastdebtdate, lasttaxdate}, {player name, bank, debt, lastvehicle, lastdebtdate, lasttaxdate}}
vehicletable {{vehicle id, owner name, cost}, {vehicle id, owner name, cost}}
islandtable {island tile name, owner, {co-owners}, {allowed to teleport}, {allowed to spawn vehicles}, {allowed to bench}, {spawncoords}}
datatable {incometax}
append them together when saving to g_savedata
]]--

function saveGame()
	saveTables()
	server.save(("Career"))
end

function saveTables()
g_savedata = {playertable, vehicletable, islandtable, datatable}
end

function ownsVehicle(target_id, target_vehicle)
	matches = 0
		for k, v in pairs(vehicletable) do
			if (v[1] == target_vehicle) and (v[2] == server.getPlayerName(target_id)) then
				matches = 1
			end
		end
return matches
end

function isPlayerOnline(target_name)
	playeronline = 0
		for k, v in pairs(server.getPlayers()) do
			if (v["name"] == target_name) then
			playeronline = 1
			end
		end
	return playeronline
end

function getPlayerID(target_name)
	playerid = -1
		for k, v in pairs(server.getPlayers()) do
			if (v["name"] == target_name) then
			playerid = v["id"]
			end	
		end
	return playerid
end

function nearestVehicle(target_id)
	local playerloc = server.getPlayerPos(target_id)
	local nearestveh = -1
	local nearestvehdistance = 1000
	for k, v in pairs(vehicletable) do
		local dist, is_success = matrix.distance(playerloc, (server.getVehiclePos(v[1])))
				if dist < nearestvehdistance then 
					nearestvehdistance = dist
					nearestveh = v[1]
				end
		end
return nearestveh, nearestvehdistance
end

function isInPurchasedArea(target_id)
	local playerloc = server.getPlayerPos(target_id)
	local x, y, z = matrix.position(playerloc)
	return server.getTilePurchased(matrix.translation(x,y,z))
end

function isInMainland(target_id)
	local playerloc = server.getPlayerPos(target_id)
	local x, y, z = matrix.position(playerloc)
	if (z < 0 and z > -14000) then
			return true
		else
			return false
		end
end

function isHomeIsland(island_tile_name)
	local hometile = server.getStartTile()
	local hometilename = hometile["name"]
	if (island_tile_name == hometilename) then return 1 else return 0 end
end

function getIslandOwner(island_tile_name)
	for k, v in pairs(islandtable) do
		if v[1] == island_tile_name then
		return v[2]
		end
	end
	return "Unowned"
end

function getIslandKeyFromID(island_tile_name)
	for k, v in pairs(islandtable) do
			if v[1] == island_tile_name then 
			return k 
			end
	end
	return -1 --if not found
end

function getIslandCoOwners(island_tile_name)
	for k, v in pairs(islandtable) do
		if v[1] == island_tile_name then
		return v[3]
		end
	end
	return {} --if not found
end

function getIslandTeleportAccess(island_tile_name)
	for k, v in pairs(islandtable) do
		if v[1] == island_tile_name then
		return v[4]
		end
	end
	return {} --if not found
end

function getIslandSpawnAccess(island_tile_name)
	for k, v in pairs(islandtable) do
		if v[1] == island_tile_name then
		return v[5]
		end
	end
	return {} --if not found
end

function getIslandBenchAccess(island_tile_name)
	for k, v in pairs(islandtable) do
		if v[1] == island_tile_name then
		return v[6]
		end
	end
	return {} --if not found
end

function isCoOwner(player_name, island_tile_name)
	local coowners = getIslandCoOwners(island_tile_name)
		for k, v in pairs(coowners) do
			if v == player_name then return 1 end
		end
	return 0
end

function hasTeleportAccess(player_name, island_tile_name)
	if isHomeIsland(island_tile_name) == 1 then return 1 end
	local access = getIslandTeleportAccess(island_tile_name)
		for k, v in pairs(access) do
			if v == player_name then return 1 end
		end
	return 0
end

function hasSpawnAccess(player_name, island_tile_name)
	if isHomeIsland(island_tile_name) == 1 then return 1 end
	local access = getIslandSpawnAccess(island_tile_name)
		for k, v in pairs(access) do
			if v == player_name then return 1 end
		end
	return 0
end

function hasBenchAccess(player_name, island_tile_name)
	if isHomeIsland(island_tile_name) == 1 then return 1 end
	local access = getIslandBenchAccess(island_tile_name)
		for k, v in pairs(access) do
			if v == player_name then return 1 end
		end
	return 0
end

function tableToFormattedString(table)
	local string = ""
		for k, v in pairs(table) do
		string = string .. v .. "\n"
		end
	return string
end

function getBank(target_id)
	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
					return playertable[k][2] --Returns bank amount
				end
	end
end

function getDebt(target_id)
	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
					return playertable[k][3] --Returns debt amount
				end
	end
end

function teleportHome(target_id)
	local hometile = server.getStartTile()
	local x = hometile["x"]
	local y = hometile["y"]
	local z = hometile["z"]
	local pos = matrix.translation(x,y,z)
	server.setPlayerPos(target_id, pos)
end

function accrueDebt()
	for k, v in pairs(playertable) do
		if (v[3] > 0) and (v[5] < server.getDateValue()) then
			if (isPlayerOnline(v[1]) == 1) then
				local currentdebt = v[3]
				local debtadded = math.ceil(currentdebt * debtperday)
				local newdebt = math.ceil(currentdebt + debtadded)
				if (newdebt > debtcap) then newdebt = debtcap end
				playertable[k][3] = newdebt
				playertable[k][5] = server.getDateValue()
			server.notify(getPlayerID(v[1]), "Debt Accrued", "Debt: $" .. currentdebt .. "\n(" .. debtperday * 100 .. "%) = $" .. debtadded .. "\nNew Debt: $" .. newdebt, 8)
			end
		end
	end
end

function incomeTax()
	for k, v in pairs(playertable) do
		if (v[6] < server.getDateValue()) then
			if (isPlayerOnline(v[1]) == 1) then
				local amount = datatable[1]
				playertable[k][6] = server.getDateValue()
				if (amount == 0) then return end
				local target_id = getPlayerID(v[1])
				addBank(target_id, amount)
				if (amount > 0) then
					server.notify(target_id, "Tax Return", "$" .. amount .. " has been added to your account", 8)
				else
				server.notify(target_id, "Taxes Due", "$" .. amount .. " has been deducted from your account", 8)
					if (getBank(target_id) < 0) then
						local deficit = getBank(target_id)
						setBank(target_id, 0)
						if (negativetaxdebt) then
							addDebt(target_id, deficit * -1)
							if (getDebt(target_id) > debtcap) then 
								setDebt(target_id, debtcap)
							end
						end
					end
				end
			end
		end
	end
end

function displayUI()
	if (playertable ~= nil) then
		for k, v in pairs(playertable) do
			if (isPlayerOnline(v[1]) == 1) then
				local target_id = getPlayerID(v[1])
				server.setPopupScreen(target_id, 47, "Bank", true, "Bank:\n$" .. string.format('%.0f', getBank(target_id)), 0.885, 0.75)
					if (getDebt(target_id) > 0) then
					server.setPopupScreen(target_id, 48, "Debt", true, "Debt:\n$" .. string.format('%.0f', getDebt(target_id)), 0.885, 0.62)
					server.setPopupScreen(target_id, 49, "Shared Bank", true, "Shared Bank:\n$" .. getSharedBank(), 0.885, 0.49)
					else
					server.setPopupScreen(target_id, 48, "Debt", false, "", 0.885, 0.62)
					server.setPopupScreen(target_id, 49, "Shared Bank", true, "Shared Bank:\n$" .. getSharedBank(), 0.885, 0.62)
					end
			end
		end
	end
end

function searchTable(table, searchedvalue) --returns key or -1 if not found
		for k, v in pairs(table) do
			if v == searchedvalue then return k end
		end
	return -1
end

function getVehicleCost(target_vehicle)
	for k, v in pairs(vehicletable) do
				if (v[1] == target_vehicle) then
					return vehicletable[k][3] --Returns vehicle cost
				end
	end
end

function deleteVehicleFromTable(target_vehicle)
	for k, v in pairs(vehicletable) do
				if (v[1] == target_vehicle) then
					vehicletable[k] = nil --Removes from array
				end
	end
end

function getLastVehicle(target_id)
	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
					return playertable[k][4] --Returns last vehicle they were in
				end
	end
end

function setLastVehicle(target_id, target_vehicle)
	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
					playertable[k][4] = target_vehicle
				end
	end
end

function clearVehicles(target_id)
	for k, v in pairs(vehicletable) do
		if (v[2] == server.getPlayerName(target_id)) then
			server.despawnVehicle(v[1], true)
		end
	end
end

function getSharedBank()
	local sharedbank = server.getCurrency() - 1000000000
	if sharedbank < 0 then
		return 0
		else
		return sharedbank
		end
end

function addSharedBank(amount) -- do not subtract using this function
		if server.getCurrency() - 1000000000 < 0 then
			server.setCurrency(1000000000 + amount, server.getResearchPoints())
		else
			server.setCurrency(server.getCurrency() + amount, server.getResearchPoints())
		end
end

function addBank(target_id, amount)

	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
					playertable[k][2] = playertable[k][2] + amount
				end
	end
end

function setBank(target_id, amount)

	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
					playertable[k][2] = amount
				end
	end
end

--Used for loans and fines
function addDebt(target_id, amount)

	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
						if playertable[k][3] == 0 then
						playertable[k][5] = server.getDateValue() --Makes it so you dont get interest immediately
						end
					playertable[k][3] = playertable[k][3] + amount

				end
	end
end

--Used for loans and fines
function setDebt(target_id, amount)

	for k, v in pairs(playertable) do
				if (v[1] == server.getPlayerName(target_id)) then
				
						if playertable[k][3] == 0 then
						playertable[k][5] = server.getDateValue() --Makes it so you dont get interest immediately
						end
						
					playertable[k][3] = amount
				end
	end
end

function InitializePlayer(target_player)

	playerfound = false
		for k, v in pairs(playertable) do
					if (v[1] == server.getPlayerName(target_player)) then
						playerfound = true
					end
		end
		
	if (playerfound == false) then
	table.insert (playertable, {server.getPlayerName(target_player), startingcash, 0, -1, -1, -1})
	server.notify(target_player, "Welcome " .. server.getPlayerName(target_player), "$" .. startingcash .. " has been deposited into your account. Type '?help' to get started!", 8)
	else
		server.notify(target_player, "Welcome back " .. server.getPlayerName(target_player), "", 8)
	end
end

function getCurrentTileName(target_id)
	local playerloc = server.getPlayerPos(target_id)
	local x, y, z = matrix.position(playerloc)
	local islandinfo, is_success = server.getTile(playerloc)
	islandname = islandinfo["name"]
	if (islandname == nil) then return "NotFound" else return islandname end
end

function onCreate(is_world_create)

	server.setGameSetting("infinite_resources", false)
	--server.setGameSetting("auto_refuel", false) --No longer exists
	if (islandclaiming) then 
		server.setGameSetting("map_teleport", false) 
		server.setGameSetting("fast_travel", false) 
	end

	if (is_world_create) then 
	playertable = {}
	vehicletable = {}
	islandtable = {}
	datatable = {incometax}
	server.setCurrency(1000000000, server.getResearchPoints())
	else
	playertable = g_savedata[1]
	vehicletable = g_savedata[2]
	islandtable = g_savedata[3]
	datatable = g_savedata[4]
	end
	
	--TURN OFF WHEN NOT TESTING --[[ ]]--
	--[[
	playertable = {}
	vehicletable = {}
	islandtable = {}
	datatable = {incometax}
	]]--
	
end

function onTick(game_ticks)
	if (server.getCurrency() < 1000000000) then server.setCurrency(0, server.getResearchPoints()) end
	accrueDebt()
	displayUI()
end

function onPlayerJoin(steam_id, name, peer_id, admin, auth)
	server.announce("[Server]", name .. " joined the game")
	InitializePlayer(peer_id)
	if getLastVehicle(peer_id) > -1 then
		server.pressVehicleButton(getLastVehicle(peer_id), "Killswitch")
		server.notify(peer_id, "Possible Crash/Disconnect", "If your last occupied vehicle has a button labelled 'Killswitch' it has been pressed", 8)
	end
end

function onPlayerLeave(steam_id, name, peer_id, admin, auth)
	server.announce("[Server]", name .. " left the game")
	saveGame()
end

function onCustomCommand(full_message, user_peer_id, is_admin, is_auth, command, arg1, arg2)
	
	--if (command == "?test") then
	--end

	if (command == "?addbank" and is_admin == true) then
		local arg2num = tonumber(arg2)
		addBank(arg1, arg2num) --target_id, amount
		server.notify(user_peer_id, "Account Updated", server.getPlayerName(arg1) .. "'s bank has increased by $" .. arg2, 8)
		server.notify(arg1, "Account Updated", "Your bank has been increased by $" .. arg2, 8)
	end
	
	if (command == "?adddebt" and is_admin == true) then
		local arg2num = tonumber(arg2)
		addDebt(arg1, arg2num) --target_id, amount
		server.notify(user_peer_id, "Account Updated", server.getPlayerName(arg1) .. "'s debt has increased by $" .. arg2, 8)
		server.notify(arg1, "Account Updated", "Your debt has been increased by $" .. arg2, 8)			
	end
	
	if (command == "?setbank" and is_admin == true) then
		local arg2num = tonumber(arg2)
		setBank(arg1, arg2num) --target_id, amount
		server.notify(user_peer_id, "Account Updated", server.getPlayerName(arg1) .. "'s bank has been set to $" .. arg2, 8)
		server.notify(arg1, "Account Updated", "Your bank has been set to $" .. arg2, 8)
	end
	
	if (command == "?setdebt" and is_admin == true) then
		local arg2num = tonumber(arg2)
		setDebt(arg1, arg2num) --target_id, amount
		server.notify(user_peer_id, "Account Updated", server.getPlayerName(arg1) .. "'s debt has been set to $" .. arg2, 8)
		server.notify(arg1, "Account Updated", "Your debt has been set to $" .. arg2, 8)
	end
	
	if (command == "?resetisland" and is_admin == true) then
			local islandname = getCurrentTileName(user_peer_id)
			local formattedname = getFormattedTileName(islandname)
			if (formattedname ~= "NotFound") then
					server.notify(user_peer_id, "Island Reset", formattedname .. " is no longer owned by anybody", 8)
					local islandkey = getIslandKeyFromID(islandname)
					islandtable[islandkey] = nil
			else
			server.notify(user_peer_id, "Reset Failed", "This area is not ownable", 8)
			end
	end
	
		if (command == "?pay") then
			local arg2num = tonumber(arg2)
				if (arg2num > 0) then
					if (getBank(user_peer_id) >= arg2num) then
						addBank(user_peer_id, arg2num * -1)
						addBank(arg1, arg2num)
						server.notify(user_peer_id, "Payment Success", "You paid " .. server.getPlayerName(arg1) .. " $" .. arg2, 8)
						server.notify(arg1, "Payment Received", "You were paid $" .. arg2 .. " by " .. server.getPlayerName(user_peer_id), 8)
			else
			server.notify(user_peer_id, "Payment Failed", "You only have $" .. getBank(user_peer_id), 8)
			end
		else
		server.notify(user_peer_id, "Invalid number", "Please enter a valid number", 8)
		end
	end
	
	if (command == "?init") then
		InitializePlayer(user_peer_id)
	end
	
	if (command == "?loan") then
		local amount = tonumber(arg1)
		local currentdebt = getDebt(user_peer_id)
		if (amount + currentdebt <= maxloan) then
			addBank(user_peer_id, amount)
			addDebt(user_peer_id, amount)
			server.notify(user_peer_id, "Loan Successful", "Current Debt: $" .. currentdebt + amount.. "\nYour debt will increase by " .. debtperday * 100 .. "%" .. " at the beginning of each day", 8)
		else
			server.notify(user_peer_id, "Loan Failed", "Loan exceeds available amount\nMax: $" .. maxloan - currentdebt, 8)		
		end
	end
	
	if (command == "?payloan") then
		local amount = tonumber(arg1)
		local currentdebt = getDebt(user_peer_id)
			if (amount > 0) then
				if (getBank(user_peer_id) >= amount) then
					if (currentdebt >= amount) then
						addBank(user_peer_id, amount * -1)
						addDebt(user_peer_id, amount * -1)
						server.notify(user_peer_id, "Payment Successful", "Remaining Debt: $" .. currentdebt - amount, 8)
					else
						server.notify(user_peer_id, "Payment Failed", "Amount larger than current debt", 8)
					end
				else
					server.notify(user_peer_id, "Payment Failed", "You do not have enough money", 8)
				end
			else
			server.notify(user_peer_id, "Payment Failed", "Please enter a valid number", 8)		
		end
	end
	
	if (command == "?accruedebt" and is_admin == true) then
		accrueDebt()
	end	
	
	--Currently disabled. System can be abused by taking loans then paying other players then getting bailed out
	--Could adapt this to an admin-only command
	
	--[[
	if (command == "?bailout") then	
		if (getBank(user_peer_id) >= bailoutcost) then
			if (getDebt(arg1) >= maxdebt) then
				clearVehicles(arg1)
				addBank(user_peer_id, bailoutcost * -1)
				setBank(arg1, startingcash)
				setDebt(arg1, 0)
			else
				server.notify(user_peer_id, "Bailout Failed", server.getPlayerName(arg1) .. " does not need a bailout", 8)
			end
		else
		server.notify(user_peer_id, "Bailout Failed", "You need $" .. bailoutcost .. "to bail out another player", 8)
		end
	end
	--]]

	if (command == "?bank") then
		local bank = getBank(user_peer_id)
		local debt = getDebt(user_peer_id)
		local sharedbank = getSharedBank()
		server.notify(user_peer_id, "Account", "Personal Bank: $" .. bank .. "\nShared Bank: $" .. sharedbank .. "\nDebt: $" .. debt, 8)
	end
	
	if (command == "?addsharedbank" and is_admin == true) then
		local arg1num = tonumber(arg1)
		if arg1num > 0 then
		addSharedBank(arg1num)
		else
		server.setCurrency(server.getCurrency() + arg1num, server.getResearchPoints())
		end
		server.notify(user_peer_id, "Shared Account Updated", "Balance: $" .. getSharedBank(), 8)	
	end	
	
	if (command == "?addresearch" and is_admin == true) then
		local arg1num = tonumber(arg1)
		server.setCurrency(server.getCurrency(), server.getResearchPoints() + arg1num)
		server.notify(user_peer_id, "Research Updated", "Total Research: " .. server.getResearchPoints(), 8)
	end
	
	if (command == "?setresearch" and is_admin == true) then
		local arg1num = tonumber(arg1)
		server.setCurrency(server.getCurrency(), arg1num)
		server.notify(user_peer_id, "Research Updated", "Total Research: " .. server.getResearchPoints(), 8)
	end	
	
	if (command == "?savegame") then
	saveGame()
	end
	
	if (command == "?playertable" and is_admin == true) then
			for k, v in pairs(playertable) do
			server.announce("Player Table", "Key ID " .. k .. "\nPlayer Name: " .. v[1] .. "\nBank: $" .. v[2] .. "\nDebt: $" .. v[3] .. "\nLast Veh ID: " .. v[4] .. "\nLast Debt Date: " .. v[5], (user_peer_id))
			end
	end
	
	if (command == "?vehicletable" and is_admin == true) then
			for k, v in pairs(vehicletable) do
			server.announce("Vehicle Table", "Key ID " .. k .. "\nVehicle ID: " .. v[1] .. "\nOwner Name: " .. v[2] .. "\nCost: $" .. v[3], (user_peer_id))
			end
	end
	
	if (command == "?islandtable" and is_admin == true) then
			for k, v in pairs(islandtable) do		
			server.announce("Island Table", "Key ID " .. k .. "\nTile: " .. v[1] .. "\nOwner Name: " .. v[2] .. "\nCo-Owner Names: " .. "WIP" .. "\nTP Access: " .. "WIP" .. "\nSpawn Access: " .. "WIP" .. "\nBench Access: " .. "WIP", (user_peer_id))
			end
	end
	
	if (command == "?bring" and is_admin == true) then
		server.setPlayerPos(arg1, (server.getPlayerPos(user_peer_id)))
		server.notify(user_peer_id, "Teleport", server.getPlayerName(arg1) .. " has been teleported to your position." , 8)
		server.notify(arg1, "Teleport", server.getPlayerName(user_peer_id) .. " has teleported you to their position." , 8)
	end
	
	if (command == "?goto" and is_admin == true) then
		server.setPlayerPos(user_peer_id, (server.getPlayerPos(arg1)))
		server.notify(user_peer_id, "Teleport", "You have teleported to " .. server.getPlayerName(arg1) .. "'s position", 8)
		server.notify(arg1, "Teleport", server.getPlayerName(user_peer_id) .. " has teleported to your position" , 8)
	end
	
	if (command == "?settax" and is_admin == true) then
			local arg1num = tonumber(arg1)
			if type(arg1num) ~= "number" then 
			server.notify(user_peer_id, "Command Failed", "Please enter a valid number", 8)
			return end
		datatable[1] = arg1num
		server.notify(user_peer_id, "Taxes Updated", "Each player gets $" .. arg1num .. " per day", 8)
	end
	
	if (command == "?bancada") or (command == "?b") then
		local islandname = getCurrentTileName(user_peer_id)
		local formattedname = getFormattedTileName(islandname)
		if isInPurchasedArea(user_peer_id) or (string.find(formattedname, "Deposit")) then
			local playername = server.getPlayerName(user_peer_id)
			if (islandclaiming == false) or (hasBenchAccess(playername, islandname) == 1 or getIslandOwner(islandname) == 			playername or isCoOwner(playername, islandname) == 1 or (isHomeIsland(islandname) == 1)) then
				local nearestveh, nearestvehdist = nearestVehicle(user_peer_id)
					if (nearestvehdist <= 25) then
							if ownsVehicle(user_peer_id, nearestveh) == 1 then
								local vehiclecost = getVehicleCost(nearestveh)
								addBank(user_peer_id, vehiclecost)
								setLastVehicle(user_peer_id, -1)
								server.despawnVehicle(nearestveh, true)
								server.notify(user_peer_id, "Vehicle Returned", "$" .. string.format('%.0f', vehiclecost) .. " was refunded to your account", 8)
							else
							server.notify(user_peer_id, "Return Failed", "This vehicle does not belong to you", 8)
							end			
				else
				server.notify(user_peer_id, "Return Failed", "No vehicle within 25m found", 8)
				end
			else
			server.notify(peer_id, "Bench Failed", "You do not have clearance to bench here", 8)
			end
		else
		server.notify(user_peer_id, "Return Failed", "You must be near a workbench you own", 8)
		end
	end
	
	if (command == "?lock" and is_admin == true) then
			local nearestveh, nearestvehdist = nearestVehicle(user_peer_id)
				if (nearestvehdist <= 25) then
					server.setVehicleEditable(nearestveh, false)
					server.notify(user_peer_id, "Vehicle Locked", "", 8)
				else
				server.notify(user_peer_id, "Lock Failed", "No vehicle within 25m found", 8)
				end
	end		

	if (command == "?unlock" and is_admin == true) then
			local nearestveh, nearestvehdist = nearestVehicle(user_peer_id)
				if (nearestvehdist <= 25) then
					server.setVehicleEditable(nearestveh, true)
					server.notify(user_peer_id, "Vehicle Unlocked", "", 8)		
				else
				server.notify(user_peer_id, "Unlock Failed", "No vehicle within 25m found", 8)
				end
	end		

	if (command == "?resgatar" || ) or (command == "?r" || ) then
			local nearestveh, nearestvehdist = nearestVehicle(user_peer_id)
				if (nearestvehdist <= 25) then
					if ownsVehicle(user_peer_id, nearestveh) == 1 then
						local refund = math.floor(getVehicleCost(nearestveh) - (getVehicleCost(nearestveh) * recoverycostpercent))
								addBank(user_peer_id, refund)
								server.notify(user_peer_id, "Vehicle Recovered", "$" .. string.format('%.0f', refund) .. " was refunded to your account after a " .. recoverycostpercent * 100 .. "% ($" .. (getVehicleCost(nearestveh) * recoverycostpercent) ..") recovery fee", 8)
								setLastVehicle(user_peer_id, -1)
								server.despawnVehicle(nearestveh, true)
					else
					server.notify(user_peer_id, "Return Failed", "This vehicle does not belong to you", 8)
					end		
				else
				server.notify(user_peer_id, "Return Failed", "No vehicle within 25m found", 8)
				end
	end	

	if (command == "?tilename" and is_admin == true) then
		local tilename = getCurrentTileName(user_peer_id)
		server.notify(user_peer_id, "Tile Name", tilename, 8)
	end
	
	if (command == "?help") then
	server.announce("Commands", "?bank\n?deposit (amount)\n?claim (amount)\n?pay (player id) (amount)\n?loan (amount)\n?payloan (amount)\n?bancada (ou ?b)\n?resgatar (ou ?r) [" .. string.format('%.0f', recoverycostpercent * 100) .. "% vehicle cost fee]\n?buyfuel (diesel/jetfuel) (amount) [$" .. fuelcostperliter .. "/L, non-dynamic tanks only]\n?savegame", (user_peer_id))
	if (islandclaiming) then 
	server.announce("Island Commands", "?access\n?islandaccess (island name)\n?claimisland\n?unclaimisland\n?setcoowner (player id) (island name)\n?setteleport (player id) (island name)\n?setspawn (player id) (island name)\n?setbench (player id) (island name)", (user_peer_id))
	end
	if (is_admin == true) then
	server.announce("Admin Commands", "?addbank (player id) (amount)\n?setbank (player id) (amount)\n?addsharedbank (amount)\n?adddebt (player id) (amount)\n?setdebt (player id) (amount)\n?addresearch (amount)\n?setresearch (amount)\n?settax (amount)\n?bring (player id)\n?lock\n?unlock\n?resetisland", (user_peer_id))
	server.announce("Debug Commands", "?init\n?playertable\n?vehicletable\n?islandtable\n?accruedebt\n?tilename", (user_peer_id))
	end
	
	end
	
	
	if (command == "?deposit") then
		local arg1num = tonumber(arg1)
		if (arg1num > 0) then
			if (getBank(user_peer_id) >= arg1num) then
				addBank(user_peer_id, arg1num * -1)
				addSharedBank(arg1num)
			server.notify(-1, server.getPlayerName(user_peer_id) .. " has deposited $"..arg1num, "Shared Bank: $".. getSharedBank(), 8)
			else
			server.notify(user_peer_id, "Deposit Failed", "You only have $" .. getBank(user_peer_id), 8)
			end
		else
		server.notify(user_peer_id, "Invalid number", "Please enter a valid number", 8)
		end
	end
	
	if (command == "?claim") then
		local arg1num = tonumber(arg1)
		if (arg1num > 0) then
			if (getSharedBank() >= arg1num) then
				addBank(user_peer_id, arg1num * 1)
				server.setCurrency(server.getCurrency() - arg1num, server.getResearchPoints())
			server.notify(-1, server.getPlayerName(user_peer_id) .. " has claimed $"..arg1num, "Shared Bank: $".. getSharedBank(), 8)
			else
			server.notify(user_peer_id, "Claim Failed", "The bank only has $" .. getSharedBank(), 8)
			end
		else
		server.notify(user_peer_id, "Invalid number", "Please enter a valid number", 8)
		end
	end
	
	
	if (command == "?buyfuel") then
		if (getLastVehicle(user_peer_id) ~= -1) then
			if isInMainland(user_peer_id) then
				if isInPurchasedArea(target_id) then 
						if (arg1 == "diesel" or arg1 == "jetfuel") then
									if (getBank(user_peer_id) >= arg2 * fuelcostperliter) then
										addBank(user_peer_id, (arg2 * fuelcostperliter) * -1)

											if (arg1 == "diesel") then
												server.setVehicleTank(getLastVehicle(user_peer_id), tank_name, arg2, 1)
												server.notify(user_peer_id, "Fueling Successful", arg2 .. "L diesel purchased for $" .. arg2 * fuelcostperliter, 8)
											end
											if (arg1 == "jetfuel") then
												server.setVehicleTank(getLastVehicle(user_peer_id), tank_name, arg2, 2)
												server.notify(user_peer_id, "Fueling Successful", arg2 .. "L jet fuel purchased for $" .. arg2 * fuelcostperliter, 8)
											end
									else
									server.notify(user_peer_id, "Fueling Failed", "You do not have enough cash", 8)
									end
						else
						server.notify(user_peer_id, "Fueling Failed", "You must enter diesel or jetfuel", 8)
						end
					else
					server.notify(user_peer_id, "Fueling Failed", "You must be near a workbench you own", 8)			
					end
				else
				server.notify(user_peer_id, "Fueling Failed", "You can only purchase fuel on the mainland and main islands", 8)
				end
		else
		server.notify(user_peer_id, "Fueling Failed", "You must be in a vehicle to do this", 8)
		end
	end

	--?teleport islandformattedname
	if (command == "?teleport") or (command == "?tp") then
		if (islandclaiming) then
			local islandformattedname = arg1
			local islandtilename = getTileIDFromName(islandformattedname)
			local playername = server.getPlayerName(user_peer_id)
			if (islandtilename ~= "NotFound") then
				if (getIslandOwner(islandtilename) == playername) or (isCoOwner(playername, islandtilename) == 1) or 					hasTeleportAccess(playername, islandtilename) == 1 or isHomeIsland(islandtilename) == 1 then
						if (isHomeIsland(islandtilename) == 1) then 
							local hometile = server.getStartTile()
							local x = hometile["x"]
							local y = hometile["y"]
							local z = hometile["z"]
							local loc = matrix.translation(x,y,z)
							server.setPlayerPos(user_peer_id, loc)
						else
							local islandkey = getIslandKeyFromID(islandtilename)
							local loc = islandtable[islandkey][7]
							server.setPlayerPos(user_peer_id, loc)
						end
					else
					server.notify(user_peer_id, "Teleport Failed", "You do not have clearance to teleport to " .. 					islandformattedname, 8)
					end
			else
			server.notify(user_peer_id, "Teleport Failed", "Island not found", 8)
			end
		else
		server.notify(user_peer_id, "Island Teleporting Disabled", "This command has been disabled by server settings", 8)
		end
	end

	if (command == "?access") then
		if (islandclaiming) then
			local hometile = server.getStartTile()
			local hometilename = hometile["name"]
			local hometileformattedname = getFormattedTileName(hometilename)
			local playername = server.getPlayerName(user_peer_id)
			local accessstring = hometileformattedname .. ": Home"

			for k, v in pairs(islandtable) do
				local island_tile_name = v[1]
				local islandformattedname = getFormattedTileName(island_tile_name)
			
				if (getIslandOwner(island_tile_name) == playername) then 
				accessstring = accessstring .. "\n" .. islandformattedname .. ": Owner"
			
				elseif (isCoOwner(playername, island_tile_name) == 1) then
				accessstring = accessstring .. "\n" .. islandformattedname  ..": Co-Owner"
			
				elseif hasTeleportAccess(playername, island_tile_name) == 1 or 
				hasSpawnAccess(playername, island_tile_name) == 1 or
				hasBenchAccess(playername, island_tile_name) == 1 then
					accessstring = accessstring .. "\n" .. islandformattedname .. ": "
					if hasTeleportAccess(playername, island_tile_name) == 1 then accessstring = accessstring .. "Teleport " end
					if hasSpawnAccess(playername, island_tile_name) == 1 then accessstring = accessstring .. "Spawn " end
					if hasBenchAccess(playername, island_tile_name) == 1 then accessstring = accessstring .. "Bench" end
				end
			end
			server.announce("Access", accessstring, (user_peer_id))
		else
		server.notify(user_peer_id, "Island Claiming Disabled", "This command has been disabled by server settings", 8)
		end
	end
	
	--?islandaccess islandformattedname
	if (command == "?islandaccess") then
		local islandformattedname = arg1
		local islandtilename = getTileIDFromName(islandformattedname)
		local playername = server.getPlayerName(user_peer_id)
		if (islandtilename ~= "NotFound") then
			if (getIslandOwner(islandtilename) == playername) or (isCoOwner(playername, islandtilename) == 1) then
				for k, v in pairs(islandtable) do
					if (v[1] == islandtilename) then	
						--Owner		
						server.announce("Owner", getIslandOwner(islandtilename), (user_peer_id))
						--Co-Owners
						local coowners = getIslandCoOwners(islandtilename)
						local coownersstring = tableToFormattedString(coowners)
						if (coownersstring ~= "") then 
						server.announce("Co-Owners", coownersstring, (user_peer_id))
						end
						--Teleport
						local teleportaccess = getIslandTeleportAccess(islandtilename)
						local teleportaccessstring = tableToFormattedString(teleportaccess)
						if (teleportaccessstring ~= "") then 
						server.announce("Teleport Access", teleportaccessstring, (user_peer_id))
						end
						--Spawn
						local spawnaccess = getIslandSpawnAccess(islandtilename)
						local spawnaccessstring = tableToFormattedString(spawnaccess)
						if (spawnaccessstring ~= "") then 
						server.announce("Spawn Access", spawnaccessstring, (user_peer_id))
						end					
						--Bench
						local benchaccess = getIslandBenchAccess(islandtilename)
						local benchaccessstring = tableToFormattedString(benchaccess)
						if (benchaccessstring ~= "") then 
						server.announce("Bench Access", benchaccessstring, (user_peer_id))
						end	
					end
				end
			else
			server.notify(user_peer_id, "Request Failed", "You do not have clearance to see this", 8)
			end
		else
		server.notify(user_peer_id, "Request Failed", "Island not found", 8)
		end
	end

	--?setcoowner playerid islandformattedname
	if (command == "?setcoowner") then
		local playername = server.getPlayerName(user_peer_id)
		local targetname = server.getPlayerName(arg1)
		local islandformattedname = arg2
		local islandtilename = getTileIDFromName(islandformattedname)
		if (islandtilename ~= "NotFound") then
			if (arg1 ~= user_peer_id) then
				if (getIslandOwner(islandtilename) == playername) or (isCoOwner(playername, islandtilename) == 1) then
					if (getIslandOwner(islandtilename) ~= targetname) then
						local islandkey = getIslandKeyFromID(islandtilename)
						if (isCoOwner(targetname, islandtilename) == 1) then
							server.notify(user_peer_id, "Permission Removed", targetname .. " is no longer a co-owner of " .. 							islandformattedname, 8)
							local playerkey = searchTable(islandtable[islandkey][3], targetname)
							islandtable[islandkey][3][playerkey] = nil
							else
							table.insert (islandtable[islandkey][3], targetname)
							server.notify(user_peer_id, "Permission Added", targetname .. " is now a co-owner of " .. 							islandformattedname, 8)
							end
					else
					server.notify(user_peer_id, "Permission Failed", "That player is the owner of the island", 8)
					end
				else
				server.notify(user_peer_id, "Permission Failed", "You do not own this island", 8)
				end
			else
			server.notify(user_peer_id, "Permission Failed", "You cannot edit your own permissions", 8)
			end
		else
		server.notify(user_peer_id, "Permission Failed", "Island not found", 8)
		end
	end
	
	--?setteleport playerid islandformattedname
	if (command == "?setteleport") then
		local playername = server.getPlayerName(user_peer_id)
		local targetname = server.getPlayerName(arg1)
		local islandformattedname = arg2
		local islandtilename = getTileIDFromName(islandformattedname)
		if (islandtilename ~= "NotFound") then
			if (arg1 ~= user_peer_id) then
				if (getIslandOwner(islandtilename) == playername) or (isCoOwner(playername, islandtilename) == 1) then
					if (getIslandOwner(islandtilename) ~= targetname) then
						local islandkey = getIslandKeyFromID(islandtilename)
						if (hasTeleportAccess(targetname, islandtilename) == 1) then
							server.notify(user_peer_id, "Permission Removed", targetname .. " can no longer teleport to " .. 							islandformattedname, 8)
							local playerkey = searchTable(islandtable[islandkey][4], targetname)
							islandtable[islandkey][4][playerkey] = nil
							else
							table.insert (islandtable[islandkey][4], targetname)
							server.notify(user_peer_id, "Permission Added", targetname .. " can now teleport to " .. 							islandformattedname, 8)
							end
					else
					server.notify(user_peer_id, "Permission Failed", "That player is the owner of the island", 8)
					end
				else
				server.notify(user_peer_id, "Permission Failed", "You do not own this island", 8)
				end
			else
			server.notify(user_peer_id, "Permission Failed", "You cannot edit your own permissions", 8)
			end
		else
		server.notify(user_peer_id, "Permission Failed", "Island not found", 8)
		end
	end
	
	--?setspawn playerid islandformattedname
	if (command == "?setspawn") then
		local playername = server.getPlayerName(user_peer_id)
		local targetname = server.getPlayerName(arg1)
		local islandformattedname = arg2
		local islandtilename = getTileIDFromName(islandformattedname)
		if (islandtilename ~= "NotFound") then
			if (arg1 ~= user_peer_id) then
				if (getIslandOwner(islandtilename) == playername) or (isCoOwner(playername, islandtilename) == 1) then
					if (getIslandOwner(islandtilename) ~= targetname) then
						local islandkey = getIslandKeyFromID(islandtilename)
						if (hasSpawnAccess(targetname, islandtilename) == 1) then
							server.notify(user_peer_id, "Permission Removed", targetname .. " can no longer spawn vehicles at " .. 							islandformattedname, 8)
							local playerkey = searchTable(islandtable[islandkey][5], targetname)
							islandtable[islandkey][5][playerkey] = nil
							else
							table.insert (islandtable[islandkey][5], targetname)
							server.notify(user_peer_id, "Permission Added", targetname .. " can now spawn vehicles at " .. 							islandformattedname, 8)
							end
					else
					server.notify(user_peer_id, "Permission Failed", "That player is the owner of the island", 8)
					end
				else
				server.notify(user_peer_id, "Permission Failed", "You do not own this island", 8)
				end
			else
			server.notify(user_peer_id, "Permission Failed", "You cannot edit your own permissions", 8)
			end
		else
		server.notify(user_peer_id, "Permission Failed", "Island not found", 8)
		end
	end	

	--?setbench playerid islandformattedname
	if (command == "?setbench") then
		local playername = server.getPlayerName(user_peer_id)
		local targetname = server.getPlayerName(arg1)
		local islandformattedname = arg2
		local islandtilename = getTileIDFromName(islandformattedname)
		if (islandtilename ~= "NotFound") then
			if (arg1 ~= user_peer_id) then
				if (getIslandOwner(islandtilename) == playername) or (isCoOwner(playername, islandtilename) == 1) then
					if (getIslandOwner(islandtilename) ~= targetname) then
						local islandkey = getIslandKeyFromID(islandtilename)
						if (hasBenchAccess(targetname, islandtilename) == 1) then
							server.notify(user_peer_id, "Permission Removed", targetname .. " can no longer bench vehicles at " .. 							islandformattedname, 8)
							local playerkey = searchTable(islandtable[islandkey][6], targetname)
							islandtable[islandkey][6][playerkey] = nil
							else
							table.insert (islandtable[islandkey][6], targetname)
							server.notify(user_peer_id, "Permission Added", targetname .. " can now bench vehicles at " .. 							islandformattedname, 8)
							end
					else
					server.notify(user_peer_id, "Permission Failed", "That player is the owner of the island", 8)
					end
				else
				server.notify(user_peer_id, "Permission Failed", "You do not own this island", 8)
				end
			else
			server.notify(user_peer_id, "Permission Failed", "You cannot edit your own permissions", 8)
			end
		else
		server.notify(user_peer_id, "Permission Failed", "Island not found", 8)
		end
	end	

	if (command == "?claimisland") then
		if (islandclaiming) then 
			local islandname = getCurrentTileName(user_peer_id)
			local formattedname = getFormattedTileName(islandname)
			local islandowner = getIslandOwner(islandname)
			local is_purchased = isInPurchasedArea(user_peer_id)
			if (is_purchased) or (string.find(formattedname, "Deposit")) then
				if (isHomeIsland(islandname) == 0) then
					if (formattedname ~= "NotFound") then
						if (islandowner == "Unowned") then
							server.notify(user_peer_id, "Claim Successful", "You now own " .. formattedname, 8)
							table.insert (islandtable, {islandname, server.getPlayerName(user_peer_id), {}, {}, {}, {}, 							server.getPlayerPos(user_peer_id)}) --Sets to owner and spawn coordinates
						else
							server.notify(user_peer_id, "Claim Failed", formattedname .. " is already owned by " .. islandowner, 8)
						end
					else
						server.notify(user_peer_id, "Claim Failed", "This area is not ownable", 8)
					end
				else
				server.notify(user_peer_id, "Claim Failed", "The starting area is not ownable", 8)
				end
			else
			server.notify(user_peer_id, "Claim Failed", "This island is not purchased", 8)
			end
		else
		server.notify(user_peer_id, "Island Claiming Disabled", "This command has been disabled by server settings", 8)
		end
	end
	
	if (command == "?unclaimisland") then
		if (islandclaiming) then 
			local islandname = getCurrentTileName(user_peer_id)
			local formattedname = getFormattedTileName(islandname)
			local islandowner = getIslandOwner(islandname)
			if (formattedname ~= "NotFound") then
				if (islandowner == server.getPlayerName(user_peer_id)) then
					server.notify(user_peer_id, "Unclaim Successful", "You no longer own " .. formattedname, 8)
					local islandkey = getIslandKeyFromID(islandname)
					islandtable[islandkey] = nil
				else
					server.notify(user_peer_id, "Unclaim Failed", "You do not own " .. formattedname, 8)
				end
			else
			server.notify(user_peer_id, "Unclaim Failed", "This area is not ownable", 8)
			end
		else
		server.notify(user_peer_id, "Island Claiming Disabled", "This command has been disabled by server settings", 8)
		end
	end

end --end for custom commands

function onPlayerSit(peer_id, vehicle_id, seat_name)
	setLastVehicle(peer_id, vehicle_id)
end

function onPlayerUnsit(peer_id, vehicle_id, seat_name)
	setLastVehicle(peer_id, -1)
end

function onPlayerRespawn(peer_id)
	setLastVehicle(peer_id, -1)
	teleportHome(peer_id)
	if (getBank(peer_id) >= hospitalbill) then
	addBank(peer_id, hospitalbill * -1)
	server.notify(peer_id, "Hospital Bills", "$" .. hospitalbill .. " was deducted from your account", 8)
	else
	server.notify(peer_id, "Hospital Bills", "$" .. getBank(peer_id) .. "was deducted from your account", 8)
	setBank(peer_id, 0)
	end
end

function onVehicleSpawn(vehicle_id, peer_id, x, y, z, cost)
	if (peer_id > -1) then
		local playername = server.getPlayerName(peer_id)
		local islandname = getCurrentTileName(peer_id)
		if (islandclaiming == false) or (hasSpawnAccess(playername, islandname) == 1 or getIslandOwner(islandname) == playername or 		isCoOwner(playername, islandname) == 1 or (isHomeIsland(islandname) == 1)) then
			if (cost ~= 2) then
				if (getDebt(peer_id) <= maxdebt) then
					if (getBank(peer_id) >= cost) then
						addBank((peer_id), cost * -1)
						server.setCurrency(server.getCurrency() + cost, server.getResearchPoints())
						table.insert (vehicletable, {vehicle_id, server.getPlayerName(peer_id), cost})
						--server.setVehicleEditable(vehicle_id, false) --Moved to onVehicleLoad
						server.notify(peer_id, "Vehicle Purchased", "$".. string.format('%.0f', getBank(peer_id)) .." remains", 8)
						if (server.getCurrency() < 1000000000) then server.setCurrency(0, server.getResearchPoints()) end --ontick doesnt work 						when vehicle is spawned here sometimes for some reason
						else
						server.despawnVehicle(vehicle_id, true)
						server.setCurrency(server.getCurrency() + cost, server.getResearchPoints())
						server.notify(peer_id, "Not enough money", "You need $"..cost - getBank(server.getPlayerName(peer_id)).." 						more.", 8)
					end
				else
				server.despawnVehicle(vehicle_id, true)
				server.setCurrency(server.getCurrency() + cost, server.getResearchPoints())
				server.notify(peer_id, "Debt too high", "You must get your debt below $" .. maxdebt .. " to spawn a vehicle", 8)
				end
			else
			server.despawnVehicle(vehicle_id, true)
			server.notify(-1, server.getPlayerName(peer_id) .. " accidentally spawned the Cube of Shame", "Everybody point and 			laugh", 8)
			end
		else
		server.despawnVehicle(vehicle_id, true)
		server.setCurrency(server.getCurrency() + cost, server.getResearchPoints())
		server.notify(peer_id, "Purchase Failed", "You do not have clearance to spawn here", 8)
		end
	end
end

function onVehicleLoad(vehicle_id)
server.setVehicleEditable(vehicle_id, false) --Had to move this here because it wasn't calculating fuel on spawn correctly
end

function onVehicleDespawn(vehicle_id, peer_id)
	deleteVehicleFromTable(vehicle_id)
end

--You can make a tile purchasable by adding entries in the next 2 sections
--If "Deposit" is in the name, it can be claimed without purchasing (useful for areas with no purchase sign like oil sites)

function getFormattedTileName(tile_id)
--Base Tiles
if (tile_id) == "data/tiles/island_33_tile_end.xml" then return "Camodo" end
if (tile_id) == "data/tiles/island_33_tile_32.xml" then return "Spycakes" end
if (tile_id) == "data/tiles/island_33_tile_33.xml" then return "Dreimor" end
if (tile_id) == "data/tiles/island_43_multiplayer_base.xml" then return "MPI" end
if (tile_id) == "data/tiles/island_15.xml" then return "Coastguard" end
if (tile_id) == "data/tiles/test_tile.xml" then return "CoastguardTT" end
if (tile_id) == "data/tiles/island12.xml" then return "CoastguardB" end
if (tile_id) == "data/tiles/island_24.xml" then return "Airstrip" end
if (tile_id) == "data/tiles/island_34_military.xml" then return "Military" end
if (tile_id) == "data/tiles/island_25.xml" then return "Harbor" end
if (tile_id) == "data/tiles/mega_island_9_8.xml" then return "NorthHarbor" end
if (tile_id) == "data/tiles/mega_island_2_6.xml" then return "Harrison" end
if (tile_id) == "data/tiles/mega_island_12_6.xml" then return "ONeill" end
if (tile_id) == "data/tiles/mega_island_15_2.xml" then return "FishingVillage" end
if (tile_id) == "data/tiles/island_31_playerbase_combo.xml" then return "CustomSmallBoat" end
if (tile_id) == "data/tiles/island_30_playerbase_boat.xml" then return "CustomLargeBoat" end
if (tile_id) == "data/tiles/island_32_playerbase_heli.xml" then return "CustomHeli" end
if (tile_id) == "data/tiles/island_29_playerbase_submarine.xml" then return "CustomSub" end
if (tile_id) == "data/tiles/oil_rig_playerbase.xml" then return "CustomRig" end
if (tile_id) == "data/tiles/arctic_tile_22.xml" then return "Endo" end
if (tile_id) == "data/tiles/arctic_tile_12_oilrig.xml" then return "Trinite" end
if (tile_id) == "data/tiles/arctic_island_playerbase.xml" then return "Tajin" end
--Desert Tiles
if (tile_id) == "data/tiles/arid_island_5_14.xml" then return "NorthMeier" end
if (tile_id) == "data/tiles/arid_island_8_15.xml" then return "Uran" end
if (tile_id) == "data/tiles/arid_island_6_7.xml" then return "Serpentine" end
if (tile_id) == "data/tiles/arid_island_7_5.xml" then return "Ender" end
if (tile_id) == "data/tiles/arid_island_11_14.xml" then return "Brainz" end
if (tile_id) == "data/tiles/arid_island_12_10.xml" then return "Mauve" end
if (tile_id) == "data/tiles/arid_island_19_12.xml" then return "Monkey" end
if (tile_id) == "data/tiles/arid_island_19_11.xml" then return "Clarke" end
if (tile_id) == "data/tiles/arid_island_24_3.xml" then return "JSI" end
if (tile_id) == "data/tiles/arid_island_26_14.xml" then return "FJWarner" end
--Desert Oil Deposits
if (tile_id) == "data/tiles/arid_island_23_14.xml" then return "CarnivoreDeposit" end
if (tile_id) == "data/tiles/arid_island_24_4.xml" then return "JSIDeposit" end
if (tile_id) == "data/tiles/arid_island_3_12.xml" then return "TurmoildDeposit" end
if (tile_id) == "data/tiles/arid_island_8_11.xml" then return "ShymavanDeposit" end
return "NotFound"
end

function getTileIDFromName(formatted_name)
--Base Tiles
if (formatted_name) == "Camodo" then return "data/tiles/island_33_tile_end.xml" end
if (formatted_name) == "Spycakes" then return "data/tiles/island_33_tile_32.xml" end
if (formatted_name) == "Dreimor" then return "data/tiles/island_33_tile_33.xml" end
if (formatted_name) == "MPI" then return "data/tiles/island_43_multiplayer_base.xml" end
if (formatted_name) == "Coastguard" then return "data/tiles/island_15.xml" end
if (formatted_name) == "CoastguardTT" then return "data/tiles/test_tile.xml" end
if (formatted_name) == "CoastguardB" then return "data/tiles/island12.xml" end
if (formatted_name) == "Airstrip" then return "data/tiles/island_24.xml" end
if (formatted_name) == "Military" then return "data/tiles/island_34_military.xml" end
if (formatted_name) == "Harbor" then return "data/tiles/island_25.xml" end
if (formatted_name) == "NorthHarbor" then return "data/tiles/mega_island_9_8.xml" end
if (formatted_name) == "Harrison" then return "data/tiles/mega_island_2_6.xml" end
if (formatted_name) == "ONeill" then return "data/tiles/mega_island_12_6.xml" end
if (formatted_name) == "FishingVillage" then return "data/tiles/mega_island_15_2.xml" end
if (formatted_name) == "CustomSmallBoat" then return "data/tiles/island_31_playerbase_combo.xml" end
if (formatted_name) == "CustomLargeBoat" then return "data/tiles/island_30_playerbase_boat.xml" end
if (formatted_name) == "CustomHeli" then return "data/tiles/island_32_playerbase_heli.xml" end
if (formatted_name) == "CustomSub" then return "data/tiles/island_29_playerbase_submarine.xml" end
if (formatted_name) == "CustomRig" then return "data/tiles/oil_rig_playerbase.xml" end
if (formatted_name) == "Endo" then return "data/tiles/arctic_tile_22.xml" end
if (formatted_name) == "Trinite" then return "data/tiles/arctic_tile_12_oilrig.xml" end
if (formatted_name) == "Tajin" then return "data/tiles/arctic_island_playerbase.xml" end
--Desert Tiles
if (formatted_name) == "NorthMeier" then return "data/tiles/arid_island_5_14.xml" end
if (formatted_name) == "Uran" then return "data/tiles/arid_island_8_15.xml" end
if (formatted_name) == "Serpentine" then return "data/tiles/arid_island_6_7.xml" end
if (formatted_name) == "Ender" then return "data/tiles/arid_island_7_5.xml" end
if (formatted_name) == "Brainz" then return "data/tiles/arid_island_11_14.xml" end
if (formatted_name) == "Mauve" then return "data/tiles/arid_island_12_10.xml" end
if (formatted_name) == "Monkey" then return "data/tiles/arid_island_19_12.xml" end
if (formatted_name) == "Clarke" then return "data/tiles/arid_island_19_11.xml" end
if (formatted_name) == "JSI" then return "data/tiles/arid_island_24_3.xml" end
if (formatted_name) == "FJWarner" then return "data/tiles/arid_island_26_14.xml" end
--Desert Oil Deposits
if (formatted_name) == "CarnivoreDeposit" then return "data/tiles/arid_island_23_14.xml" end
if (formatted_name) == "JSIDeposit" then return "data/tiles/arid_island_24_4.xml" end
if (formatted_name) == "TurmoildDeposit" then return "data/tiles/arid_island_3_12.xml" end
if (formatted_name) == "ShymavanDeposit" then return "data/tiles/arid_island_8_11.xml" end
return "NotFound"
end