2019-10-20 14:28:17 +00:00
|
|
|
-- Copyright (c) 2019 David Vogel
|
|
|
|
--
|
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
2019-10-22 20:48:43 +00:00
|
|
|
function SplitStringByLength(string, length)
|
2019-10-20 14:28:17 +00:00
|
|
|
local chunks = {}
|
|
|
|
for i = 1, #string, length do
|
|
|
|
table.insert(chunks, string:sub(i, i + length - 1))
|
|
|
|
end
|
|
|
|
return chunks
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Improved version of GamePrint, that behaves more like print.
|
2019-10-22 20:48:43 +00:00
|
|
|
local oldGamePrint = GamePrint
|
|
|
|
function GamePrint(...)
|
2019-10-20 14:28:17 +00:00
|
|
|
local arg = {...}
|
|
|
|
|
|
|
|
local result = ""
|
|
|
|
|
|
|
|
for i, v in ipairs(arg) do
|
|
|
|
result = result .. tostring(v) .. " "
|
|
|
|
end
|
|
|
|
|
|
|
|
for line in result:gmatch("[^\r\n]+") do
|
|
|
|
for i, v in ipairs(splitStringByLength(line, 100)) do
|
2019-10-22 20:48:43 +00:00
|
|
|
oldGamePrint(v)
|
2019-10-20 14:28:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-22 20:48:43 +00:00
|
|
|
function getPlayer()
|
|
|
|
local players = EntityGetWithTag("player_unit")
|
|
|
|
if players == nil or #players < 1 then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return players[1]
|
|
|
|
end
|
2019-10-20 14:28:17 +00:00
|
|
|
|
2019-10-22 20:48:43 +00:00
|
|
|
function getPlayerPos()
|
|
|
|
return EntityGetTransform(getPlayer())
|
|
|
|
end
|
|
|
|
|
|
|
|
function teleportPlayer(x, y)
|
|
|
|
EntitySetTransform(getPlayer(), x, y)
|
|
|
|
end
|
|
|
|
|
|
|
|
function setPlayerHP(hp)
|
|
|
|
local damagemodels = EntityGetComponent(getPlayer(), "DamageModelComponent")
|
|
|
|
|
|
|
|
if damagemodels ~= nil then
|
|
|
|
for i, damagemodel in ipairs(damagemodels) do
|
|
|
|
ComponentSetValue(damagemodel, "max_hp", hp)
|
|
|
|
ComponentSetValue(damagemodel, "hp", hp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function addEffectToEntity(entity, gameEffect)
|
|
|
|
local gameEffectComp = GetGameEffectLoadTo(entity, gameEffect, true)
|
|
|
|
if gameEffectComp ~= nil then
|
|
|
|
ComponentSetValue(gameEffectComp, "frames", "-1")
|
2019-10-20 14:28:17 +00:00
|
|
|
end
|
2019-10-22 20:48:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function addPerkToPlayer(perkID)
|
|
|
|
local playerEntity = getPlayer()
|
|
|
|
local x, y = getPlayerPos()
|
|
|
|
local perkData = get_perk_with_id(perk_list, perkID)
|
|
|
|
|
|
|
|
-- Add effect
|
|
|
|
addEffectToEntity(playerEntity, perkData.game_effect)
|
|
|
|
|
|
|
|
-- Add ui icon etc
|
2019-10-23 01:25:38 +00:00
|
|
|
--[[local perkIcon = EntityCreateNew("")
|
2019-10-22 20:48:43 +00:00
|
|
|
EntityAddComponent(
|
|
|
|
perkIcon,
|
|
|
|
"UIIconComponent",
|
|
|
|
{
|
|
|
|
name = perkData.ui_name,
|
|
|
|
description = perkData.ui_description,
|
|
|
|
icon_sprite_file = perkData.ui_icon
|
|
|
|
}
|
|
|
|
)
|
2019-10-23 01:25:38 +00:00
|
|
|
EntityAddChild(playerEntity, perkIcon)]]
|
2019-10-20 14:28:17 +00:00
|
|
|
|
2019-10-22 20:48:43 +00:00
|
|
|
--local effect = EntityLoad("data/entities/misc/effect_protection_all.xml", x, y)
|
|
|
|
--EntityAddChild(playerEntity, effect)
|
2019-10-20 14:28:17 +00:00
|
|
|
end
|
2019-10-23 18:03:03 +00:00
|
|
|
|
|
|
|
function fileExists(fileName)
|
|
|
|
local f = io.open(fileName, "r")
|
|
|
|
if f ~= nil then
|
|
|
|
io.close(f)
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2019-11-02 20:37:10 +00:00
|
|
|
|
|
|
|
function progressBarString(progress, look)
|
|
|
|
local factor = progress.Progress / progress.Max
|
|
|
|
local count = math.ceil(look.BarLength * factor)
|
|
|
|
local barString = string.rep(look.CharFull, count) .. string.rep(look.CharEmpty, look.BarLength - count)
|
|
|
|
|
|
|
|
return string.format(look.Format, barString, progress.Progress, progress.Max, factor * 100)
|
|
|
|
end
|