Toggle Binds

RokiyoRokiyo A.K.A. .::FeX::. Revenge Join Date: 2002-10-10 Member: 1471Members, Constellation
<div class="IPBDescription">Not quite lastinv, but close</div>As per the discussion going on over here: <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=116452" target="_blank">http://www.unknownworlds.com/ns2/forums/in...howtopic=116452</a>

I haven't managed to add a new input command, so haven't been able to create a genuine lastinv key. In the mean-time, I've given the five weapon keys binds toggle functionality for players on the ground.

Pressing a weapon key will bring that weapon out. Pressing it again will bring your primary weapon out. If, for example, you were to rebind slot2 to Q, you could whack Q repeatedly to switch betweens slots 1 & 2 (shotgun/pistol, spikes/spores, etc etc).

<b>Download</b>
To use it, replace Steam\steamapps\common\natural selection 2\ns2\lua\Player.lua with this: <a href="http://www.unknownworlds.com/ns2/forums/index.php?act=attach&type=post&id=36061" target="_blank">Player.zip</a>

<b>Code</b>
Added the following on line 57:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Player.kLastWeapon = 1<!--c2--></div><!--ec2-->
Modified function Player:HandleButtons(input) at line 2269:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->    // Weapon switch
    if not self:GetIsCommander() then
        local weaponNum
    
        if bit.band(input.commands, Move.Weapon1) ~= 0 then
            self:SwitchWeapon(1)
            Player.kLastButton = 1
        end
              
        if bit.band(input.commands, Move.Weapon2) ~= 0 then
            if (Player.kLastButton == 2) then weaponNum = 1 else weaponNum = 2 end
            
            self:SwitchWeapon(weaponNum)
            Player.kLastButton = weaponNum
        end
        
        if bit.band(input.commands, Move.Weapon3) ~= 0 then
            if (Player.kLastButton == 3) then weaponNum = 1 else weaponNum = 3 end
            
            self:SwitchWeapon(weaponNum)
            Player.kLastButton = weaponNum
        end
        
        if bit.band(input.commands, Move.Weapon4) ~= 0 then
            if (Player.kLastButton == 4) then weaponNum = 1 else weaponNum = 4 end
            
            self:SwitchWeapon(weaponNum)
            Player.kLastButton = weaponNum
        end
        
        if bit.band(input.commands, Move.Weapon5) ~= 0 then
            if (Player.kLastButton == 5) then weaponNum = 1 else weaponNum = 5 end
            
            self:SwitchWeapon(weaponNum)
            Player.kLastButton = weaponNum
        end
        
    end<!--c2--></div><!--ec2-->

Comments

  • RokiyoRokiyo A.K.A. .::FeX::. Revenge Join Date: 2002-10-10 Member: 1471Members, Constellation
    To create a proper lastinv key, I've only gotten as far as figuring out how to add new options to the key bindings menu BindingsDialog.lua.

    I haven't found where the Move object is defined, so I have been unable to add new commands to it. If anybody here knows where it is, a heads up would be appreciated.

    Being able to do something like
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if bit.band(input.commands, Move.LastInv) ~= 0 then<!--c2--></div><!--ec2-->Would allow me to add entirely new keys with their own logic.
  • CodeineCodeine Join Date: 2010-11-22 Member: 75155Members
    or just install this <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=113246&st=0&start=0" target="_blank">http://www.unknownworlds.com/ns2/forums/in...t=0&start=0</a>
  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    edited February 2012
    Sorry misread post :P
  • RokiyoRokiyo A.K.A. .::FeX::. Revenge Join Date: 2002-10-10 Member: 1471Members, Constellation
    <!--quoteo(post=1904712:date=Feb 19 2012, 02:53 PM:name=Codeine)--><div class='quotetop'>QUOTE (Codeine @ Feb 19 2012, 02:53 PM) <a href="index.php?act=findpost&pid=1904712"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->or just install this <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=113246&st=0&start=0" target="_blank">http://www.unknownworlds.com/ns2/forums/in...t=0&start=0</a><!--QuoteEnd--></div><!--QuoteEEnd-->
    Ah, right you are. Good job I only wasted a couple of minutes on this then. :P
  • GuneeYoufixGuneeYoufix Join Date: 2012-09-06 Member: 158059Members
    Hi all,

    As a beginner modder for ns2, and a newbie at Lua, I wanted to try and get involved by starting with a simple enough implementation.
    The last used weapon seemed a good idea, and I of course, ran into the same problem as you did: where on Earth is located this Move class/object.
    Up to now, the question stays without answer.

    Has anyone finally found where this file is located? I'm starting to think that this is implemented in some dll, or even in Spark itself.

    I have another project in mind for a nice and useful mod for NS2 (I won't divulge the topic, as I'm not sure my partner in crime is ready to make it sort of public), and it will also require some handling of pressing keys. Having the flexibility to add some would really be a bonus I believe.

    Also, would someone be kind enough to explain how the mod proposed by Codeine solves the problem (or works around it)?

    Cheers
Sign In or Register to comment.