-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
45 lines (36 loc) · 1.38 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
if not (ResdaynCore or ResdaynMining) then return end
---@class smeltine
local smelting = {}
smelting.recipes = require("custom.resdaynSmelting.recipes")
smelting.config = require("custom.resdaynSmelting.config")
---@param pid integer
---@return boolean isInRange
function smelting.isInRange(pid)
for i=1, #smelting.config.locations, 1 do
if -(smelting.config.locations[i] - ResdaynCore.functions.getPlayerCoords(pid) < smelting.config.maxRadius) then
return true
end
end
return false
end
---@param seconds integer
function smelting.smeltingProcess(seconds)
local interval, elapsed = seconds / 4, 0
while elapsed < seconds do
elapsed = elapsed + interval
ResdaynCore.functions.Wait(interval)
end
end
---@param pid integer
---@param targetMat string
function smelting.startSmelting(pid, targetMat)
if not (targetMat or smelting.recipes[targetMat]) then return end
if not smelting.isInRange(pid) then return end
local player = Players[pid]
local input, output = smelting.recipes[targetMat].requirement, smelting.recipes[targetMat].output
if tes3mp.GetInventoryItemCount(pid, input.item) < input.amount then return end
ResdaynCore.functions.removeItem(player, input.item, input.amount)
smelting.smeltingProcess(input.time)
ResdaynCore.functions.addItem(player, output.item, output.amount)
end
return smelting