Jump to content

Recommended Posts

Hello, I have a problem which I don't know how to fix if someone can help me that'd really be great :D!

So here is my code

Spoiler

local function Find(inst)
	if inst.components.health:IsDead() or inst.jump == true or inst.swimming == true then return end
	
	local bump = math.random(1,2)
	local fx = SpawnPrefab("maxwell_smoke")
	local x, y, z = inst.Transform:GetWorldPosition()

	if bump == 1 then
		fx.Transform:SetPosition(x, y, z)
		fx.Transform:SetScale(.35,.40,.45)
		inst.SoundEmitter:PlaySound("dontstarve/common/stone_drop")
		ShakeAllCameras(CAMERASHAKE.VERTICAL,.5, .01, .05, inst, .01)
		inst.components.talker:Say(GetString(inst, "ANNOUNCE_FOUND"))
		SpawnPrefab("dirtpile").Transform:SetPosition(inst.Transform:GetWorldPosition())
	end
end

--inside master_postinit
inst:DoPeriodicTask(3, Find)

 

so my character has chance to find a dirtpile everyday which he can get loot from the problem is when my character is not supposed to find a dirtpile, the maxwell smoke will spawn somewhere in a random point of a world always. In each new world it's a different area, but all stuff I spawn with "local x, y, z = inst.Transform:GetWorldPosition()" & "local fx = SpawnPrefab("maxwell_smoke")"  that happens. I also have this problem I try to spawn a item for my character to wear when I press a key.

local ic = act.target.components
local wathgrithrhat = SpawnPrefab("wathgrithrhat")
ic.inventory:Equip(wathgrithrhat)

I don't know how to fix this or what is wrong, so I would really appreciate any sort of help someone can provide, thank you very much :D!!

 

Thanks for looking into my problem, have a great day/night :D!!

Edited by SuperDavid
being stupid sux

please better describe what you want and what is happening.

By looking at your code you check bump==1 after spawning the smoke. So of course everytime the function is called, the smoke will spawn, but only with your random chance, also the dirtpile will spawn. That is what you wrote. What should happen instead?

edit:
And I suggest to use my function for spawning something near someone/something:

but first try to understand what the function does. It is not that hard and meanwhile you should be able to understand it ;)

Edited by Serpens

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...