Toggle Binds
<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-->
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
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.
Ah, right you are. Good job I only wasted a couple of minutes on this then. :P
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