Sign in to follow this  
FaZZa

Item that can haunt - need help please

Recommended Posts

FaZZa    23

Hi all,

So im working an weapon that can haunt objects, if it has the ammo to do so. Ive been messing around with it for a while and had no luck yet.

I want the item to be able to cast a spell on the target as long as the target is hauntable, which will cause the items haunt effect, eg if the item was used on a pig, it would transform it into a werepig, if cast on a flower it would turn into an evil flower etc.

Ive made the ammo and the weapon, the prefab for the ammo is "soul" and the prefab for the weapon is "soullamp", if anyone could give me an idea of anything i could base this off, or even be good enough the write code for it, i would be very grateful.

Thanks in advance.

 

Share this post


Link to post
Share on other sites
Aquaterion    821

I tried to do this, using a way Muche suggested for me to do for my staffs(although for animations this would just do the staff animation, that part you'll have to figure out yourself I'm afraid. I'm not sure this 100% works as I just took mine as example and changed a few things so there might be something I missed.

modmain.lua:

AddComponentPostInit("hauntable", function(self)
	self.inst:AddTag("hauntable")--clients use tags, and sadly there wasnt a tag I could see for hauntable things, so I added 1
end)

local actSoulHaunt = AddAction("SoulHaunt", "Haunt", function(act)
	local lantern = act.invobject or act.doer.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS)

	if lantern 
	and lantern.components.spellcaster 
	and lantern.components.spellcaster:CanCast(act.doer, act.target, act.pos) 
	and lantern:HasTag("soullantern") then--u can change the tag to whatever tag u want, as long as the soullantern has it
		lantern.components.spellcaster:CastSpell(act.target, act.pos)
		return true
	end
end)
actSoulHaunt.priority = -1
actSoulHaunt.distance = 20
actSoulHaunt.mount_valid = true

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

-- add the "spell" to the stategraph under the state "castspell"
AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(actSoulHaunt,
	function(inst, action)
		return action.invobject.components.spellcaster.castingstate or "castspell"
end))
AddStategraphActionHandler("wilson_client", GLOBAL.ActionHandler(actSoulHaunt, "castspell"))

soullantern.lua

local function onsoulhaunt(lantern, target)
	local player = lantern.components.inventoryitem.owner
	target.components.hauntable:DoHaunt(player)
	--player:PushEvent("haunt", {target = target}) --not needed as nothing listens for it
end

--inside the main function of ur lantern prefab:

inst:AddTag("soullantern")
inst:AddComponent("spellcaster")
inst.fxcolour = { 1,1,1 } --staff fx color
inst.components.spellcaster:SetSpellFn(onsoulhaunt)

 

Edited by Aquaterion

Share this post


Link to post
Share on other sites
FaZZa    23

Thanks a lot for the reply, this works very nicely, and it doesnt crash, which is a bonus.

However when i actually cast the spell, the animation and sound plays, but nothing happens to the target, the character just says "i cant do that".

any ideas on fixing this?

 

Share this post


Link to post
Share on other sites
FaZZa    23

Ah yes that works brilliantly, thank you, evil flowers all over the place!

two problems though:

Firstly, the spell cast isnt using fuel

secondly, if cast on the portal, it causes the game to crash (i thought this might be because the character was trying to respawn using it, but i cast it on a touch stone and had no crash)

thanks for your help by the way, and sorry for all the questions

Share this post


Link to post
Share on other sites
Aquaterion    821
1 hour ago, FaZZa said:

Ah yes that works brilliantly, thank you, evil flowers all over the place!

two problems though:

Firstly, the spell cast isnt using fuel

secondly, if cast on the portal, it causes the game to crash (i thought this might be because the character was trying to respawn using it, but i cast it on a touch stone and had no crash)

thanks for your help by the way, and sorry for all the questions

well does ur lantern have durability?

like

inst:AddComponent("finiteuses")
inst.components.finiteuses:SetMaxUses(10)
inst.components.finiteuses:SetUses(10)


-- in the onsoulhaunt you can do
inst.components.finiteuses:Use(1)

as for the portal, If you were in endless, it might indeed be the revive thing.

this should stop you from being able to use it on reviver prefabs:

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

(find this part in the first version i gave you and replace it.)

 

Edit: btw, does the cast option appear on non hauntable items too?

Edited by Aquaterion

Share this post


Link to post
Share on other sites
FaZZa    23

Is there a way to do it without having duribility? i wanted to use the "soul" prefab as ammo, so it would consume the item, if it cant be done ill give it duribility

11 hours ago, Aquaterion said:

Edit: btw, does the cast option appear on non hauntable items too?

Its hard to tell, as nearly everthing in game can be haunted, however i have found that if you cast the spell on yourself, it crashes the game

 

Edited by FaZZa

Share this post


Link to post
Share on other sites
Aquaterion    821
14 minutes ago, FaZZa said:

Is there a way to do it without having duribility? i wanted to use the "soul" prefab as ammo, so it would consume the item, if it cant be done ill give it duribility

Its hard to tell, as nearly everthing in game can be haunted, however i have found that if you cast the spell on yourself, it crashes the game

 

well what you can do is make souls be its fuel, and use the fueled component instead?

as for the crash, it might be indeed due to it still appearing on non-hauntables, try this:

modmain.lua

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)

soulantern.lua(under the spellcaster component)

inst.components.spellcaster.islantern = true
-- remove the spellcaster.canuseontargets thing

 

Edited by Aquaterion

Share this post


Link to post
Share on other sites
FaZZa    23

