Jump to content

Recommended Posts

I just want to make an item that, when used, make something spawn on the map then disappears.

But i don't find any item to use as a model.

Instruments use a "play" function, healing items an "healing" component, and map scroll a maprecorder component. I don't see a basic item involving no anim but where i can put a custom function to use.

 

I'm probably missing some obvious example, but i would appreciate any help to point me in the right direction.

Don't want to make commercial for my mod, but you can check the arrows from my Archery Mod. When you right click on them in your inventory they are transferred to a custom container. I believe that's the kind of thing you mean by "use from inventory"?

 

EDIT: I realized you asked for a "basic item" so you probably don't want to involve custom components?

Edited by ZupaleX

Yeah, i mean right click, like you can do for food and healing items and this kind of stuff, or even some staff/music instruments (you right click, you do your custom action), but the closest at the moment would be the staffes and i'm not sure it's a "clean" way to manage it.

 

It's not i'm against a custom component, but it feel like using big solution for what seems to me a "tiny" problem. Maybe it's not so tiny ?

Well you either need to add a custom action to your object or hack an already existing one.

I am saying stuffs without thinking too much about it so it might not work, but the first thing I would try would be to take an existing component like the instrument and try to see if you can hack the play action. There is probably a function OnPlay which you could override for your item.

Like in your prefab instantiation function

inst:AddComponent("instrument")
inst.components.instrument.OnPlay = function(...) [...] end

I don't even know if this function exists but there must be something similar.

 

EDIT: I checked quickly the instrument.lua

You could override it like that

local function MyOnPlayFn(inst, player)
	[... Do your stuff ...]
end

local function myprefab_fn()
	[... Classic Stuffs ...]

	inst:AddComponent("instrument")
	inst.components.instrument:SetOnPlayedFn(MyOnPlayFn)
	inst.components.instrument.Play = function(self, player)
		self.onplayed(self.inst, player)
		return true
	end
	
	return inst
end

Totally untested and written in 2min so comes with no warranties :)

Edited by ZupaleX

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