2021-09-10 20:53:48 +00:00
|
|
|
dofile("data/scripts/perks/perk.lua")
|
|
|
|
dofile("data/scripts/lib/utilities.lua")
|
|
|
|
dofile("data/scripts/lib/mod_settings.lua")
|
2021-08-12 02:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
function OnPlayerSpawned( player_entity )
|
|
|
|
|
|
|
|
-- Run this only once per game
|
|
|
|
local init_check_flag = "starting_perk_init_done"
|
|
|
|
if GameHasFlagRun( init_check_flag ) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
GameAddFlagRun( init_check_flag )
|
|
|
|
|
2021-09-10 20:53:48 +00:00
|
|
|
-- Load mod settings
|
2021-09-11 02:06:53 +00:00
|
|
|
local perks_amount = math.ceil(ModSettingGet("starting_perk.perks_spawned"))
|
2021-09-10 20:53:48 +00:00
|
|
|
local only_one = ModSettingGet("starting_perk.only_one")
|
2021-08-12 02:49:54 +00:00
|
|
|
|
2021-09-10 20:53:48 +00:00
|
|
|
-- Print mod settings to the player
|
|
|
|
if only_one then
|
|
|
|
GamePrint("Starting with a choice between " .. to_string(perks_amount) .. " perks")
|
|
|
|
else
|
|
|
|
GamePrint("Starting with " .. to_string(perks_amount) .. " free perks")
|
|
|
|
end
|
|
|
|
|
|
|
|
local x_center = 789
|
|
|
|
local y_bottom = -96
|
|
|
|
|
|
|
|
local gap = 6
|
|
|
|
local size = 14
|
|
|
|
local offset = gap + size
|
|
|
|
|
|
|
|
-- Find the number of rows
|
|
|
|
-- Ceil makes it wider instead of taller
|
|
|
|
local rows = math.ceil(math.sqrt(perks_amount))
|
|
|
|
|
|
|
|
-- Draw perk rows
|
|
|
|
for current_row = 1, rows, 1 do
|
|
|
|
|
|
|
|
-- Find the number of columns
|
|
|
|
local cols
|
|
|
|
if perks_amount < rows then
|
|
|
|
-- Spawn only the leftover amount
|
|
|
|
cols = perks_amount
|
|
|
|
else
|
|
|
|
-- Spawn the full amount
|
|
|
|
cols = rows
|
|
|
|
end
|
|
|
|
|
|
|
|
-- If there is something to spawn
|
|
|
|
if cols ~= 0 then
|
|
|
|
-- Find the total row width
|
|
|
|
local width = (offset * cols) + size
|
|
|
|
|
|
|
|
-- Find the X position to start spawning perks at
|
|
|
|
local x_left = x_center - (width / 2)
|
|
|
|
|
|
|
|
-- Draw perk columns
|
|
|
|
for current_col=1, cols, 1 do
|
|
|
|
|
|
|
|
-- Find the position to spawn each perk at
|
|
|
|
local x = x_left + (current_col - 1) * offset
|
|
|
|
local y = y_bottom - (current_row - 1) * offset
|
|
|
|
|
|
|
|
-- Spawn the perk
|
2021-09-10 21:41:49 +00:00
|
|
|
perk_spawn_random(x, y, not only_one)
|
2021-09-10 20:53:48 +00:00
|
|
|
|
|
|
|
perks_amount = perks_amount - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-09-10 21:41:49 +00:00
|
|
|
|
|
|
|
-- Used to take the screenshot
|
|
|
|
-- perk_spawn( 771, -96, "GENOME_MORE_LOVE" )
|
2021-08-12 02:49:54 +00:00
|
|
|
end
|