ФЭНДОМ


function c_sel()return GetDebugEntity()end____________________________________________________________________________function c_select(inst)return SetDebugEntity(inst)end____________________________________________________________________________function c_tile()local s = "" local ground = GetWorld()local mx, my, mz = TheInput:GetWorldPosition():Get()local tx, ty = ground.Map:GetTileCoordsAtPoint(mx,my,mz)s = s..string.format("world[%f,%f,%f] tile[%d,%d] ", mx,my,mz, tx,ty) local tile = ground.Map:GetTileAtPoint(TheInput:GetWorldPosition():Get())for k,v in pairs(GROUND) doif v == tile thens = s..string.format("ground[%s] ", k)breakendend print(s)end____________________________________________________________________________-- Apply a scenario script to the selection and run it.function c_doscenario(scenario)local inst = GetDebugEntity()if not inst thenprint("Need to select an entity to apply the scenario to.")returnendif inst.components.scenariorunner theninst.components.scenariorunner:ClearScenario()end -- force reload the script -- this is for testing after all!package.loaded["scenarios/"..scenario] = nil inst:AddComponent("scenariorunner")inst.components.scenariorunner:SetScript(scenario)inst.components.scenariorunner:Run()SuUsed("c_doscenario_"..scenario, true)end____________________________________________________________________________-- Some helper shortcut functionsfunction c_season() return GetWorld().components.seasonmanager endfunction c_sel_health()if c_sel() thenlocal health = c_sel().components.healthif health thenreturn healthelseprint("Gah! Selection doesn't have a health component!")returnendelseprint("Gah! Need to select something to access it's components!")endend____________________________________________________________________________function c_setminhealth(n)SuUsed("c_minhealth", true)GetPlayer().components.health:SetMinHealth(n)end____________________________________________________________________________function c_pos(inst)return inst and Point(inst.Transform:GetWorldPosition())end function c_printpos(inst)print(c_pos(inst))end____________________________________________________________________________function c_move(inst)inst = inst or c_sel()inst.Transform:SetPosition(TheInput:GetWorldPosition():Get())SuUsed("c_move", true)end____________________________________________________________________________function c_goto(dest, inst)inst = inst or GetPlayer()if dest theninst.Transform:SetPosition(dest.Transform:GetWorldPosition())endSuUsed("c_goto", true)end____________________________________________________________________________function c_inst(guid)return Ents[guid]end____________________________________________________________________________function c_list(prefab)local x,y,z = GetPlayer().Transform:GetWorldPosition()local ents = TheSim:FindEntities(x,y,z, 9001)for k,v in pairs(ents) doif v.prefab == prefab thenprint(string.format("%s {%2.2f, %2.2f, %2.2f}", tostring(v), v.Transform:GetWorldPosition()))endendendПо-моему, показывает координаты объекта.____________________________________________________________________________function c_listtag(tag)local tags = {tag}local x,y,z = GetPlayer().Transform:GetWorldPosition()local ents = TheSim:FindEntities(x,y,z, 9001, tags)for k,v in pairs(ents) doprint(string.format("%s {%2.2f, %2.2f, %2.2f}", tostring(v), v.Transform:GetWorldPosition()))endend____________________________________________________________________________local lastfound = -1function c_findnext(prefab, radius, inst)inst = inst or GetPlayer()radius = radius or 9001 local trans = inst.Transformlocal found = nillocal foundlowestid = nillocal reallowest = nillocal reallowestid = nil print("Finding a ",prefab) local x,y,z = trans:GetWorldPosition()local ents = TheSim:FindEntities(x,y,z, radius)for k,v in pairs(ents) doif v ~= inst and v.prefab == prefab thenprint(v.GUID,lastfound,foundlowestid )if v.GUID > lastfound and (foundlowestid == nil or v.GUID < foundlowestid) thenfound = vfoundlowestid = v.GUIDendif not reallowestid or v.GUID < reallowestid thenreallowest = vreallowestid = v.GUIDendendendif not found thenfound = reallowestendif found thenlastfound = found.GUIDendreturn foundend____________________________________________________________________________function c_find(prefab, radius, inst)inst = inst or GetPlayer()radius = radius or 9001 local trans = inst.Transformlocal found = nillocal founddistsq = nil local x,y,z = trans:GetWorldPosition()local ents = TheSim:FindEntities(x,y,z, radius)for k,v in pairs(ents) doif v ~= inst and v.prefab == prefab thenif not founddistsq or inst:GetDistanceSqToInst(v) < founddistsq thenfound = vfounddistsq = inst:GetDistanceSqToInst(v)endendendreturn foundend____________________________________________________________________________function c_findtag(tag, radius, inst)return GetClosestInstWithTag(tag, inst or GetPlayer(), radius or 1000)end____________________________________________________________________________function c_gonext(name)c_goto(c_findnext(name))endПереносит игрока к объекту, вроде.

