local PacificBankRob = {}
local Stage = 0

function PacificBankRob.init()
end

function PacificBankRob.tick()
	local playerPed = PLAYER.PLAYER_PED_ID()

		if(Stage==0) then
			
			local location = ENTITY.GET_ENTITY_COORDS( playerPed, nil )
				if (GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( 264.6, 213.5, 102.5 , location.x, location.y, location.z, true ) < 2 ) then
					if(PLAYER.GET_PLAYER_WANTED_LEVEL(PLAYER.GET_PLAYER_PED_SCRIPT_INDEX(playerPed))<3) then
										
					FIRE.ADD_EXPLOSION(location.x, location.y, location.z+10,1,1.0,false,false,0)
					
					PED.SET_PED_COMPONENT_VARIATION(playerPed, 9, 1, 0, 0)
					PLAYER.SET_PLAYER_WANTED_LEVEL(PLAYER.GET_PLAYER_PED(playerPed),4,false)
					PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(PLAYER.GET_PLAYER_PED(playerPed),false)
					Stage = 1
						
					end
				end
	else if not(ENTITY.IS_ENTITY_DEAD(playerPed)) then
			
			local location = ENTITY.GET_ENTITY_COORDS( playerPed, nil )
			
			if (GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( 248.634, 220.423, 108.663 , location.x, location.y, location.z, true ) < 42 )
			then
				
			if(PLAYER.GET_PLAYER_WANTED_LEVEL(PLAYER.GET_PLAYER_PED_SCRIPT_INDEX(playerPed))<5) then

					PLAYER.SET_PLAYER_WANTED_LEVEL(PLAYER.GET_PLAYER_PED(playerPed),5,false)
					PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(PLAYER.GET_PLAYER_PED(playerPed),false)
					PLAYER.SET_PLAYER_WANTED_LEVEL(PLAYER.GET_PLAYER_PED(playerPed),4,false)
					PLAYER.SET_PLAYER_WANTED_LEVEL_NOW(PLAYER.GET_PLAYER_PED(playerPed),false)
				end
			end
			
			-- if(PLAYER.GET_PLAYER_WANTED_LEVEL(PLAYER.GET_PLAYER_PED_SCRIPT_INDEX(playerPed))<1) then
			
		if not(PLAYER.IS_PLAYER_WANTED_LEVEL_GREATER(PLAYER.GET_PLAYER_PED(playerPed),0)) then

			if (PED.IS_PED_MODEL(playerPed, GAMEPLAY.GET_HASH_KEY("player_zero"))) then
			model = 0
		elseif (PED.IS_PED_MODEL(playerPed, GAMEPLAY.GET_HASH_KEY("player_one"))) then                                
			model = 1                                         
		elseif (PED.IS_PED_MODEL(playerPed, GAMEPLAY.GET_HASH_KEY("player_two"))) then
			model = 2
		end
					local statname = "SP"..model.."_TOTAL_CASH"
					local hash = GAMEPLAY.GET_HASH_KEY(statname)
					local bool, score = STATS.STAT_GET_INT(hash, 0, -1)
					UI.DISPLAY_CASH(true)
					STATS.STAT_SET_INT(hash, score+math.random(35000,75000), true)
					PED.SET_PED_COMPONENT_VARIATION(playerPed, 9, 0, 0, 0)
					AUDIO.PLAY_MISSION_COMPLETE_AUDIO("FRANKLIN_BIG_01")	
					Stage=0
			end
		else
		Stage = 0
		end
	end 
end

function PacificBankRob.unload()

end

return PacificBankRob