Jump to content

Making skeletons hauntable


Recommended Posts

Hi all

Can anyone help me with some coding, I have an item that can haunt things, and want it so that when you use it on a skeleton it spawns a prefab, the skeleton can only be haunted by this specific item, so not ghosts.

If anyone could give me an idea of where to start, or even be great enough to write the code for me, id be very grateful.  The item has a custom tag "soullantern" in case a tag needs to be added.

Thanks in advance :) 

 

Edited by FaZZa
Edited because I cant spell
Link to comment
Share on other sites

Since I was the one that helped you last time, I still had a copy of a version of your, so all you gotta do is replace some stuff here and there

Changes:

 

--MODMAIN.LUA

--CHANGE:
AddComponentAction("EQUIPPED", "spellcaster", function(inst, doer, target, actions, right)
	if right then
		if inst ~= nil and inst:HasTag("canhaunt") and target:HasTag("hauntable") and not target:HasTag("resurrector") then
			table.insert(actions, actSoulHaunt)
		end
	end
end)

--TO:
AddComponentAction("EQUIPPED", "spellcaster", function(inst, doer, target, actions, right)
	if right then
		if inst ~= nil and inst:HasTag("canhaunt") and (target:HasTag("hauntable") or target.prefab == "skeleton" or target.prefab == "skeleton_player") and not target:HasTag("resurrector") then
			table.insert(actions, actSoulHaunt)
		end
	end
end)

--MODMAIN.LUA

--CHANGE:
AddComponentPostInit("spellcaster", function(self)
	self.islantern = false
	
	local oldCanCast = self.CanCast
	function self:CanCast(doer, target, pos)
		if self.islantern then
			return true
		else
			return oldCanCast(self, doer, target, pos)
		end
	end
end)

--TO:
AddComponentPostInit("spellcaster", function(self)
	self.islantern = false
	
	local oldCanCast = self.CanCast
	function self:CanCast(doer, target, pos)
		if self.islantern or target.prefab == "skeleton" or target.prefab == "skeleton_player" then
			return true
		else
			return oldCanCast(self, doer, target, pos)
		end
	end
end)

Soullamp.lua changes

 


--SOULLAMP.LUA

--CHANGE:
local function onsoulhaunt(lantern, target)
	local player = lantern.components.inventoryitem.owner
	lantern.components.fueled:DoDelta(-10) -- 50% each haunt, you can change this to any value, make sure its minus
	target.components.hauntable:DoHaunt(player)
	--player:PushEvent("haunt", {target = target}) --not needed as nothing listens for it
end

--TO:
local function onsoulhaunt(lantern, target)
	local player = lantern.components.inventoryitem.owner
	lantern.components.fueled:DoDelta(-10) -- 50% each haunt, you can change this to any value, make sure its minus
	if target.components.hauntable then
		target.components.hauntable:DoHaunt(player)
		--player:PushEvent("haunt", {target = target}) --not needed as nothing listens for it
	elseif target.prefab == "skeleton" or target.prefab == "skeleton_player" then--test code spawns a gold nugget and removes skeleton
		local x,y,z = target.Transform:GetWorldPosition()
		local monster = SpawnPrefab("goldnugget")
		monster.Transform:SetPosition(x,y,z)
		
		target:Remove()
	end
end

 

 

atm it spawns a gold nugget, you should be able to change it easily.

Edited by Aquaterion
Link to comment
Share on other sites

Works absolutely perfectly, thanks very much.

One thing though that i didnt think of, is it possible to add an effect to it, like a puff of smoke when it dissapears? just to make the transition a little smoother.

Link to comment
Share on other sites

8 minutes ago, FaZZa said:

Works absolutely perfectly, thanks very much.

One thing though that i didnt think of, is it possible to add an effect to it, like a puff of smoke when it dissapears? just to make the transition a little smoother.

fx are prefabs too, so doing

SpawnPrefab("collapse_small").Transform:SetPosition(x,y,z)

before removing the target would work fine.

that fx(which is smoke) might have some sound with it

8 minutes ago, FaZZa said:

Works absolutely perfectly, thanks very much.

One thing though that i didnt think of, is it possible to add an effect to it, like a puff of smoke when it dissapears? just to make the transition a little smoother.

fx are prefabs too, so doing

SpawnPrefab("collapse_small").Transform:SetPosition(x,y,z)

before removing the target would work fine.

that fx(which is smoke) might have some sound with it

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