____________________________________________________________________________

function c_printtextureinfo( filename )

TheSim:PrintTextureInfo( filename )

end

____________________________________________________________________________

function c_simphase(phase)

GetWorld():PushEvent("phasechange", {newphase = phase})

end

____________________________________________________________________________

function c_anim(animname, loop)

if GetDebugEntity() then

GetDebugEntity().AnimState:PlayAnimation(animname, loop or false)

else

print("No DebugEntity selected")

end

end

____________________________________________________________________________

function c_light(c1, c2, c3)

TheSim:SetAmbientColour(c1, c2 or c1, c3 or c1)

end

____________________________________________________________________________

function c_spawn_ds(prefab, scenario)

local inst = c_spawn(prefab)

if not inst then

print("Need to select an entity to apply the scenario to.")

return

end

if inst.components.scenariorunner then

inst.components.scenariorunner:ClearScenario()

end

-- force reload the script -- this is for testing after all!

package.loaded["scenarios/"..scenario] = nil

inst:AddComponent("scenariorunner")

inst.components.scenariorunner:SetScript(scenario)

inst.components.scenariorunner:Run()

end

____________________________________________________________________________

function c_countprefabs(prefab, noprint)

local count = 0

for k,v in pairs(Ents) do

if v.prefab == prefab then

count = count + 1

end

end

if not noprint then

print("There are ", count, prefab.."s in the world.")

end

return count

end

____________________________________________________________________________

function c_countallprefabs()

local counted = {}

for k,v in pairs(Ents) do

if v.prefab and not table.findfield(counted, v.prefab) then

local num = c_countprefabs(v.prefab, true)

counted[v.prefab] = num

end

end

local function pairsByKeys (t, f)

local a = {}

for n in pairs(t) do table.insert(a, n) end

table.sort(a, f)

local i = 0      -- iterator variable

local iter = function ()   -- iterator function

i = i + 1

if a[i] == nil then return nil

else return a[i], t[a[i]]

end

end

return iter

end

for k,v in pairsByKeys(counted) do

print(k, v)

end

print("There are ", GetTableSize(counted), " different prefabs in the world.")

end

____________________________________________________________________________

function c_forcecrash(unique)

local path = "a"

