Jump to content

Recommended Posts

Hi ! Today i'm making a mod witch add a reward in the shipwrecked slot machine as a "good reward".

The reward is :

- 2 messagebottles

- 1 goldenshovel

 

I've added the reward and all work but when a try to read a messagebottle the character said me the message is unreadable.

I've try to add a function for messagebottle post init but this is not working.

AddPrefabPostInit("messagebottle", function(inst)
	if inst.treasure == nil then
		inst.treasure = require "prefabs/buriedtreasure"
	end
end)

this code allow me to read the messagebottle but the game crash after that with the screen : 

Spoiler

scripts/prefabs/messagebottle.lua(25,1) Read Message Bottle	Prefab buriedtreasure - 	nil	
...n/dont_starve/data/scripts/prefabs/messagebottle.lua:12: attempt to call method 'Reveal' (a nil value)
LUA ERROR stack traceback:
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/messagebottle.lua:12 in (upvalue) revealTreasure (Lua) <10-15>
   inst = 113745 - messagebottle(LIMBO) (valid:true)
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/messagebottle.lua:37 in () ? (Lua) <23-58>
   inst = 113745 - messagebottle(LIMBO) (valid:true)
   reader = 100021 - wx78 (valid:true)
   message = nil
=(tail call):-1 in ()  (tail) <-1--1>
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/reader.lua:7 in () ? (Lua) <5-14>
   self =
      inst = 100021 - wx78 (valid:true)
   book = 113745 - messagebottle(LIMBO) (valid:true)
=(tail call):-1 in ()  (tail) <-1--1>
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/bufferedaction.lua:20 in (method) Do (Lua) <17-33>
   self (valid:true) =
      options = table: 0CA22020
      action = table: 138D2620
      doer = 100021 - wx78 (valid:true)
      onsuccess = table: 0CA22070
      onfail = table: 0CA22048
      invobject = 113745 - messagebottle(LIMBO) (valid:true)
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/entityscript.lua:1073 in (method) PerformBufferedAction (Lua) <1063-1086>
   self (valid:true) =
      DynamicShadow = DynamicShadow (2A02AD18)
      inlimbo = false
      brain = --brain--
sleep time: 0.00
Priority - READY <FAILED> ()>0.00
   >Parallel - READY <FAILED> ()>0.00
   >   >Hold LMB - READY <FAILED> ()>0.00
   >   >ChaseAndAttack - READY <READY> ()>0.00
   >ChaseAndAttack - READY <FAILED> ()>0.00

      OnLongUpdate = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/wx78.lua:214
      AnimState = AnimState (2A02AD00)
      Light = Light (2A02D700)
      age = 0
      LightWatcher = LightWatcher (2A02AF40)
      profile = table: 131B5DB0
      inherentactions = table: 27D085A8
      spawntime = 0
      CanExamine = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:527
      HUD = HUD
      Transform = Transform (2A02ACE8)
      event_listening = table: 365709C0
      bufferedaction = Read nil With Inv:113745 - messagebottle(LIMBO) (valid:true)
      children = table: 27D116D0
      name = Wx78
      OnPreLoad = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/wx78.lua:85
      entity = Entity (2A02ACB8)
      GUID = 100021
      prefab = wx78
      updatecomponents = table: 36571640
      OnLoad = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/wx78.lua:102
      Soak = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:529
      spark_time = 3
      Physics = Physics (2A02AD60)
      persists = false
      MiniMapEntity = MiniMapEntity (2A02AD48)
      SoundEmitter = SoundEmitter (2A02AD30)
      level = 20
      OnSave = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/wx78.lua:115
      brainfn = table: 27D083A0
      sg = sg="wilson", state="map", time=2.00, tags = "doing,"
      event_listeners = table: 365708F8
      charge_time = 0
      AddLevelComponents = function - @C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:79
      components = table: 3656D2C0
      pendingtasks = table: 21835E80
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraphs/SGwilson.lua:2339 in () ? (Lua) <2338-2340>
   inst = 100021 - wx78 (valid:true)
=(tail call):-1 in ()  (tail) <-1--1>
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua:371 in (method) HandleEvents (Lua) <366-381>
   self =
      tags = table: 48BE5588
      mem = table: 27D08670
      statemem = table: 48BF02A8
      currentstate = table: 12E89948
      timeinstate = 1.9333334341645
      sg = St
scripts/mainfunctions.lua(849,1) ...n/dont_starve/data/scripts/prefabs/messagebottle.lua:12: attempt to call method 'Reveal' (a nil value)
LUA ERROR stack traceback:
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/messagebottle.lua:12 in (upvalue) revealTreasure (Lua) <10-15>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/prefabs/messagebottle.lua:37 in () ? (Lua) <23-58>
    =(tail call):-1 in ()  (tail) <-1--1>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/reader.lua:7 in () ? (Lua) <5-14>
    =(tail call):-1 in ()  (tail) <-1--1>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/bufferedaction.lua:20 in (method) Do (Lua) <17-33>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/entityscript.lua:1073 in (method) PerformBufferedAction (Lua) <1063-1086>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraphs/SGwilson.lua:2339 in () ? (Lua) <2338-2340>
    =(tail call):-1 in ()  (tail) <-1--1>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua:371 in (method) HandleEvents (Lua) <366-381>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/stategraph.lua:144 in (method) Update (Lua) <108-147>
    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/update.lua:126 in () ? (Lua) <73-139>
	
