Jump to content

[SOLVED] Custom Usable Items


Recommended Posts

14 hours ago, Serpens said:

Cant tell you why, I think the code looks okay, but I mmight overlook sth. It should work when a ghost is haunting it.
If not, and you are not able to  find out why, I would have to test your current mod version.

I'm not sure what the problem is but I'll attach my updated mod file here. 

 

Edited by suteneko
Link to comment
Share on other sites

16 minutes ago, suteneko said:

I'm not sure what the problem is but I'll attach my updated mod file here.

The "MakeHauntableLaunch" at the end of the MakeArcana function is reverting the instant rez, so simply remove that line (or add if else statements to not call it for the crown)
And I had a crash telling me that arcana.tex does not exist, in case you care.

Edited by Serpens
Link to comment
Share on other sites

14 hours ago, Serpens said:

The "MakeHauntableLaunch" at the end of the MakeArcana function is reverting the instant rez, so simply remove that line (or add if else statements to not call it for the crown)
And I had a crash telling me that arcana.tex does not exist, in case you care.

Oh, thanks. I had added card images to replace the book images for inventory/dropped and I forgot to get rid of the filler image's code ¯\_(ツ)_/¯

I added the "else" statement so now all the cards except "Lady of Crowns" bounce when haunted. "Lady of Crowns" erodes but does not resurrect when haunted.

 

Edited by suteneko
Link to comment
Share on other sites

I forgot that the onhaunt function has to return true:

            inst.components.hauntable:SetOnHauntFn(function(inst,haunter)
			-- when haunted
                ErodeAway(inst)
                return true
				-- remove arcana_crown with a small effect
            end)

(one can find out about this, by looking at the hauntable.lua code and searching for REZ, then you see the ressurect code is only called, if the result of onhaunt is true.)

Edited by Serpens
Link to comment
Share on other sites

9 hours ago, Serpens said:

I forgot that the onhaunt function has to return true:


            inst.components.hauntable:SetOnHauntFn(function(inst,haunter)
			-- when haunted
                ErodeAway(inst)
                return true
				-- remove arcana_crown with a small effect
            end)

(one can find out about this, by looking at the hauntable.lua code and searching for REZ, then you see the ressurect code is only called, if the result of onhaunt is true.)

I looked at the hauntable.lua code and saw a bunch of stuff in there. Found semi-matching code and figured it looked fine already (I know pretty much squat about coding).

Everything works perfectly now! Thank you so much.

Is there a way to add the health penalty on revive, though? I looked around the forum and nothing I saw touched upon the subject (except one about reviving by possessing a deer but that topic was never finished/solved). I'm am fairly sure I can't just copy and past inst.components.health:DeltaPenalty(TUNING.REVIVE_HEALTH_PENALTY) from player_common.lua (found it in a file search).

I tried pulling code from hauntable.lua but I got an error.

if def.name=="arcana_crown" then
	inst:AddComponent("hauntable")
	inst.components.hauntable:SetHauntValue(TUNING.HAUNT_INSTANT_REZ) 

	if doer:HasTag("playerghost") then
		doer:PushEvent("respawnfromghost", { source = self.inst })
	end
  
	inst.components.hauntable:SetOnHauntFn(function(inst,haunter)
		ErodeAway(inst)
		return true
	end)
end)

Assuming I would've had to put the whole block of code in :confused: But you were able to put in a simple line of code instead of a text block and I was hoping it'd work the same haha

Edited by suteneko
Link to comment
Share on other sites

you see in hauntable.lua, that this

doer:PushEvent("respawnfromghost", { source = self.inst })

is called if the hauntvalue is TUNING.HAUNT_INSTANT_REZ, so this is already done by the hauntable component and no need to copy it into your mod.
In addition these 2 problems (for general information):
1) "doer" is nowhere defined. "doer" is simply a variable. the name "doer" was just chosen by the devs, usually it is the acting player. So in case this code would fit into your code (which it does not), you would have to use your variable name for the player, so eg "haunter", but this is only defined within the OnhHauntFn.
2) You (did) put it outside of anything that is related to hauntable, so code in common_fn (in your prefab) is called at every game start. And I gfuess you dont want to ressurect anyone at every game start. So the code would work with haunter within the OnHauntFn.  But as I wrote above, hauntable already does push this event (which does the ressurection) so there is no need to add it.

Your were on the right track, this line is exactly what you need:

inst.components.health:DeltaPenalty(TUNING.REVIVE_HEALTH_PENALTY)

But we also need a location where to put this line. We want to do it after resurrection. We can use events for this.
As you already found out, the hauntable is doing

doer:PushEvent("respawnfromghost", { source = self.inst })

So we can listen for this event, to find out when a player is ressurected. And the "source" will tell us by what he was ressurected.

But it gets a bit complicated now. The way to go would be to use AddPlayerPostInit in modmain and listen for ressurection of every player, and if they ressurect with help of your item, they will get the penalty. It does not look straight forward, it would be better if we could simply add this effect to your cards...
I can only imagine of replacing the code from hauntable.lua, so NOT using TUNING.HAUNT_INSTANT_REZ (remove that line) and instead do what you maybe tried to do above, but putting it in the right location:

    inst.components.hauntable:SetOnHauntFn(function(inst,haunter)
        if haunter:HasTag("playerghost") then
            haunter:PushEvent("respawnfromghost", { source = inst })
            haunter.components.health:DeltaPenalty(TUNING.REVIVE_HEALTH_PENALTY)
            ErodeAway(inst)
		    return true
        end		
	end)

 

Edited by Serpens
Link to comment
Share on other sites

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
 Share

×
  • Create New...