Skip to content

Instantly share code, notes, and snippets.

@Putnam3145 Putnam3145/force.lua
Last active Dec 25, 2015

Embed
What would you like to do?
force.lua. Some work, some don't, it's a crapshoot. It's mostly good enough to use, though.Updated a bit for once.
-- Forces an event.
local function findCiv(arg)
local entities = df.global.world.entities.all
if tonumber(arg) then return arg end
if arg and not tonumber(arg) then
for eid,entity in ipairs(entities) do
if entity.entity_raw.code == arg then return entity end
end
end
end
local args = {...}
if not args then qerror('Needs an argument. Valid arguments are caravan, migrants, diplomat, megabeast, curiousbeast, mischievousbeast, flier, siege and nightcreature. Second argument is civ, either raw entity ID or "player" for player\'s civ.') end
local EventType = string.lower(args[1])
forceEntity = args[2]=="player" and df.historical_entity.find(df.global.ui.civ_id) or findCiv(args[2])
if (EventType == "caravan" or EventType == "diplomat" or EventType == "siege") and not forceEntity then
qerror('caravan, diplomat and siege require a civilization ID to be included.')
end
local function eventTypeIsNotValid()
local eventTypes =
{
"caravan",
"migrants",
"diplomat",
"megabeast",
"curiousbeast",
"mischevousbeast",
"mischeviousbeast",
"flier",
"siege",
"nightcreature"
}
for _,v in ipairs(eventTypes) do
if args[1] == v then return false end
end
return true
end
--code may be kind of bad below :V Putnam ain't experienced in lua...
if eventTypeIsNotValid() then
qerror('Invalid argument. Valid arguments are caravan, migrants, diplomat, megabeast, curiousbeast, mischievousbeast, flier, siege and nightcreature.')
end
allEventTypes={
megabeast=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Megabeast, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end,
migrants=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Migrants, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = df.historical_entity.find(df.global.ui.civ_id) } )
end,
caravan=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Caravan, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = forceEntity } )
end,
diplomat=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.Diplomat, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = forceEntity } )
end,
curious=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeCurious, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end,
mischevousbeast=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeMichievous, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end,
mischeviousbeast=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeMichievous, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end,
flier=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.WildlifeFlier, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end,
siege=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.CivAttack, season = df.global.cur_season, season_ticks = df.global.cur_season_tick, entity = forceEntity } )
end,
nightcreature=function()
df.global.timed_events:insert('#', { new = df.timed_event, type = df.timed_event_type.NightCreature, season = df.global.cur_season, season_ticks = df.global.cur_season_tick } )
end
}
allEventTypes[EventType]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.