Recommended Posts

This might be long depending the answer, but I was wondering if was possible to make it so that when nothing is equipped in the hands slot, you can fire a projectile similar to the fire staffs?

Edited by ELEMENTALCRAFTER009

Share this post


Link to post
Share on other sites
DarkXero    2887

Well, the usual way is to make an equipped weapon a projectile.

 

But you can do something like this:

local CASTFIRE = AddAction("CASTFIRE", "Cast Fire", function(act)	local projectile = GLOBAL.SpawnPrefab("fire_projectile")	projectile:AddComponent("weapon")	projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())	projectile.components.projectile:Throw(act.doer, act.target)	return trueend)CASTFIRE.rmb = trueCASTFIRE.distance = 7AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(GLOBAL.ACTIONS.CASTFIRE, "throw"))AddPrefabPostInit("wilson", function(inst)	inst:DoTaskInTime(0, function()		local self = inst.components.playeractionpicker		self.rightclickoverride = function(inst, target, position)			local actions = {}			if target and target.replica.health and not (inst == target) then				table.insert(actions, GLOBAL.ACTIONS.CASTFIRE)			end			return self:SortActionList(actions, target)		end	end)end)

Share this post


Link to post
Share on other sites

 

Well, the usual way is to make an equipped weapon a projectile.

 

But you can do something like this:

local CASTFIRE = AddAction("CASTFIRE", "Cast Fire", function(act)	local projectile = GLOBAL.SpawnPrefab("fire_projectile")	projectile:AddComponent("weapon")	projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())	projectile.components.projectile:Throw(act.doer, act.target)	return trueend)CASTFIRE.rmb = trueCASTFIRE.distance = 7AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(GLOBAL.ACTIONS.CASTFIRE, "throw"))AddPrefabPostInit("wilson", function(inst)	inst:DoTaskInTime(0, function()		local self = inst.components.playeractionpicker		self.rightclickoverride = function(inst, target, position)			local actions = {}			if target and target.replica.health and not (inst == target) then				table.insert(actions, GLOBAL.ACTIONS.CASTFIRE)			end			return self:SortActionList(actions, target)		end	end)end)

Would this be for a specific character or for all characters? Also, is there a way to edit the projectile being fired as far as damage and effects?

 

Edit: Variable AddAction is not declared

Edited by ELEMENTALCRAFTER009

Share this post


Link to post
Share on other sites
DarkXero    2887

@ELEMENTALCRAFTER009, what I did there is for only one character: Wilson.

Although everybody gets the stategraph change, only Wilson gets the right click override.

 

If the variable AddAction is not declared, it's because you are not putting the code in modmain. It has to go there.

AddAction and AddStategraphActionHandler are only valid in modmain.

 

You can put the content of the AddPrefabPostInit in your character's prefab though.

Share this post


Link to post
Share on other sites

@ELEMENTALCRAFTER009, what I did there is for only one character: Wilson.

Although everybody gets the stategraph change, only Wilson gets the right click override.

 

If the variable AddAction is not declared, it's because you are not putting the code in modmain. It has to go there.

AddAction and AddStategraphActionHandler are only valid in modmain.

 

You can put the content of the AddPrefabPostInit in your character's prefab though.

Ah, okay. To change the character would I just change wilson in the AddPrefabPostinit to the desired character? And is there still a way to change the damage?

Edited by ELEMENTALCRAFTER009

Share this post


Link to post
Share on other sites
NeddoFreddo    1056

 

Well, the usual way is to make an equipped weapon a projectile.

 

But you can do something like this:

local CASTFIRE = AddAction("CASTFIRE", "Cast Fire", function(act)	local projectile = GLOBAL.SpawnPrefab("fire_projectile")	projectile:AddComponent("weapon")	projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())	projectile.components.projectile:Throw(act.doer, act.target)	return trueend)CASTFIRE.rmb = trueCASTFIRE.distance = 7AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(GLOBAL.ACTIONS.CASTFIRE, "throw"))AddPrefabPostInit("wilson", function(inst)	inst:DoTaskInTime(0, function()		local self = inst.components.playeractionpicker		self.rightclickoverride = function(inst, target, position)			local actions = {}			if target and target.replica.health and not (inst == target) then				table.insert(actions, GLOBAL.ACTIONS.CASTFIRE)			end			return self:SortActionList(actions, target)		end	end)end)

