Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local KEY_ALERT = GetModConfigData("Key_Alert")
- local ICON_HEAL = GetModConfigData("Icon_Heal")
- local ICON_METEOR = GetModConfigData("Icon_Meteor")
- local ICON_PETRIFY = GetModConfigData("Icon_Petrify")
- local ICON_DEAD = GetModConfigData("Icon_Dead")
- local LANGUAGE = GetModConfigData("Language")
- local DISABLE_ICONS = GetModConfigData("Disable_Icons")
- local KEY_REFRESH = GetModConfigData("Key_Refresh")
- local Player
- local Widget = GLOBAL.require("widgets/widget")
- local Image = GLOBAL.require("widgets/image")
- local ImageButton = GLOBAL.require("widgets/imagebutton")
- local Button = GLOBAL.require("widgets/button")
- --[[local ICONS = {
- ICON_HEAL,
- ICON_METEOR,
- ICON_PETRIFY,
- ICON_DEAD
- }]]--
- local cantButtons = 2
- local button = {}
- local icon_button = {}
- local actual_item = nil
- local button_order = {1,2}
- local player_dead = false
- local finish_init = false
- local default_icon = {
- "blowdart_lava",
- "skull_wes"
- }
- local weapons = {
- --"blowdart_lava",
- "healingstaff",
- "fireballstaff",
- "book_fossil"
- --[["spear",
- "axe",
- "pickaxe",
- "shovel"]]--
- }
- local lang = {}
- lang["en"] = 1
- lang["es"] = 2
- lang["chs"] = 3
- lang["cht"] = 4
- local heal_phrase = {
- "HEAL (DON'T ATTACK)",
- "VOY A CURAR (NO ATAQUEN)",
- "治疗术(停止攻击)",
- "治療術(停止攻擊)"
- }
- local meteor_phrase = {
- "METEOR",
- "METEORITO",
- "陨石!",
- "陨石!"
- }
- local petrify_phrase = {
- "PETRIFY (DON'T ATTACK)",
- "PETRIFICARE (NO ATAQUEN)",
- "石化术(请勿攻击)",
- "石化術(請勿攻擊)"
- }
- local dead_phrase = {
- "NEED RESURRECTION",
- "RESUCITENME",
- "请求复活",
- "請求復活"
- }
- if (DISABLE_ICONS == "true") then
- ICON_HEAL = ""
- ICON_METEOR = ""
- ICON_PETRIFY = ""
- ICON_DEAD = ""
- else
- if (ICON_HEAL ~= "false") then
- ICON_HEAL = ":"..ICON_HEAL..":"
- else
- ICON_HEAL = ""
- end
- if (ICON_METEOR ~= "false") then
- ICON_METEOR = ":"..ICON_METEOR..":"
- else
- ICON_METEOR = ""
- end
- if (ICON_PETRIFY ~= "false") then
- ICON_PETRIFY = ":"..ICON_PETRIFY..":"
- else
- ICON_PETRIFY = ""
- end
- if (ICON_DEAD ~= "false") then
- ICON_DEAD = ":"..ICON_DEAD..":"
- else
- ICON_DEAD = ""
- end
- end
- local function IsInItemGroup(item,group)
- for i,v in pairs(group) do
- if (item ~= nil and v == item) then
- return true
- end
- end
- return false
- end
- local function SendAlert(index)
- --GLOBAL.TheNet:Say(tostring(Player.replica.health:IsDead()),true)
- if (not Player.replica.health:IsDead()) then
- --GLOBAL.TheNet:Say(tostring(actual_item),true)
- if (actual_item ~= nil) then
- if (actual_item.prefab == "healingstaff") then
- GLOBAL.TheNet:Say(ICON_HEAL.." "..heal_phrase[lang[LANGUAGE]],false)
- elseif (actual_item.prefab == "fireballstaff") then
- GLOBAL.TheNet:Say(ICON_METEOR.." "..meteor_phrase[lang[LANGUAGE]],false)
- elseif (actual_item.prefab == "book_fossil") then
- GLOBAL.TheNet:Say(ICON_PETRIFY.." "..petrify_phrase[lang[LANGUAGE]],false)
- end
- end
- else
- GLOBAL.TheNet:Say(ICON_DEAD.." "..dead_phrase[lang[LANGUAGE]],false)
- end
- end
- local function IsInGroup(item,group)
- if (item ~= nil) then
- for i,v in pairs(group) do
- if (v == item.prefab) then
- return true
- end
- end
- end
- return false
- end
- local function IsItemEquipped(item)
- return IsInItemGroup(item, Player.replica.inventory:GetEquips())
- end
- local function ChangeButtonIconItem(index,item)
- if (item ~= nil) then
- if (icon_button[index] ~= nil and button[index] ~= nil) then
- button[index]:RemoveChild(icon_button[index])
- icon_button[index]:Kill()
- icon_button[index] = Image(item.replica.inventoryitem:GetAtlas(),item.replica.inventoryitem:GetImage())
- icon_button[index]:SetScale(0.8,0.8,0.8)
- button[index]:AddChild(icon_button[index])
- end
- end
- end
- local function ChangeButtonIcon(index)
- if (icon_button[index] ~= nil and button[index] ~= nil) then
- icon_button[index]:SetTint(1,1,1,1)
- end
- end
- local function CheckButtonItem(item)
- if (not Player.replica.health:IsDead()) then
- if (IsInGroup(item,weapons)) then
- actual_item = item
- ChangeButtonIconItem(1,actual_item)
- button[1]:Show()
- end
- end
- end
- local function CheckButton()
- if (Player.replica.health:IsDead()) then
- ChangeButtonIcon(2)
- button[2]:Show()
- end
- end
- local function ClearButton(index)
- actual_item = nil
- if (icon_button[index] ~= nil and button[index] ~= nil) then
- button[index]:RemoveChild(icon_button[index])
- icon_button[index]:Kill()
- if (default_icon[index] ~= nil) then
- icon_button[index] = Image("images/inventoryimages.xml",default_icon[index]..".tex")
- else
- icon_button[index] = Image("images/inventoryimages.xml","spear.tex")
- end
- icon_button[index]:SetScale(0.8,0.8,0.8)
- icon_button[index]:SetTint(0,0,0,0.7)
- button[index]:AddChild(icon_button[index])
- button[index]:Hide()
- end
- end
- local function ClearAllButton()
- for i=1, cantButtons do
- ClearButton(i)
- end
- end
- local function CheckAllButton()
- if (finish_init) then
- ClearAllButton()
- for i,v in pairs(Player.replica.inventory:GetEquips()) do
- CheckButtonItem(v)
- end
- if (Player.replica.inventory:GetActiveItem() ~= nil) then
- CheckButtonItem(Player.replica.inventory:GetActiveItem())
- end
- CheckButton()
- end
- end
- local function InventoryEvents(inst)
- --EQUIP EVENT--
- inst:ListenForEvent("equip", function(inst, data)
- --GLOBAL.TheNet:Say("equip, "..tostring(data.item),true)
- CheckAllButton()
- end)
- --UNEQUIP EVENT--
- inst:ListenForEvent("unequip", function(inst, data)
- --GLOBAL.TheNet:Say("unequip",true)
- CheckAllButton()
- end)
- --ATTACKED EVENT--
- inst:ListenForEvent("healthdelta", function(inst, data)
- --GLOBAL.TheNet:Say("healthdelta",true)
- if (Player.replica.health:IsDead()) then
- --GLOBAL.TheNet:Say("dead",true)
- --player_dead = true
- CheckAllButton()
- end
- end)
- --[[inst:ListenForEvent("healthdelta", function(inst, data)
- GLOBAL.TheNet:Say("healthdelta",true)
- if (Player.replica.health:IsDead()) then
- --GLOBAL.TheNet:Say("dead",true)
- player_dead = true
- CheckAllButton()
- else
- player_dead = false
- CheckAllButton()
- end
- end)]]--
- end
- local function AddKeybindButton(index)
- button[index] = Player.HUD.controls.bottom_root:AddChild(ImageButton("images/hud.xml","inv_slot_spoiled.tex","inv_slot.tex","inv_slot_spoiled.tex","inv_slot_spoiled.tex","inv_slot_spoiled.tex"))
- local x = 0--68*(button_order[index]-1)
- button[index]:SetScale(0.8,0.8,0.8)
- button[index]:SetPosition(x,150,0)
- button[index]:SetOnClick(function(inst) return SendAlert() end)
- button[index]:MoveToFront()
- if (default_icon[index] ~= nil) then
- icon_button[index] = Image("images/inventoryimages.xml",default_icon[index]..".tex")
- else
- icon_button[index] = Image("images/inventoryimages.xml","spear.tex")
- end
- icon_button[index]:SetScale(0.8,0.8,0.8)
- icon_button[index]:SetTint(0,0,0,0.7)
- button[index]:AddChild(icon_button[index])
- end
- local function InitKeybindButtons()
- for i=1, cantButtons do
- icon_button[i] = nil
- end
- AddKeybindButton(1)
- AddKeybindButton(2)
- finish_init = true
- end
- --AddClassPostConstruct("widgets/inventorybar", InitKeybindButtons)
- local function Init(inst)
- inst:DoTaskInTime(1,function()
- Player = GLOBAL.ThePlayer
- InitKeybindButtons()
- InventoryEvents(inst)
- CheckAllButton()
- end)
- end
- AddPlayerPostInit(Init)
- local function IsDefaultScreen()
- if GLOBAL.TheFrontEnd:GetActiveScreen() and GLOBAL.TheFrontEnd:GetActiveScreen().name and type(GLOBAL.TheFrontEnd:GetActiveScreen().name) == "string" and GLOBAL.TheFrontEnd:GetActiveScreen().name == "HUD" then
- return true
- else
- return false
- end
- end
- local TKey = "T"
- --[[GLOBAL.TheInput:AddKeyUpHandler(
- TKey:lower():byte(),
- function()
- if not GLOBAL.IsPaused() and IsDefaultScreen() then
- GLOBAL.TheNet:Say(tostring(Player.replica.health:IsDead()),true)
- end
- end
- )]]--
- if (KEY_ALERT ~= "false") then
- GLOBAL.TheInput:AddKeyUpHandler(
- KEY_ALERT:lower():byte(),
- function()
- if not GLOBAL.IsPaused() and IsDefaultScreen() then
- SendAlert()
- end
- end
- )
- end
- if (KEY_REFRESH ~= "false") then
- GLOBAL.TheInput:AddKeyUpHandler(
- KEY_REFRESH:lower():byte(),
- function()
- if not GLOBAL.IsPaused() and IsDefaultScreen() then
- CheckAllButton()
- end
- end
- )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement