ELEMENTALCRAFTER009 Posted May 1, 2015 Share Posted May 1, 2015 (edited) 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 May 1, 2015 by ELEMENTALCRAFTER009 Link to comment Share on other sites More sharing options...
DarkXero Posted May 1, 2015 Share Posted May 1, 2015 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) Link to comment Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted May 2, 2015 Author Share Posted May 2, 2015 (edited) 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 May 2, 2015 by ELEMENTALCRAFTER009 Link to comment Share on other sites More sharing options...
DarkXero Posted May 2, 2015 Share Posted May 2, 2015 @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. Link to comment Share on other sites More sharing options...
ELEMENTALCRAFTER009 Posted May 2, 2015 Author Share Posted May 2, 2015 (edited) @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 May 2, 2015 by ELEMENTALCRAFTER009 Link to comment Share on other sites More sharing options...
DarkXero Posted May 2, 2015 Share Posted May 2, 2015 @ELEMENTALCRAFTER009, yes.Or you can insert the content of the AddPrefabPostInit into your character's prefab. AddStategraphActionHandler and AddAction are only for the mod environment though. Link to comment Share on other sites More sharing options...
NeddoFreddo Posted September 11, 2015 Share Posted September 11, 2015 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 :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 Link to comment Share on other sites More sharing options...
DarkXero Posted September 12, 2015 Share Posted September 12, 2015 @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. Link to comment Share on other sites More sharing options...
NeddoFreddo Posted September 12, 2015 Share Posted September 12, 2015 (edited) @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 September 12, 2015 by NeddoFreddo Link to comment Share on other sites More sharing options...
DarkXero Posted September 12, 2015 Share Posted September 12, 2015 @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) Link to comment Share on other sites More sharing options...
ZupaleX Posted September 13, 2015 Share Posted September 13, 2015 For the birds to fly away or rabbits to flee you could do something like thatlocal 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 endendand then call this in your projectile.onhitfn Link to comment Share on other sites More sharing options...
NeddoFreddo Posted September 13, 2015 Share Posted September 13, 2015 @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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now