I'd like do to this for my character, but when i enable the char mod this happens :p:

post-655693-0-76980600-1442013612_thumb.

I added  this line of code to the chunk:

castlightning.id = "Cast Lightning Ball"

adn here is the whole chunk of code:

local CASTLIGHTNING = AddAction("castlightning", "Cast Lightning Ball", function(act)    local projectile = GLOBAL.SpawnPrefab("bishop_charge")    projectile:AddComponent("weapon")    projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())    projectile.components.projectile:Throw(act.doer, act.target)	castlightning.id = "Cast Lightning Ball"    return trueend)CASTLIGHTNING.rmb = trueCASTLIGHTNING.distance = 7 AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(GLOBAL.ACTIONS.CASTLIGHTNING, "throw")) AddPrefabPostInit("wally", function(inst)    inst:DoTaskInTime(3, function()        local self = inst.components.playeractionpicker        self.rightclickoverride = function(inst, target, position)            local actions = {}            if target and target.replica.health and not (inst == target) then                table.insert(actions, GLOBAL.ACTIONS.CASTLIGHTNING)            end            return self:SortActionList(actions, target)        end    end)end)

So hope you can help with that :p

Share this post


Link to post
Share on other sites
DarkXero    2887

@NeddoFreddo, there's no chance any of that work.

AddAction takes an action for argument in Don't Starve, not that info.

It also doesn't have the health replica, and the throw state is different.

local myaction = GLOBAL.Action(7, true, true, 7)myaction.str = "Cast Lightning Ball"myaction.id = "CASTLIGHTNING"myaction.fn = function(act)	act.doer.AnimState:PlayAnimation("throw")	act.doer:DoTaskInTime(7*GLOBAL.FRAMES, function()		local projectile = GLOBAL.SpawnPrefab("bishop_charge")		projectile:AddComponent("weapon")		projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())		projectile.components.projectile:Throw(act.doer, act.target)	end)	return trueendAddAction(myaction)AddComponentPostInit("playeractionpicker", function(self)	if not self.inst.prefab == "wilson" then return end	local _GRCA = self.GetRightClickActions	self.GetRightClickActions = function(self, target_ent, position)		local actions = _GRCA(self, target_ent, position)		if target_ent and target_ent.components.health and not (self.inst == target_ent) then			actions = self:SortActionList({ GLOBAL.ACTIONS.CASTLIGHTNING }, target_ent)		end		return actions	endend)

This works better.

Share this post


Link to post
Share on other sites
NeddoFreddo    1056

@NeddoFreddo, there's no chance any of that work.

AddAction takes an action for argument in Don't Starve, not that info.

It also doesn't have the health replica, and the throw state is different.

local myaction = GLOBAL.Action(7, true, true, 7)myaction.str = "Cast Lightning Ball"myaction.id = "CASTLIGHTNING"myaction.fn = function(act)	act.doer.AnimState:PlayAnimation("throw")	act.doer:DoTaskInTime(7*GLOBAL.FRAMES, function()		local projectile = GLOBAL.SpawnPrefab("bishop_charge")		projectile:AddComponent("weapon")		projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())		projectile.components.projectile:Throw(act.doer, act.target)	end)	return trueendAddAction(myaction)AddComponentPostInit("playeractionpicker", function(self)	if not self.inst.prefab == "wilson" then return end	local _GRCA = self.GetRightClickActions	self.GetRightClickActions = function(self, target_ent, position)		local actions = _GRCA(self, target_ent, position)		if target_ent and target_ent.components.health and not (self.inst == target_ent) then			actions = self:SortActionList({ GLOBAL.ACTIONS.CASTLIGHTNING }, target_ent)		end		return actions	endend)

