Jump to content

[SOLVED] Useable nonequippable item with infinite uses


Recommended Posts

Hello people. As the tittle says, i need to do an ítem that is useable (nonequippable) with infinite uses.

So far i've tried a few ones, but no luck.

	inst:AddComponent("useableitem")
	inst.components.useableitem:SetOnUseFn(magic)

After using this code, i went to the game but i could only examine the item, but not use it.

i want this items to be useable (with infinite uses) so that i can do magical items for my mod.

Any ideas about how to accomplish this?

This is so that i can finish phase 2 of my currently underdevelopment mod:

Thanks a lot in advance guys, i'd acomplished a lot thanks to your help, and the mod will be great and fun so we can all give it a try.

 

EDIT:

Solved by @DarkXero. Check out the comments if you want to learn how.

Edited by Jpianist
Link to comment
Share on other sites

14 minutes ago, DarkXero said:

The usableitem component is obsolete. Useless.

I attach a example with two spellbooks.

spellbooks.zip

Why? I mean, is still possible right? It would be very helpful since i'm thinking on creating at least 4 magics and it would be easier to press the number of the inventory slot where they are to use them rather than equipping them and then use them, switching to the next and so on.

Also this is great for control support since it's easier to use ítems in the inventory than equipping them, then moving the cursor to the handslot and usethem, rollback and repeat with a different magic. I myselft love playing DST with my controller, and equipping differents magic would be painfully exhausting. I'm gonna try right now the code you just gave me. Thanks!!

Link to comment
Share on other sites

9 minutes ago, Jpianist said:

Why? I mean, is still possible right? It would be very helpful since i'm thinking on creating at least 4 magics and it would be easier to press the number of the inventory slot where they are to use them rather than equipping them and then use them, switching to the next and so on.

There is not a single item in DST that makes use of the usableitem component.

As such, it is missing important networking code.

It is literally useless, it doesn't work.

Which is why made a new component in the example, and gave it the proper networking with the AddComponentAction.

That way you can right click stuff in your inventory to make an action on it.

Link to comment
Share on other sites

17 minutes ago, DarkXero said:

There is not a single item in DST that makes use of the usableitem component.

As such, it is missing important networking code.

It is literally useless, it doesn't work.

Which is why made a new component in the example, and gave it the proper networking with the AddComponentAction.

That way you can right click stuff in your inventory to make an action on it.

Just tried your example, is pure genious, you're a genious @DarkXero, thanks!! This is exactly what i was looking for, you've done so much for me that i feel i should buy you a drink. You're awesome man!!


Btw, is there a way to delete the spellcast animation if you're in cooldown? I mean, if you still have time before being able to do the spell again, then you just get the cooldown time left message instead of doing the spell animation with no effect. I think maybe i can just remove the spellbook_freeze from the else part, here:

	else
		if owner and owner.components.talker then
			local timeleft = math.ceil(inst.components.timer:GetTimeLeft("spellbook_freeze"))

So it will be like this:

	else
		if owner and owner.components.talker then
			local timeleft = math.ceil(inst.components.timer:GetTimeLeft)

Will this work?

And one more question, is this line what sets the range of effect of the frezze? The number 35?

		local targets = TheSim:FindEntities(pos.x, pos.y, pos.z, 35, {"freezable"}, {"player"})

 

Also, i will try to make my own animation to replace the book spell casting, when i got it done, i just replace this lines with my animation's name right?

local function fn()	

    inst.AnimState:SetBank("myanimation") -- here
	inst.AnimState:SetBuild("myanimation")
	inst.AnimState:PlayAnimation("my_animation")

or is it maybe this one..

	inst:AddComponent("spellbook")
	inst.components.spellbook.spell = spellcast

will turn into

	inst:AddComponent("spellbook")
	inst.components.spellbook.spell = myanimation.zip

 

I know the animation does nothing to do with the thing i asked, but i though it might be a good time to understand what triggers the animation :lol:

Again, thank you a lot @DarkXero, you made my day, now i'm a lot closer to finish phase 2 and publish the mod.

Link to comment
Share on other sites

37 minutes ago, Jpianist said:

Btw, is there a way to delete the spellcast animation if you're in cooldown? I mean, if you still have time before being able to do the spell again

Yes, instead of letting the stategraph go into the "book" state, you return the function without giving nothing, as in the attachment.

When the timer is active, the "cooldown" tag will be on the book, so you won't go into the "book" state.

38 minutes ago, Jpianist said:

I think maybe i can just remove the spellbook_freeze from the else part, here:

inst.components.timer:GetTimeLeft("spellbook_freeze")
inst.components.timer:GetTimeLeft

You butchered the function call and achieved absolutely nothing but a crash.

"spellbook_freeze" is a key inside the timers table of the timer component.

41 minutes ago, Jpianist said:

And one more question, is this line what sets the range of effect of the frezze? The number 35?

Yes, 35 is the range radius.

{"freezable"} is the table with tags that must be on the entity for it to be included on the targets table.

{"player"} is the table with tags that must NOT be on the entity for it to be included on the targets table.

42 minutes ago, Jpianist said:

Also, i will try to make my own animation to replace the book spell casting, when i got it done, i just replace this lines with my animation's name right?

  inst.AnimState:SetBank("myanimation")
  inst.AnimState:SetBuild("myanimation")
  inst.AnimState:PlayAnimation("my_animation")

No. This is for the ground animation. What you see when you drop the book.

Like for the equippable from scratch tutorial.

The reading animation for all books is the same. Keep it like that.

	inst:AddComponent("spellbook")
	inst.components.spellbook.spell = myanimation.zip

