Yakuzashi Posted May 21, 2018 Share Posted May 21, 2018 Hi, I had an idea about shotgun (or other firearm) as main weapon of my character in DST. I have created 3 character mods so far, but I used Extended Sample Character Template by Dleowolf, so basically I do not have any knowledge and I have a little experience about simple modding. Anyway I want my character to be badass with shotgun, but I totally don't know how to achieve it. Programing in Lua is black magic to me and I do not want to bother one very kind person from this forum everytime I need help with something trivial for veteran modders. I would be grateful for every clue. Thank you in advance and have a nice day. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 23, 2018 Share Posted May 23, 2018 Hmm interesting I thought someone else would have the code for something like this, guess not. I only have code that's close to a gun/crossbow so I haven't coded something like the spread of the pellets to hit multiple enemies. First you need something the modmain: local STRINGS = GLOBAL.STRINGS local ACTIONS = GLOBAL.ACTIONS local Action = GLOBAL.Action AddComponentPostInit("combat", function(Combat, inst) local DoAttack_prev = Combat.DoAttack function Combat:DoAttack(target_override, weapon, ...) if weapon and weapon.HasAmmo then if weapon:HasAmmo(inst) then return DoAttack_prev(self, target_override, weapon, ...) end return end return DoAttack_prev(self, target_override, weapon, ...) end end) Next is the weapon lua: inst.components.weapon:SetDamage(0) inst.components.weapon:SetRange(30) inst.components.weapon:SetProjectile("batteries") inst.HasAmmo = function(inst, owner) if (owner and owner.components.inventory and owner.components.inventory:Has("ammo", 1)) then owner.components.inventory:ConsumeByName("ammo", 1) inst.components.weapon:SetDamage(570) return true end return false end And there's your black magic. Link to comment Share on other sites More sharing options...
RedHairedHero Posted May 23, 2018 Share Posted May 23, 2018 This makes me think you could do an AOE attack as a cone instead of a circle. That way you would just hit whatever enemies are within the AOE instead of worrying about separate pellets. It would almost be a melee weapon, but you just have extended range and hit multiple enemies within an area. Just a few ideas. Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 23, 2018 Author Share Posted May 23, 2018 I've used code by K1NGT1GER609 and my character swings with weapon (I used it on sword-a-like thing) while staying in place. It doesn't come close to target and swing, just swing from place where it was. Is it caused by absence of ammo ? What shall I set as ammo then and how of course. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 24, 2018 Share Posted May 24, 2018 (edited) Oh yeah the ammo you'll need to make the bullets with this: use the sampleprefab.zip and in the lua file add these lines of code for the shotgun: local function OnHit(inst, owner, target) inst:Remove() end inst:AddTag("projectile") if not TheWorld.ismastersim then return inst end inst:AddComponent("stackable") inst.components.stackable.maxsize = 40 inst:AddComponent("projectile") inst.components.projectile:SetSpeed(40) inst.components.projectile:SetOnHitFn(OnHit) inst.components.projectile:SetOnMissFn(OnHit) Edited May 24, 2018 by K1NGT1GER609 Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 25, 2018 Author Share Posted May 25, 2018 I solved some of errors myself but due to lack of my knowledge I hit the wall that I just can't pass myself. Test.rar Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 25, 2018 Share Posted May 25, 2018 (edited) Actually this line of code should be above the main(fn(sim)): local function OnHit(inst, owner, target) inst:Remove() end in the ammo lua file. Declaring the function after the main the code the game will never see the function. Edited May 25, 2018 by K1NGT1GER609 Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 25, 2018 Author Share Posted May 25, 2018 When I keep these code lines: if not TheWorld.ismastersim then return inst end It gives me error. In other hand when I delete it there is no error, but when I attack something further away then character swings and nothing happens. I have an ammo in inventory and still nothing. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 25, 2018 Share Posted May 25, 2018 The code: if not TheWorld.ismastersim then return inst end needs to be between the animstate and inventory item like so: inst.AnimState:SetBank("ammo") inst.AnimState:SetBuild("ammo_build") inst.AnimState:PlayAnimation("idle", true) if not TheWorld.ismastersim then return inst end inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/ammo.xml" without theworld.ismastersim you get some weird errors. Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 25, 2018 Author Share Posted May 25, 2018 Error was fixed but this problem with weapon swing still occurs. I've made video about it. I hope you can see it without downloading. If I am wrong you can see it on youtube: video.flv Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 25, 2018 Share Posted May 25, 2018 (edited) So your saw is a gun? I'm not sure where your going with this. Your not using ammo probably cause your missing the code above: inst.components.weapon:SetDamage(0) inst.components.weapon:SetRange(12) inst.components.weapon:SetProjectile("ammo") inst.HasAmmo = function(inst, owner) if (owner and owner.components.inventory and owner.components.inventory:Has("ammo", 1)) then owner.components.inventory:ConsumeByName("ammo", 1) inst.components.weapon:SetDamage(570) return true end return false end Edited May 25, 2018 by K1NGT1GER609 Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 25, 2018 Author Share Posted May 25, 2018 Shall I paste it to weapon or ammo prefab ? When all of those technical problems will be solved I will change this saw to gun or something. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 25, 2018 Share Posted May 25, 2018 Weapon prefab Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 25, 2018 Author Share Posted May 25, 2018 Yay. It works ! After swing bird dies. I don't see projectile but it's kinda fun to kill with it. It can be used as Soul Sword or something like that to kill with swing. BTW if I want to make my animation similar to recoil from firing shotgun, shall I change animation.xml and build.xml in exported>swap_wand>swap_wand_saw.zip ? If yes, can I use any program to preview weapon position in character's hands ? Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 25, 2018 Share Posted May 25, 2018 I want to say you can make animations in spriter but animations in general are my gray field. I chose to work with bots over doing custom animations so I can't help much if you want to make animations. It does get messy though. Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 25, 2018 Author Share Posted May 25, 2018 Thanks. I will figure out something. Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 26, 2018 Author Share Posted May 26, 2018 (edited) What can I do to make projectiles visible ? I made some artworks for this new weapon. Now it's sawn-off shotgun not regular saw for cutting wood. I need projectiles to finish it off (except animations). Edited May 26, 2018 by Yakuzashi Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 26, 2018 Share Posted May 26, 2018 In order to see your projectile you'll have to match the setbank with your prefab name and setbuild with the name in the spriter file. Link to comment Share on other sites More sharing options...
Yakuzashi Posted May 26, 2018 Author Share Posted May 26, 2018 (edited) Ok, got it. Thanks once more. Edited May 26, 2018 by Yakuzashi Problem solved 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