This works better.

Thank you so much! I don't know if this is the right place to ask but there is one problem, when you use this to attack birds/rabbits etc they don't fly away after getting hit, I don't want people able to infintely get morsels from birds and rabbits. Also is there a way to add a cooldown, right now you can fire it like a machine gun.

Thanks again.

EDIT: A bigger issue is that any character can us the lightning ball ability now, for some reason.

Edited by NeddoFreddo

Share this post


Link to post
Share on other sites
DarkXero    2887

@NeddoFreddo, ah, yes, the playeractionpicker loads but the player prefab isn't setup in the moment.

So, here, another way to go with it. Also added 10 sec cooldown.

local myaction = GLOBAL.Action(7, true, true, 7)myaction.str = "Cast Lightning Ball"myaction.id = "CASTLIGHTNING"myaction.fn = function(act)	act.doer.lightincooldown = true	act.doer:DoTaskInTime(10, function() act.doer.lightincooldown = nil end)    act.doer.AnimState:PlayAnimation("throw")    act.doer:DoTaskInTime(7*GLOBAL.FRAMES, function()        local projectile = GLOBAL.SpawnPrefab("bishop_charge")        projectile:AddComponent("weapon")        projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())        projectile.components.projectile:Throw(act.doer, act.target)    end)    return trueendAddAction(myaction)local function editPAP(inst)	if not (inst.prefab == "wally") then		return	end	local self = inst.components.playeractionpicker	local _GRCA = self.GetRightClickActions	self.GetRightClickActions = function(self, target_ent, position)		local actions = _GRCA(self, target_ent, position)		if not self.inst.lightincooldown and target_ent and target_ent.components.health and not (self.inst == target_ent) then			actions = self:SortActionList({ GLOBAL.ACTIONS.CASTLIGHTNING }, target_ent)		end		return actions	endendAddSimPostInit(editPAP)

Share this post


Link to post
Share on other sites
ZupaleX    270

For the birds to fly away or rabbits to flee you could do something like that

local function runawaytest(target)  if target.components.health and not target.components.health:IsDead() then    if target:HasTag("bird") then      TheWorld:DoTaskInTime(0.5, function() target.sg:GoToState("flyaway") end)    elseif target.prefab == "rabbit" then      TheWorld:DoTaskInTime(0.5, function() target:PushEvent("gohome") end)    end  endend

and then call this in your projectile.onhitfn

 

 

Share this post


Link to post
Share on other sites
NeddoFreddo    1056

 

@NeddoFreddo, ah, yes, the playeractionpicker loads but the player prefab isn't setup in the moment.

So, here, another way to go with it. Also added 10 sec cooldown.

local myaction = GLOBAL.Action(7, true, true, 7)myaction.str = "Cast Lightning Ball"myaction.id = "CASTLIGHTNING"myaction.fn = function(act)	act.doer.lightincooldown = true	act.doer:DoTaskInTime(10, function() act.doer.lightincooldown = nil end)    act.doer.AnimState:PlayAnimation("throw")    act.doer:DoTaskInTime(7*GLOBAL.FRAMES, function()        local projectile = GLOBAL.SpawnPrefab("bishop_charge")        projectile:AddComponent("weapon")        projectile.Transform:SetPosition(act.doer.Transform:GetWorldPosition())        projectile.components.projectile:Throw(act.doer, act.target)    end)    return trueendAddAction(myaction)local function editPAP(inst)	if not (inst.prefab == "wally") then		return	end	local self = inst.components.playeractionpicker	local _GRCA = self.GetRightClickActions	self.GetRightClickActions = function(self, target_ent, position)		local actions = _GRCA(self, target_ent, position)		if not self.inst.lightincooldown and target_ent and target_ent.components.health and not (self.inst == target_ent) then			actions = self:SortActionList({ GLOBAL.ACTIONS.CASTLIGHTNING }, target_ent)		end		return actions	endendAddSimPostInit(editPAP)

Thanks, thats all I needed witht that.

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