That new set of code works perfectly, thank you.

Any ideas where i can start with the fuel part? i was going to look at the Maxwell Journal, but then i remembered they changed how it works, so i dont have a clue where to start with this.

 

 

Share this post


Link to post
Share on other sites
Aquaterion    821
21 minutes ago, FaZZa said:

That new set of code works perfectly, thank you.

Any ideas where i can start with the fuel part? i was going to look at the Maxwell Journal, but then i remembered they changed how it works, so i dont have a clue where to start with this.

 

 

--modmain.lua
GLOBAL.FUELTYPE.SOUL = "SOUL"

--soul lantern main fn
inst:AddComponent("fueled")
inst.components.fueled.fueltype = FUELTYPE.SOUL
inst.components.fueled.accepting = true
inst.components.fueled:InitializeFuelLevel(100)--you can change this to any value

--soul lantern onsoulhaunt fn
lantern.components.fueled:DoDelta(-10) -- 10% each haunt, you can change this to any value, make sure its minus

--souls main fn
inst:AddComponent("fuel")
inst.components.fuel.fueltype = FUELTYPE.SOUL
inst.components.fuel.fuelvalue = 10-- you can change this to any value

 

Edited by Aquaterion

Share this post


Link to post
Share on other sites
FaZZa    23

Ive put this in, and the lantern now has durability, which goes down by 10 each time i use it, however it isnt consuming the "soul" and can still cast the spell when at 0 durability, any ideas? 

Edited by FaZZa

Share this post


Link to post
Share on other sites
Aquaterion    821
55 minutes ago, FaZZa said:

Ive put this in, and the lantern now has durability, which goes down by 10 each time i use it, however it isnt consuming the "soul" and can still cast the spell when at 0 durability, any ideas? 

soul lantern:

local function onfueldelta(inst, pct)
	if pct == 0 then
		inst:RemoveComponent("spellcaster")
	else
		if inst.components.spellcaster == nil then
			inst:AddComponent("spellcaster")
			inst.components.spellcaster:SetSpellFn(onsoulhaunt)
			inst.components.spellcaster.islantern = true
		end
	end
end

--under fuel component in main fn
inst:ListenForEvent("percentusedchange", onfueldelta)
onfueldelta(inst, inst.components.fueled:GetPercent())

as for the soul not being consumed into the lantern.. im not sure.. it should be being removed by itself.. wait when you said isnt getting consumed. do you mean its not taking it, or is it giving it fuel but not using it?

 

Edited by Aquaterion

Share this post


Link to post
Share on other sites
FaZZa    23

This causes a crash before the game even starts creating world.

and i meant i can pick up the fuel, use the lantern, but nothing will happen to the soul, it will just stay in my inventory

 

 

Edited by FaZZa

Share this post


Link to post
Share on other sites
Aquaterion    821
2 minutes ago, FaZZa said:

This causes a crash before the game even starts creating world.

 

first issue i see is in "RemoveComponent" its misspelt(my bad), retype it correctly and see if it works

Share this post


Link to post
Share on other sites
FaZZa    23

yeah that stopped the crash :) 

It still isnt using the souls as ammo though, and still casts the spell at 0 durability 

Edited by FaZZa

Share this post


Link to post
Share on other sites
FaZZa    23

I have found the problem, because the soul lantern had a "container" tag, the souls wernt being used as ammo because it didnt give the option the  "refuel", instead just "open" or "close". Now the souls can be used to refuel the lantern.

Thanks alot for your help, Ill give you credit for helping me, really appreciate it :D

Edited by FaZZa

Share this post


Link to post
Share on other sites
Aquaterion    821
6 minutes ago, FaZZa said:

I have found the problem, because the soul lantern had a "container" tag, the souls wernt being used as ammo because it didnt give the option the  "refuel", instead just "open" or "close". Now the souls can be used to refuel the lantern.

Thanks alot for your help, Ill give you credit for helping me, really appreciate it :D

ah good job, ^^ did the no use on 0 durability work fine?

Edited by Aquaterion

Share this post


Link to post
Share on other sites
FaZZa    23
17 minutes ago, Aquaterion said:

ah good job, ^^ did the no use on 0 durability work fine?

no, havnt found a way around that yet

Share this post


Link to post
Share on other sites
FaZZa    23

Caused a crash before the game even starts creating world again

Edit: ive fixed the crash, where you put 

onfueldelta(inst, inst.components.fueled:GetPercent())

There needed to be a number between the two brackets at the end, so i threw a 0 in and no more crashing, it still casts the haunt with 0 durability though

Edited by FaZZa

Share this post


Link to post
Share on other sites
Aquaterion    821
8 minutes ago, FaZZa said:

Caused a crash before the game even starts creating world again

change:

onfueldelta(inst, inst.components.fueled:GetPercent())
--to
onfueldelta(inst, {percent = inst.components.fueled:GetPercent()})

 

Share this post


Link to post
Share on other sites
FaZZa    23
onfueldelta(inst, inst.components.fueled:GetPercent())
--to
onfueldelta(inst, {percent = inst.components.fueled:GetPercent()})

also caused a crash, however with the number between the brackets it doesnt

Share this post


Link to post
Share on other sites
Aquaterion    821
5 minutes ago, FaZZa said:

onfueldelta(inst, inst.components.fueled:GetPercent())
--to
onfueldelta(inst, {percent = inst.components.fueled:GetPercent()})

also caused a crash, however with the number between the brackets it doesnt

what number?

Share this post


Link to post
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
Sign in to follow this