scripts/frontend.lua(723,1) SCRIPT ERROR! Showing error screen	
HttpClientWriteCallback (0x008C21F5, 1, 22, 0x0689FDCC)
HttpClientWriteCallback READ 22 (22 total)
QueryServerComplete no callback

 

I think i'm doing something wrong for generate the treasure of these bottles.

 

I need your help to finish this mod

Edited by AireAyquaza

The file you are referencing with 'require' returns the prefab definition of buried treasure, not an initializer for it.

 

Buried treasure is created at worldgen, so you will need to generate new treasure. Once it is created, set the bottle's 'inst.treasure' field to the treasure's instance.

 

The simplest way to generate new chests would probably be this: (Untested code)

local valid_ground_types = {
	GROUND.MEADOW,
	GROUND.BEACH,
	GROUND.JUNGLE
}

local function CanPlaceChestOnGround(type)
	for _,v in ipairs(valid_ground_types) do
		if type == v then
			return true
		end
	end
	return false
end

local function GenerateChest(tries)
	local x,y,z = 0,0,0
	for i=1,(10 or tries) do
		x = math.random(-5000,5000)
		z = math.random(-5000,5000)
		if CanPlaceChestOnGround(GetWorld().Map:GetTileAtPoint(x,y,z)) then
			local chest = SpawnPrefab("buriedtreasure")
			chest.Transform:SetPosition(x,y,z)
			return chest
		end
	end
	print("Failed to place chest in "..(10 or tries).." tries.")
end

 

Edited by Arkathorn

Thanks for reply, this look nice but the game crash with this error:

Spoiler

scripts/mods.lua(253,1) Disabling slot-machine (Slot machine message bottle) because it had an error.	
scripts/mods.lua(44,1) error calling PrefabPostInit: messagebottle in mod slot-machine (Slot machine message bottle): 
...on/dont_starve/data/../mods/slot-machine/modmain.lua:37: attempt to call global 'GetWorld' (a nil value)
LUA ERROR stack traceback:
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/slot-machine/modmain.lua(37,1) in function 'GenerateChest'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/slot-machine/modmain.lua(47,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(42,1) in function 'mod'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(136,1)
        =[C] in function 'SpawnPrefab'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(163,1) in function 'SpawnPrefab'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(170,1) in function 'SpawnSaveRecord'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(680,1) in function 'PopulateWorld'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(933,1) in function 'DoInitGame'
	...
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(111,1) in function 'Load'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1306,1) in function 'callback'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(602,1) in function 'Set'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(486,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(484,1) in function 'Load'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1305,1) in main chunk
        =[C] in function 'require'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(654,1)	
scripts/mods.lua(253,1) Disabling slot-machine (Slot machine message bottle) because it had an error.	

 

 

The error said GetWorld() in GenerateChest is nil, I've tried these solutions :

- Generate new world, save and quit, enable the mod and reload -> same error

- Generate new world with the mod enable -> same error

- Add priority = 2^16 into modinfo.lua -> same error

 

What is wrong ? GetWorld() shouldn't be nil. Maybe it's because the GenerateChest is called in a AddPrefabPostInit ?

 

There is my code (I've modified a bit your code)

Spoiler

local require = GLOBAL.require
require "map/treasurehunt"

local addedSlotMachineReward = {
	["slot_treasurebottle"] = 
	{
		loot = 
		{
			messagebottle = 2,
			goldenshovel = 1,
		},
	},
}

for name, data in pairs(addedSlotMachineReward) do
	AddTreasureLoot(name, data)
end

PrefabFiles = {
	"slotmachine"
}

local function CanPlaceChestOnGround(tile)
	if not GetWorld().Map:IsWater(tile) then
		return true
	end
	return false
end

local function GenerateChest()
	local x,y,z = 0,0,0
	local chest = nil
	while chest == nil do
		x = math.random(-5000,5000)
		z = math.random(-5000,5000)
		if CanPlaceChestOnGround(GetWorld().Map:GetTileAtPoint(x,y,z)) then
			chest = SpawnPrefab("buriedtreasure")
			chest.Transform:SetPosition(x,y,z)
			return chest
		end
	end
end

AddPrefabPostInit("messagebottle", function(inst)
	if inst.treasure == nil then
		inst.treasure = GenerateChest()
	end
end)

 

 

Thanks you ! It's works ! Now the problem is when I dug the x spot, I get bone shard but no chest. I think I need to generate the chest manually.

 

EDIT: Treasure generation done ! Thanks for contributing !

Edited by AireAyquaza

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...