local g_miner_deployed = {} local g_miner_state = {} local g_miner_x = {} local g_miner_y = {} local g_miner_z = {} local g_miner_collected_amount = {} local tempscale = 0 local temptime = 0 local tempx = 0 local tempy = 0 local tempz = 0 pressed = 0 local new_mine_delay = {} local deploying_miner = 0 local recalling_miner = 0 local deploy_height = 50 --how high above terrain height to deploy the miner local deploy_distance = 200 --how far infront of player to deploy miner if g_miners_collected == nil then g_miners_collected = 2 --how many miners player has in inventory end if g_ores == nil then g_ores = 0 --number of ores player has in inventory (what the miner digs for) end local deploy_time = 2000 --how long to hold e to complete the install process local mine_delay = 6000 --how quickly the miner collects ore after being installed --miner will random an amount between these 2 values per dig local min_find = 1 local max_find = 2 local use_range = 220 --how far away you can be to interact with the miner local recall_delay = 4000 --how long to hold Q to put miner back into inventory function deployable_miner_init(e) if g_miner_deployed[e] == nil then g_miner_deployed[e] = 0 end if g_miner_state[e] == nil then g_miner_state[e] = "inventory" end if g_miner_collected_amount[e] == nil then g_miner_collected_amount[e] = 0 end end --sound0 = deploying sound --sound1 = mining loop --sound2 = dug ore --sound3 = take ore from miner --sound4 = dismantle sound function deployable_miner_main(e) Text(1,4,3,"You currently have "..g_ores.." ores") if g_miner_state[e] == "inventory" then CollisionOff(e) Text(1,1,3,"You have "..g_miners_collected.." auto miners in inventory, hold 'E' to deploy") if g_KeyPressE == 1 and (deploying_miner == 0 or deploying_miner == e) then if GetTimer(e) > deploy_time then StartTimer(e) new_mine_delay[e] = GetTimer(e)+mine_delay StopSound(e,0) PromptDuration("Deployed the Auto-Miner",2000) g_miners_collected = g_miners_collected - 1 g_miner_state[e] = "deployed" deploying_miner = 0 Scale(e,100) elseif GetTimer(e) > deploy_time*0.1 then deploying_miner = e tempscale = GetTimer(e)/deploy_time tempscale = 100*tempscale Scale(e,tempscale) SetFreezePosition(frzx,frzy,frzz) SetFreezeAngle(frzax,frzay,frzaz) TransportToFreezePosition() new_y = math.rad(g_PlayerAngY) tempx = g_PlayerPosX + (math.sin(new_y) * deploy_distance) tempz = g_PlayerPosZ + (math.cos(new_y) * deploy_distance) tempy = GetTerrainHeight(tempx,tempz)+deploy_height SetPosition(e,tempx,tempy,tempz) RotateToPlayer(e) Show(e) temptime = (deploy_time/1000)-((deploy_time/1000)-(GetTimer(e)/1000)) LoopSound(e,0) PromptLocal(e,"DEPLOYING "..round(temptime,1).."/"..(deploy_time/1000).."s") end else deploying_miner = 0 StopSound(e,0) SetPosition(e,g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) Hide(e) StartTimer(e) frzx = g_PlayerPosX frzy = g_PlayerPosY frzz = g_PlayerPosZ frzax = g_PlayerAngX frzay = g_PlayerAngY frzaz = g_PlayerAngZ end elseif g_miner_state[e] == "deployed" then vol = 110 - GetPlayerDistance(e)/30 if vol > 100 then vol = 100 elseif vol < 1 then vol = 1 end LoopSound(e,1) SetSoundVolume(vol) if GetTimer(e) > new_mine_delay[e] then StartTimer(e) g_miner_collected_amount[e] = g_miner_collected_amount[e] + math.random(min_find,max_find) PlaySound(e,2) end if PlayerLooking(e,use_range,20) == 1 then PromptLocal(e,"Auto-Miner has collected "..g_miner_collected_amount[e].." ores, Press E to take ores or hold Q to recall Auto-Miner") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 if g_miner_collected_amount[e] > 0 then g_ores = g_ores + g_miner_collected_amount[e] PromptDuration("Collected "..g_miner_collected_amount[e].." ores from the Auto-Miner",2000) g_miner_collected_amount[e] = 0 PlaySound(e,3) else PromptDuration("No ores to collect yet",2000) end end if g_Scancode == 16 then StartTimer(e) frzx = g_PlayerPosX frzy = g_PlayerPosY frzz = g_PlayerPosZ frzax = g_PlayerAngX frzay = g_PlayerAngY frzaz = g_PlayerAngZ g_miner_state[e] = "recalling" end end elseif g_miner_state[e] == "recalling" then if g_Scancode == 16 and (recalling_miner == 0 or recalling_miner == e) then SetFreezePosition(frzx,frzy,frzz) SetFreezeAngle(frzax,frzay,frzaz) TransportToFreezePosition() LoopSound(e,4) StopSound(e,1) if GetTimer(e) > recall_delay then StopSound(e,4) StartTimer(e) recalling_miner = 0 g_miner_state[e] = "inventory" g_ores = g_ores + g_miner_collected_amount[e] g_miners_collected = g_miners_collected + 1 PromptDuration("Recalled the Auto-Miner",2000) elseif GetTimer(e) > recall_delay*0.1 then recalling_miner = e temptime = (recall_delay/1000)-((recall_delay/1000)-(GetTimer(e)/1000)) PromptLocal(e,"Recalling the Auto-Miner, "..round(temptime,1).."/"..(recall_delay/1000).."s") tempscale = GetTimer(e)/recall_delay tempscale = 100-(100*tempscale) Scale(e,tempscale) end else recalling_miner = 0 Scale(e,100) g_miner_state[e] = "deployed" StopSound(e,4) end end if g_KeyPressE == 0 then pressed = 0 end --Prompt(miner_deployed[e].." "..miner_state[e]) end --main function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end