
--Local Variables
local myProcessTime = 0
local myResourceSpawnLocation = math.random(1,10)
local myResourceSpawned = false
local myNextResourceSpawn = 0

--Global Variables
gPickedMoney = false
gResource1 = false
gResource2 = false
gResource3 = false
gResource4 = false
gResource5 = false
gResource6 = false
gResource7 = false
gResource8 = false
gResource9 = false
gResource10 = false

--Resource Positions
local myResourcePosition1x = -102
local myResourcePosition1y = 359
local myResourcePosition2x = -107
local myResourcePosition2y = 103
local myResourcePosition3x = -357
local myResourcePosition3y = 13
local myResourcePosition4x = -246
local myResourcePosition4y = -85
local myResourcePosition5x = -111
local myResourcePosition5y = -144
local myResourcePosition6x = 56
local myResourcePosition6y = -388
local myResourcePosition7x = 383
local myResourcePosition7y = -75
local myResourcePosition8x = 246
local myResourcePosition8y = 35
local myResourcePosition9x = 46
local myResourcePosition9y = 140
local myResourcePosition10x = 394
local myResourcePosition10y = -311


function SpawnResources_Init()
	Event.SetStatus("SpawnResources",true)		
end


function SpawnResources_Activate()
	myProcessTime = 0	
end


function SpawnResources_Update(someElapsedTime)	

	myProcessTime = myProcessTime + someElapsedTime
	myResourceSpawnLocation = math.random(1,10)
	
	if(gPickedMoney == true)
	then
		myProcessTime = 0
		myResourceSpawned = false
	end
	
	if(gPickedMoney == true and myResourceSpawned == false)
	then
		myNextResourceSpawn = myNextResourceSpawn + someElapsedTime
	end
	
	if(myNextResourceSpawn >= 2)
	then
		gPickedMoney = false
		myNextResourceSpawn = 0
	end
	
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 1)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource1()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 2)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource2()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 3)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource3()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 4)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource4()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 5)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource5()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 6)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource6()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 7)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource7()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 8)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource8()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 9)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource9()
	end
	
	if(myProcessTime >= 30 and gPickedMoney == false and myResourceSpawned == false and myResourceSpawnLocation == 10)
	then
		myResourceSpawned = true
		myProcessTime = 0	
		Resource10()
	end

end


function SpawnResources_Deactivate()	

end


function Resource1()
	Game.AddObject("ResourcePickup",myResourcePosition1x,myResourcePosition1y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition1x,myResourcePosition1y)
	gResource1 = true
end 

function Resource2()
	Game.AddObject("ResourcePickup",myResourcePosition2x,myResourcePosition2y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition2x,myResourcePosition3y)
	gResource2 = true
end 

function Resource3()
	Game.AddObject("ResourcePickup",myResourcePosition3x,myResourcePosition3y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition3x,myResourcePosition3y)
	gResource3 = true
end 

function Resource4()
	Game.AddObject("ResourcePickup",myResourcePosition4x,myResourcePosition4y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition4x,myResourcePosition4y)
	gResource4 = true
end 

function Resource5()
	Game.AddObject("ResourcePickup",myResourcePosition5x,myResourcePosition5y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition5x,myResourcePosition5y)
	gResource5 = true
end 

function Resource6()
	Game.AddObject("ResourcePickup",myResourcePosition6x,myResourcePosition6y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition6x,myResourcePosition6y)
	gResource6 = true
end 

function Resource7()
	Game.AddObject("ResourcePickup",myResourcePosition7x,myResourcePosition7y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition7x,myResourcePosition7y)
	gResource7 = true
end 

function Resource8()
	Game.AddObject("ResourcePickup",myResourcePosition8x,myResourcePosition8y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition8x,myResourcePosition8y)
	gResource8 = true
end 

function Resource9()
	Game.AddObject("ResourcePickup",myResourcePosition9x,myResourcePosition9y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition9x,myResourcePosition9y)
	gResource9 = true
end 

function Resource10()
	Game.AddObject("ResourcePickup",myResourcePosition10x,myResourcePosition10y)
	Game.AddObjective("Find the loot for more resources",false)
	Game.AddGold(myResourcePosition10x,myResourcePosition10y)
	gResource10 = true
end 