if unique then

    path = string.random(10, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV")

end

if GetWorld() then

    GetWorld():DoTaskInTime(0,function() _G[path].b = 0 end)

elseif TheFrontEnd then

    TheFrontEnd.screenroot.inst:DoTaskInTime(0,function() _G[path].b = 0 end)

end

end

____________________________________________________________________________

function c_teststate(state)

c_sel().sg:GoToState(state)

end

____________________________________________________________________________

function c_poison()-накладывает отравление (разобрался, не знаю, куда вставить в статью)

____________________________________________________________________________ function c_warp(dest)'c_gonext(dest) end____________________________________________________________________________function c_holdingdevtool()local item = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)if item and item.prefab == "devtool" thenreturn trueend return falseend____________________________________________________________________________c_wetseason(skipPlayer)'c_greenseason(skipPlayer)' c_dryseason(skipPlayer)'c_nextseason(skipPlayer)'Вроде сезоны в св меняют.'____________________________________________________________________________function c_erupt()local vm = GetWorld().components.volcanomanagerif vm thenvm:StartEruption(60.0, 60.0, 60.0, 1 / 8)endend function c_nexterupt()local sm = GetSeasonManager()local vm = GetWorld().components.volcanomanager if not sm:IsDrySeason() thenc_dryseason()end if vm thenlocal segs = vm:GetNumSegmentsUntilEruption() or 0if segs > 0 thenprint("Skipping", segs)LongUpdate(TUNING.SEG_TIME * segs, true)endendend____________________________________________________________________________function c_prefabexists(prefab)if not PrefabExists(prefab) thenprint(prefab, "doest not exist!")return falseendreturn trueend____________________________________________________________________________

function c_treasuretest()

local l = GetTreasureLootDefinitionTable()

for name, data in pairs(l) do

if type(data) == "table" then

if type(data.loot) == "table" then

for k, _ in pairs(data.loot) do

c_prefabexists(k)

end

end

if type(data.random_loot) == "table" then

for k, _ in pairs(data.random_loot) do

c_prefabexists(k)

end

end

if type(data.chance_loot) == "table" then

for k, _ in pairs(data.chance_loot) do

c_prefabexists(k)

end

end

end

end

local t = GetTreasureDefinitionTable()

local obj_layout = require("map/object_layout")

for name, data in pairs(t) do

if type(data) == "table" then

for i, stage in ipairs(data) do

if type(stage) == "table" then

if stage.treasure_set_piece then

obj_layout.LayoutForDefinition(stage.treasure_set_piece)

end

if stage.treasure_prefab then

c_prefabexists(stage.treasure_prefab)

end

if stage.map_set_piece then

obj_layout.LayoutForDefinition(stage.map_set_piece)

end

if stage.map_prefab then

c_prefabexists(stage.map_prefab)

end

if stage.tier == nil then

if stage.loot == nil then

print("missing loot!", name)

elseif l[stage.loot] == nil then

print("missing loot!", name, stage.loot)

end

end

end

end

end

end

end

____________________________________________________________________________

function c_sounddebug()

if not package.loaded["debugsounds"] then

require "debugsounds"

end

SOUNDDEBUG_ENABLED = true

TheSim:SetDebugRenderEnabled(true)

end

____________________________________________________________________________

function c_mapstats()

local map = GetWorld().Map

local ground = {}

for k,v in pairs(GROUND) do

ground[v] = 0

end

local width, height = map:GetSize()

for y = 0, height, 1 do

for x = 0, width, 1 do

local g = map:GetTile(x, y)

if ground[g] then

ground[g] = ground[g] + 1

end

end

end

local totaltiles = width * height

local totalwater = 0

local totalland = 0

for k,v in pairs(ground) do

if map:IsWater(k) then

totalwater = totalwater + ground[k]

else

totalland = totalland + ground[k]

end

end

print("Map Stats")

print(string.format("  Shallow    \t%d\t(%4.4f%%)", ground[GROUND.OCEAN_SHALLOW], ground[GROUND.OCEAN_SHALLOW] / totaltiles * 100))

print(string.format("  Shore      \t%d\t(%4.4f%%)", ground[GROUND.OCEAN_SHORE], ground[GROUND.OCEAN_SHORE] / totaltiles * 100))

print(string.format("  Medium     \t%d\t(%4.4f%%)", ground[GROUND.OCEAN_MEDIUM], ground[GROUND.OCEAN_MEDIUM] / totaltiles * 100))

print(string.format("  Deep       \t%d\t(%4.4f%%)", ground[GROUND.OCEAN_DEEP], ground[GROUND.OCEAN_DEEP] / totaltiles * 100))

print(string.format("  Coral      \t%d\t(%4.4f%%)", ground[GROUND.OCEAN_CORAL], ground[GROUND.OCEAN_CORAL] / totaltiles * 100))

print(string.format("  Coral Shore\t%d\t(%4.4f%%)", ground[GROUND.OCEAN_CORAL_SHORE], ground[GROUND.OCEAN_CORAL_SHORE] / totaltiles * 100))

print(string.format("  Mangrove   \t%d\t(%4.4f%%)", ground[GROUND.MANGROVE], ground[GROUND.MANGROVE] / totaltiles * 100))

print(string.format("  Mangrove Sh\t%d\t(%4.4f%%)", ground[GROUND.MANGROVE_SHORE], ground[GROUND.MANGROVE_SHORE] / totaltiles * 100))

print(string.format("  Impassible \t%d\t(%4.4f%%)", ground[GROUND.IMPASSABLE], ground[GROUND.IMPASSABLE] / totaltiles * 100))

print(string.format("  Total water\t%d\t(%4.4f%%)", totalwater, totalwater / totaltiles * 100))

print(string.format("  Total land \t%d\t(%4.4f%%)", totalland, totalland / totaltiles * 100))

print(string.format("  Total tiles\t%d", totaltiles))

end

____________________________________________________________________________

function c_regenwater(data)

print("Water regen...")

local map = GetWorld().Map

local width, height = map:GetSize()

--clear water

for y = 0, height, 1 do

for x = 0, width, 1 do

local tile = map:GetTile(x, y)

if tile == GROUND.MANGROVE_SHORE then

map:SetTile(x, y, GROUND.MANGROVE)

elseif map:IsWater(tile) and tile ~= GROUND.MANGROVE then

map:SetTile(x, y, GROUND.IMPASSABLE)

end

end

end

WorldSim:SetTileMap(map:GetTileMap()) --so so hacky

require("map/water")

if type(data) == "table" then

ConvertImpassibleToWater(width, height, data)

elseif type(data) == "string" then

ConvertImpassibleToWater(width, height, require(data))

package.loaded[data] = nil

else

ConvertImpassibleToWater(width, height, require("map/watergen"))

package.loaded["map/watergen"] = nil

end

AddShoreline(width, height)

print("Rebuild...")

local tiles =

{

GROUND.OCEAN_SHALLOW, GROUND.OCEAN_MEDIUM, GROUND.OCEAN_DEEP, GROUND.OCEAN_CORAL, GROUND.MANGROVE,

GROUND.OCEAN_SHIPGRAVEYARD, GROUND.JUNGLE, GROUND.BEACH, GROUND.MAGMAFIELD, GROUND.TIDALMARSH,

GROUND.MEADOW, GROUND.IMPASSABLE

}

map:Finalize(1, COLLISION_TYPE.WATER)

local minimap = TheSim:FindFirstEntityWithTag("minimap")

if minimap then

for i = 1, #tiles, 1 do

minimap.MiniMap:RebuildLayer( tiles[i], 2, 2 )

end

end

c_mapstats()

WorldSim:SetTileMap(nil)

print("Water regen done.")

end

____________________________________________________________________________

function c_selectnear(prefab, rad)

local player = GetPlayer()

local x,y,z = player.Transform:GetWorldPosition()

local ents = TheSim:FindEntities(x,y,z, rad or 30)

local closest = nil

local closeness = nil

for k,v in pairs(ents) do

    if v.prefab == prefab then

        if closest == nil or player:GetDistanceSqToInst(v) < closeness then

            closest = v

            closeness = player:GetDistanceSqToInst(v)

        end

    end

end

if closest then

    c_select(closest)

end

end

____________________________________________________________________________

function c_skipdays(num)

LongUpdate(TUNING.TOTAL_DAY_TIME * num, true)

end

____________________________________________________________________________

function c_setlightningflashenabled(enabled)

GetWorld().components.clock:SetLightningFlashEnabled(enabled)

end 

Материалы сообщества доступны в соответствии с условиями лицензии CC-BY-SA , если не указано иное.