Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- broadcast = true
- function onLoad(save_state)
- local loaded = JSON.decode(save_state)
- if loaded ~= nil then
- Wait.frames(function() loadHP(loaded) end, 5)
- broadcast = loaded.broadcast
- end
- end
- function loadHP(hp)
- Global.UI.setAttribute("HP Bars", "height", hp.tableHeight)
- for i=1, 4 do
- if hp["P" .. i] ~= nil then
- Global.UI.setAttribute("P" .. i .. "_Table", "active", hp["P" .. i].table)
- Global.UI.setAttribute("P" .. i .. "_name", "text", hp["P" .. i].name)
- Global.UI.setAttribute("P" .. i .. "_totalhp", "text", hp["P" .. i].hp)
- Global.UI.setAttribute("P" .. i .. "_hp_bar", "percentage", tonumber(hp["P" .. i].hp:match("(%d+)/")) / tonumber(hp["P" .. i].hp:match("/(%d+)")) * 100)
- Global.UI.setAttribute("P" .. i .. "_totalstam", "text", hp["P" .. i].stam)
- Global.UI.setAttribute("P" .. i .. "_stam_bar", "percentage", tonumber(hp["P" .. i].stam:match("(%d+)/")) / tonumber(hp["P" .. i].stam:match("/(%d+)")) * 100)
- Global.UI.setAttribute("F" .. i .. "_Table", "active", hp["F" .. i].table)
- Global.UI.setAttribute("F" .. i .. "_name", "text", hp["F" .. i].name)
- Global.UI.setAttribute("F" .. i .. "_totalhp", "text", hp["F" .. i].hp)
- Global.UI.setAttribute("F" .. i .. "_hp_bar", "percentage", tonumber(hp["F" .. i].hp:match("(%d+)/")) / tonumber(hp["F" .. i].hp:match("/(%d+)")) * 100)
- end
- end
- end
- function onSave()
- local saveState = {
- P1 = {}
- , P2 = {}
- , P3 = {}
- , P4 = {}
- , F1 = {}
- , F2 = {}
- , F3 = {}
- , F4 = {}
- , tableHeight = Global.UI.getAttribute("HP Bars", "height")
- , broadcast = broadcast
- }
- for i=1, 4 do
- saveState["P" .. i].table = Global.UI.getAttribute("P" .. i .. "_Table", "active")
- saveState["P" .. i].name = Global.UI.getAttribute("P" .. i .. "_name", "text")
- saveState["P" .. i].hp = Global.UI.getAttribute("P" .. i .. "_totalhp", "text")
- saveState["P" .. i].stam = Global.UI.getAttribute("P" .. i .. "_totalstam", "text")
- saveState["F" .. i].table = Global.UI.getAttribute("F" .. i .. "_Table", "active")
- saveState["F" .. i].name = Global.UI.getAttribute("F" .. i .. "_name", "text")
- saveState["F" .. i].hp = Global.UI.getAttribute("F" .. i .. "_totalhp", "text")
- end
- saved_data = JSON.encode(saveState)
- self.script_state = saved_data
- end
- function showHPBar(player, value, id)
- if Global.UI.getAttribute("Bars Config", "active") == "false" then
- for i=1, 4 do
- if Global.UI.getAttribute("P" .. i .. "_Table", "active") == "true" or Global.UI.getAttribute("P" .. i .. "_Table", "active") == "True" then
- Global.UI.setAttribute("P" .. i .. "Name", "text", Global.UI.getAttribute("P" .. i .. "_name", "text"))
- Global.UI.setAttribute("P" .. i, "isOn", "true")
- if Global.UI.getAttribute("F" .. i .. "_Table", "active") == "true" or Global.UI.getAttribute("F" .. i .. "_Table", "active") == "True" then
- Global.UI.setAttribute("F" .. i .. "Name", "text", Global.UI.getAttribute("F" .. i .. "_name", "text"))
- Global.UI.setAttribute("F" .. i, "isOn", "true")
- end
- end
- end
- Global.UI.show("Bars Config")
- Global.UI.setAttribute("Bars Config", "active", "true")
- else
- Global.UI.hide("Bars Config")
- Global.UI.setAttribute("Bars Config", "active", "false")
- end
- end
- function onClick(player, value, id)
- local classes = {
- P1 = {
- -- colorHex = "#B22A28", color = {0.70, 0.16, 0.15}, class = Global.UI.getAttribute("P1_name", "text")
- colorHex = "#B22A28", color = {1, 1, 1}, class = Global.UI.getAttribute("P1_name", "text"), companion = Global.UI.getAttribute("F1_name", "text")
- },
- P2 = {
- colorHex = "#B22A28", color = {1, 1, 1}, class = Global.UI.getAttribute("P2_name", "text"), companion = Global.UI.getAttribute("F2_name", "text")
- },
- P3 = {
- colorHex = "#B22A28", color = {1, 1, 1}, class = Global.UI.getAttribute("P3_name", "text"), companion = Global.UI.getAttribute("F3_name", "text")
- },
- P4 = {
- colorHex = "#B22A28", color = {1, 1, 1}, class = Global.UI.getAttribute("P4_name", "text"), companion = Global.UI.getAttribute("F4_name", "text")
- },
- stamina = {
- colorHex = "#E8CE74", color = {1, 1, 1}
- },
- companion = {
- colorHex = "#721413", color = {1, 1, 1}
- },
- stam = "Strain",
- hp = "Health"
- }
- classes["hp1"] = " gained 1 Health"
- classes["hp-1"] = " lost 1 Health"
- classes["stam1"] = " gained 1 Strain"
- classes["stam-1"] = " used 1 Strain"
- local bar = id:sub(1,1) == "H" and "hp" or "stam"
- local max = id:sub(2,2) == "M" and "max" or "act"
- local change = id:sub(3,3) == "U" and 1 or -1
- local barText = Global.UI.getAttribute(value .. "_total" .. bar, "text")
- local stats = {act = barText:match("(%d+)/"), max = barText:match("/(%d+)")}
- stats[max] = stats[max] + change
- if tonumber(stats[max]) < 0 then stats[max] = 0 end
- if max == "max" then
- stats.act = stats.max
- else
- -- if tonumber(stats.act) > tonumber(stats.max) then stats.act = stats end
- if tonumber(stats.act) > tonumber(stats.max) then return end
- if broadcast then
- if value:sub(1,1) == "P" then
- broadcastToAll(classes[value].class .. classes[bar .. change], classes[value].color)
- else
- broadcastToAll(classes["P" .. value:sub(2,2)].companion .. ", the Companion of " .. classes["P" .. value:sub(2,2)].class .. ", " .. classes[bar .. change], classes.companion.color)
- end
- end
- end
- Global.UI.setAttribute(value .. "_total" .. bar, "text", stats.act .. "/" .. stats.max)
- Global.UI.setAttribute(value .. "_" .. bar .. "_bar", "percentage", stats.act / stats.max * 100)
- end
- function toggle(player, value, id)
- Global.UI.setAttribute(id, "isOn", value)
- end
- function onValueChanged(player, value, id)
- Global.UI.setAttribute(id, "value", value)
- end
- function toggleBroadcast()
- broadcast = not broadcast
- if broadcast then
- broadcastToAll("Broadcast is now activated", {0,1,0})
- else
- broadcastToAll("Broadcast is now deactivated", {1,0,0})
- end
- end
- function changeBars(player, value, id)
- local totalHeight = 0
- for i=1,4 do
- local height = 100
- if Global.UI.getAttribute("F" .. i, "isOn") == "True" or Global.UI.getAttribute("F" .. i, "isOn") == "true" then
- Global.UI.setAttribute("F" .. i .. "_name", "text", Global.UI.getAttribute("F" .. i .. "Name", "value"))
- height = 150
- end
- if Global.UI.getAttribute("P" .. i, "isOn") == "True" or Global.UI.getAttribute("P" .. i, "isOn") == "true" then
- Global.UI.setAttribute("P" .. i .. "_Table", "minHeight", height)
- Global.UI.setAttribute("P" .. i .. "_name", "text", Global.UI.getAttribute("P" .. i .. "Name", "value"))
- totalHeight = totalHeight + height
- end
- Global.UI.setAttribute("P" .. i .. "_Table", "active", Global.UI.getAttribute("P" .. i, "isOn"))
- Global.UI.setAttribute("F" .. i .. "_Table", "active", Global.UI.getAttribute("F" .. i, "isOn"))
- end
- Global.UI.setAttribute("HP Bars", "height", totalHeight)
- showHPBar()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement