-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_collected = g_collected or {} g_foraged = g_foraged or {} local objScale = {} local miningZone = {} local objChances = {} local objMined = {} local objCollected = {} local objTimer = {} local U = require "scriptbank\\utillib" local random = math.random function survival_mining_init_name(e, name) Include( "utillib.lua" ) objScale[e] = random(70, 100) Scale(e, objScale[e]) g_collected[e] = { name = name, randMax = g_Entity[e].health } local foraged = g_foraged if name == 'Metal Ores' then if foraged['Lead' ] == nil then g_foraged['Lead' ] = {amount = 0} end if foraged['Iron' ] == nil then g_foraged['Iron' ] = {amount = 0} end if foraged['Copper'] == nil then g_foraged['Copper'] = {amount = 0} end else if foraged['Sulphur' ] == nil then g_foraged['Sulphur' ] = {amount = 0} end if foraged['Saltpeter'] == nil then g_foraged['Saltpeter'] = {amount = 0} end if foraged['Carbon' ] == nil then g_foraged['Carbon' ] = {amount = 0} end end end local function chooseRandomChances( e, name ) if name == 'Metal Ores' then objChances[e] = {iron = random(1, 7), copper = random(1, 7), lead = random(1, 7)} else objChances[e] = {sulphur = random(1, 7), saltpeter = random(1, 7), carbon = random(1, 7)} end end function survival_mining_main(e) local collect = g_collected[e] if collect == nil then return end local chance = objChances[e] if chance == nil then chooseRandomChances( e, collect.name ) return end local inZone = miningZone[e] local foraged = g_foraged if inZone == nil then if ZonePointIn ~= nil then local Ent = g_Entity[e] local zName = ZonePointIn( Ent.x, Ent.z ) if zName ~= 'None' then miningZone[e] = zName end end elseif foraged["Hammers Crafted"] ~= nil then if not PlayerIsInZone( inZone ) then return end if not U.PlayerLookingNear( e, 200, 110 ) then return end if not objMined[e] then PromptDuration("This area looks good to Mine for " .. collect.name, 3000) objMined[e] = true objTimer[e] = g_Time + 100 * 1000 -- 100 seconds end if not objCollected[e] then if g_PlayerGunFired == 1 then PlaySound(e, 1) objCollected[e] = true end end else return end if objCollected[e] and g_PlayerGunFired == 0 then objScale[e] = objScale[e] - random(1, 3) Scale(e, objScale[e]) objCollected[e] = false if collect.name == 'Metal Ores' then if random(0, 10) > chance.iron then foraged['Iron'].amount = foraged['Iron'].amount + 1 end if random(0, 10) > chance.copper then foraged['Copper'].amount = foraged['Copper'].amount + 1 end if random(0, 10) > chance.lead then foraged['Lead'].amount = foraged['Lead'].amount + 1 end PromptDuration("You have " .. foraged['Iron'].amount .. " Iron, " .. foraged['Lead'].amount .. " Lead and " .. foraged['Copper'].amount .. " Copper.", 2000) else if random(0, 10) > chance.sulphur then foraged['Sulphur'].amount = foraged['Sulphur'].amount + 1 end if random(0, 10) > chance.saltpeter then foraged['Saltpeter'].amount = foraged['Saltpeter'].amount + 1 end if random(0, 10) > chance.carbon then foraged['Carbon'].amount = foraged['Carbon'].amount + 1 end PromptDuration("You have " .. foraged['Sulphur'].amount .. " Sulphur, " .. foraged['Saltpeter'].amount .. " Saltpeter and " .. foraged['Carbon'].amount .. " Carbon.", 2000) end if objScale[e] < 10 then Destroy(e) end end if objMined[e] and g_Time > objTimer[e] then objMined[e] = false objTimer[e] = math.huge end end