Jump to content

Recommended Posts

11 hours ago, _zwb said:

You didn't call the function sanity_heal...

Uhm, but I call function(inst), that is sanity_heal, aren't it?

edit: ig I understand but it's doesn't work anyway
image.png.2d88f0a6e168d2f611726c36a6639829.png
image.png.87c76fe4cec2c4b90cfd66a9a49679bf.png

Edited by Mint Candy
17 hours ago, _zwb said:

It's "inst:DoPeriodicTask(...)" with a colon after "inst", in lua that's equivalent to "inst.DoPeriodicTask(inst, ...)", you need inst as the first parameter.

I don't really understand why it's work like this, I'm using guide for auras as example, and there no info about what are you saying.

local myFunction = function(inst)
	-- Do something
end

inst:DoPeriodicTask(1.0, myFunction)

Why in DPT should be inst?.. In the whole guide no info about it...(

Just now, Mint Candy said:

I don't really understand why it's work like this, I'm using guide for auras as example, and there no info about what are you saying.

local myFunction = function(inst)
	-- Do something
end

inst:DoPeriodicTask(1.0, myFunction)

Why in DPT should be inst?.. In the whole guide no info about it...(

Mostly I'm using this part, it's closer to thing that I trying to do.
 

local mustHaveTags = { "player" }
local cantHaveTags = { "playerghost", "INLIMBO" }
local mustHaveOneOfTheseTags = nil

inst:DoPeriodicTask(1.0, function(inst)
	-- Do nothing if the entity has a health component and is dead, or it is a playerghost.
	if inst.components.health and inst.components.health:IsDead() or inst:HasTag("playerghost") then
		return
	end
	
	local x,y,z = inst.Transform:GetWorldPosition()
	
	local players = TheSim:FindEntities(x, y, z, 10, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)
	
	-- Run through all the players within range...
	for _,v in ipairs(players) do
		-- ...and if they have a health component, add 1 to their health.
		if v.components.health then
			v.components.health:DoDelta(1)
		end
	end
end)
2 hours ago, Mint Candy said:

I don't really understand why it's work like this, I'm using guide for auras as example, and there no info about what are you saying.

local myFunction = function(inst)
	-- Do something
end

inst:DoPeriodicTask(1.0, myFunction)

Why in DPT should be inst?.. In the whole guide no info about it...(

Mostly I'm using this part, it's closer to thing that I trying to do.
 

local mustHaveTags = { "player" }
local cantHaveTags = { "playerghost", "INLIMBO" }
local mustHaveOneOfTheseTags = nil

inst:DoPeriodicTask(1.0, function(inst)
	-- Do nothing if the entity has a health component and is dead, or it is a playerghost.
	if inst.components.health and inst.components.health:IsDead() or inst:HasTag("playerghost") then
		return
	end
	
	local x,y,z = inst.Transform:GetWorldPosition()
	
	local players = TheSim:FindEntities(x, y, z, 10, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)
	
	-- Run through all the players within range...
	for _,v in ipairs(players) do
		-- ...and if they have a health component, add 1 to their health.
		if v.components.health then
			v.components.health:DoDelta(1)
		end
	end
end)

P.S. It START to work somehow, but now I have troubles to stop sanity heal after while...

10 hours ago, Mint Candy said:

I don't really understand why it's work like this,

In lua there are no classes, so it is usually implemented using tables. Such as:

MyClass = {}

function MyClass:MyMethod() end

Here, calling MyClass:MyMethod() is the same as MyClass.MyMethod(MyClass)

If you still don't understand, you should go learn the basics of Object Orientated Programming(OOP) and OOP in lua.

Edited by _zwb
  • Like 1
8 hours ago, _zwb said:

In lua there are no classes, so it is usually implemented using tables. Such as:

MyClass = {}

function MyClass:MyMethod() end

Here, calling MyClass:MyMethod() is the same as MyClass.MyMethod(MyClass)

If you still don't understand, you should go learn the basics of Object Orientated Programming(OOP) and OOP in lua.

Oh, I see. Okay. For now, my code looking like this.
image.png.84fb75f65da259af95ec6cf47b7a8fb7.png
It's working, but sanity healing works without stop. It's not canceling for some reason, and I don't understand why...

1 hour ago, _zwb said:

because you cancelled the task you use to cancel sanity_heal_end task, you didn't cancel the healing task

Hmm, I thought they equal (in those guide it's working like this...). I will test it, thanks.

7 hours ago, _zwb said:

because you cancelled the task you use to cancel sanity_heal_end task, you didn't cancel the healing task

image.png.cb05d47b1893d2d82bc054cfad545223.png

image.png.cb0e6dc67be114e352b68e530d4bf00b.png

Well I'm really don't know what to do, it's just don't work))

I need it to heal sanity for /time/, and after it stop until I reuse this item. Maybe I'm doing everything wrong and should use DoTaskInTime?..

Edited by Mint Candy

I think you could probably make this into a buff instead of having to do this all by yourself.
Buffs have on attach, detach, and extend, so it's probably more flexible to work on those and make the instrument apply the buff to you and others around you.

On 6/24/2024 at 11:32 AM, Baguettes said:

I think you could probably make this into a buff instead of having to do this all by yourself.
Buffs have on attach, detach, and extend, so it's probably more flexible to work on those and make the instrument apply the buff to you and others around you.

Hmm
Okie-dokie, I'll try, but maybe you have some examples? 

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