Help modding/custom weapons

EggOfAwesomeEggOfAwesome Join Date: 2015-01-31 Member: 201139Members

I was following some modding tutorials and found a cool one about adding effects to weapons. It taught how to make a shotgun light things on fire, but out of curiousity wanted to try to do it with an axe. Unfortunely it seems to have got messed up. I'm not sure if the naming is wrong, but where I put "axe" was originally shotgun, in hopes of well, getting an axe that lights things on fire. This is what I put below. (In the lua folder of the source of my "mod" from LaunchPad, a.k.a in mymodname.lua



function Axe:ApplyBulletGameplayEffects(player, hitEnt, impactPoint, Direction, damage, surface, showTracer)
   if HasMixin(hitEnt, "Fire") then
       hitEnt:SetOnFire(player, self)
   end
end

Any ideas onto how to get it working?

Comments

  • GhoulofGSG9GhoulofGSG9 Join Date: 2013-03-31 Member: 184566Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Reinforced - Supporter, WC 2013 - Supporter, Pistachionauts
    edited June 2015
    It's not working because the Axe is not shooting bullets ;)

    The ApplyBulletGameplayEffects method is part of the BulletMixin which is inherited by the ClipWeapon class. And the Riftle class is a child of the ClipWeapon class.

    If the previous sentence doesn't make sense to you best read up about the OOP concept (http://en.wikipedia.org/wiki/Object-oriented_programming).
    You need to know and be used to it to really work with the ns2 code or any kind of modern coding language.

    But the Axe is just a simple child of the Weapon class. So declaring the given method there won't make any difference.

    So how to apply "fire blade" to the axe:

    Let's simple use the DamageMixin:DoDamage(damage, target, point, direction, surface, altMode, showtracer) function. ( http://ns2docs.bplaced.net/ns2docs/tables/DamageMixin/index.html )

    So it's
    function Axe:DoDamage(damage, target, point, direction, surface, altMode, showtracer)
    if damage > 0 then --sometimes there are hits with 0 damage don't ask why now
    if target and HasMixin(target, "Fire") then -- check if target is burnable
    if self:GetParent() and self:GetParent():isa("Player") then --self refers to the axe, parent should be the player holding the axe
    local player = self:GetParent()
    if GetAreEnemies( player, target ) then --don't hurt friendly targets
    target:SetOnFire(player,self) --let them burn
    end
    end
    end
    end
    end
    Here the link to the gist as the code block is making it so ugly and hard to read: https://gist.github.com/anonymous/ebc42f37261f3b6bd007

    I once started a mod guide but never ever worked again at it but it might help you to sort out the basics: https://goo.gl/ipxtYQ


  • EggOfAwesomeEggOfAwesome Join Date: 2015-01-31 Member: 201139Members
    Thank you so much!  :) 
    One additional question though, my rifle and pistol don't do any damage, was that my computer glitching out or did the code do that? (my computer loves to do stuff like that on occasion.)
  • GhoulofGSG9GhoulofGSG9 Join Date: 2013-03-31 Member: 184566Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Reinforced - Supporter, WC 2013 - Supporter, Pistachionauts
    edited June 2015
    Thank you so much!  :) 
    One additional question though, my rifle and pistol don't do any damage, was that my computer glitching out or did the code do that? (my computer loves to do stuff like that on occasion.)
    Could it be that you tested your mod pregame? I just realized i missed a check for that. Try to use cheats 1 to start the game.

    Edit: The "fixed" version:
    function Axe:DoDamage(damage, target, point, direction, surface, altMode, showtracer)
    if damage > 0 then --sometimes there are hits with 0 damage don't ask why now
    if target and HasMixin(target, "Fire") then -- check if target is burnable
    if self:GetParent() and self:GetParent():isa("Player") then --self refers to the axe, parent should be the player holding the axe
    local player = self:GetParent()
    if CanEntityDoDamageTo( player, target ) then --don't hurt friendly targets or while pregame etc.
    target:SetOnFire(player,self) --let them burn
    end
    end
    end
    end
    end

    Gist: https://gist.github.com/GhoulofGSG9/5aaa5e8ebf2d899964d9




  • EggOfAwesomeEggOfAwesome Join Date: 2015-01-31 Member: 201139Members
    Thanks for the help. Yeah, I forgot it was pregame. :#
    I'm having fun burning and axing hives and harvesters with this. I wonder what'd happen if I kill a hive in pregame... >:)
  • BeigeAlertBeigeAlert Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
    Wow that code highlighting is... it leaves a lot to be desired.
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Can we please have a fix for the CDT theme code highlighting? My eyes are popping after trying to read that :P
Sign In or Register to comment.