And this is beyond dumb.

spellcast IS A FUNCTION. spell GETS ASSIGNED A FUNCTION.

spellbooks.zip

Link to comment
Share on other sites

23 minutes ago, DarkXero said:

And this is beyond dumb.

:lol: I'm sorry, i know it is, i knew it was a dumb question when i asked that, but i was just clueless on how to change the spellcast animation and kind of propose random possibilities. The worst part is that i knew it was a function, but nevermind, it's 4am and i'm still here, brain fails when your sleepy :lol:

25 minutes ago, DarkXero said:

No. This is for the ground animation. What you see when you drop the book.

Like for the equippable from scratch tutorial.

Right, i forgot about that. Thanks for reminding me.

30 minutes ago, DarkXero said:

The reading animation for all books is the same. Keep it like that.

So the only way to have an useable ítem working is having the reading animation? There is no way of changing that?

Link to comment
Share on other sites

8 minutes ago, Jpianist said:

So the only way to have an useable ítem working is having the reading animation? There is no way of changing that?

Well, you can pick any of the other existing animations in the game.

Making a brand new animation for characters from scratch is not worth it.

Link to comment
Share on other sites

15 minutes ago, DarkXero said:

Well, you can pick any of the other existing animations in the game.

Making a brand new animation for characters from scratch is not worth it.

I'll give it a try with other existing animations, where do i place my choosen animation? What do i have to change to have another animation?

Edited by Jpianist
Link to comment
Share on other sites

7 minutes ago, Jpianist said:

I'll give it a try with other existing animations, where do i place the choosen animation in the spellcast.lua?

Nowhere.

When you want to perform an action, like ACTIONS.REPAIR, the game will handle the action in the wilson stategraph.

The handler handles the repair action and sends Wilson to the "dolongaction" state.

In the "dolongaction" state, you can see the animations played and/or pushed (set up to be played after).

("build_pre", then "build_loop", then "build_pst" if the state times out).

Link to comment
Share on other sites

10 minutes ago, DarkXero said:

When you want to perform an action, like ACTIONS.REPAIR, the game will handle the action in the wilson stategraph.

This sentence kind of gave me the answer. So if i wanna change the spellbook animation, i go into the modmain and change all "ACTIONS.CASTSPELLBOOK" to (for example), "ACTIONS.REPAIR".

Am i right? :D

Link to comment
Share on other sites

7 minutes ago, Jpianist said:

This sentence kind of gave me the answer. So if i wanna change the spellbook animation, i go into the modmain and change all "ACTIONS.CASTSPELLBOOK" to (for example), "ACTIONS.REPAIR".

Am i right?

You don't want to send the ACTIONS.REPAIR to the "book" state.

You want to send the ACTIONS.CASTSPELLBOOK to another state.

AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.CASTSPELLBOOK, function(inst, act)
	local target = act.target or act.invobject
	if target and target:HasTag("cooldown") then
		if target.prefab == "spellbook_freeze" then
			if inst.components.talker then
				local timeleft = math.ceil(target.components.timer:GetTimeLeft("spellbook_freeze"))
				inst.components.talker:Say("Cooldown: "..tostring(timeleft).."s")
			end
		elseif target.prefab == "spellbook_heal" then
			if inst.components.talker then
				local timeleft = math.ceil(target.components.timer:GetTimeLeft("spellbook_heal"))
				inst.components.talker:Say("Cooldown: "..tostring(timeleft).."s")
			end
		end
		return
	end
	return "book"
end))

See that "book"?

The handler handles the action and returns "book".

You want it to return something else.

Link to comment
Share on other sites

51 minutes ago, DarkXero said:

See that "book"?

The handler handles the action and returns "book".

You want it to return something else.

What about ACTIONS.READ for the book state? Will that work and change the spellcast animation to a different one? (The answer is no, still the same book reading animation, i tried) :lol:

or..

If i wanna (for example) have the angry emote animation, i have to change the code to return "angry"? And also change the "ACTIONS." to one that suits the angry state?

Edited by Jpianist
Link to comment
Share on other sites

6 hours ago, Jpianist said:

What about ACTIONS.READ for the book state? Will that work and change the spellcast animation to a different one? (The answer is no, still the same book reading animation, i tried) :lol:

or..

If i wanna (for example) have the angry emote animation, i have to change the code to return "angry"? And also change the "ACTIONS." to one that suits the angry state?

did you already tried to just return "angry" ?
From what I understand from DarkXeros posts, you should never change the ACTIONS. thing ;) Cause if you change this, he won't do a spellcast, but tries to repair the book for example.

 

edit:
you marked the thread as solved, so what exactly was the solution?

Edited by Serpens
Link to comment
Share on other sites

5 hours ago, Serpens said:

did you already tried to just return "angry" ?
From what I understand from DarkXeros posts, you should never change the ACTIONS. thing ;) Cause if you change this, he won't do a spellcast, but tries to repair the book for example.

 

edit:
you marked the thread as solved, so what exactly was the solution?

Oh i understand now, i shouldn't change the spellcast action, just the return thing, i'll try that. Btw yeah, i marked solved because this topic was about the useable but unequippable ítems, which is solved, the animation thing is just an extra i'm trying to figure out. I'm just waking up right now so i'm gonna try the return thing. :encouragement:

EDIT: I tried but now it doesn't do anything (with return "angry", now i use the ítem but does nothing). I still think it might work but need to change some other things, i'll keep trying other stuff and if i discover how to do it i'll tell you guys.

Edited by Jpianist
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...