[How do I?] replace client functions without breaking forward compatibility
syntroniks
Join Date: 2012-10-18 Member: 162662Members
Hello, unfortunately this is my first post. I've been in the pre-release for quite some time now and I am so happy with how far the game has come in just one year!!
To my question/situation:
I am able to replace existing classes and edit functionality -- that is fine, but I feel that when the game development progresses, some things I rely on may break in the future.
For an example, let's say I want to subclass the player and implement different functionality for one of the methods, say
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Player:GetCanClimb()
return true
end<!--c2--></div><!--ec2-->
and I want to force players to be ground-dwellers by removing their ability to climb anything.
<b>Can I do this in a separate file for just the changed functions?</b> Can I subclass the player/marine/alien and override that function without copying and pasting code from the current release (potentially requiring a mod update every time the game updates)
I hope this was clear, thank you for any help you can provide.
To my question/situation:
I am able to replace existing classes and edit functionality -- that is fine, but I feel that when the game development progresses, some things I rely on may break in the future.
For an example, let's say I want to subclass the player and implement different functionality for one of the methods, say
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function Player:GetCanClimb()
return true
end<!--c2--></div><!--ec2-->
and I want to force players to be ground-dwellers by removing their ability to climb anything.
<b>Can I do this in a separate file for just the changed functions?</b> Can I subclass the player/marine/alien and override that function without copying and pasting code from the current release (potentially requiring a mod update every time the game updates)
I hope this was clear, thank you for any help you can provide.
Comments
Example from the SoulCatcherMod:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Script.Load("lua/Class.lua")
Script.Load("lua/Player_Client.lua")
local kSoulEffect = PrecacheAsset("cinematics/soul.cinematic")
local originalPlayerOnKillClient
originalPlayerOnKillClient = Class_ReplaceMethod( "Player", "OnKillClient",
function(self)
local cinematic = Client.CreateCinematic(RenderScene.Zone_Default)
cinematic:SetCinematic(kSoulEffect)
cinematic:SetCoords(self:GetCoords())
originalPlayerOnKillClient(self)
end
)<!--c2--></div><!--ec2-->
Having this much lua inside a game is as interesting & fun as it is confusing at times :O
[I'm slowly making headway]
This is what I have been waiting for!!!
Thank You. The only questions is, does this only start with build 224? Or can we go back a couple versions to resurrect our currently broken mods without updates? I have 2 big mods, and a number of smaller mods, so making these constant changes has meant only 1 mod getting updated per build :P
Hard to build a playerbase when the mod only works every other NS2 release, hahah :D
Suppose I want to write something on the client that alters input. In other words, something that could mask a jump clientside so you can not jump as often.
Normally I'd just input.commands = bit.band(input.commands, bit.bnot(Move.Jump))
But it looks like the input is getting to the server unmodified and prediction is overwriting what I want to do.
Where/how is the correct way/place to modify/mask user input clientside?
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local originalScriptActorOverrideInput
originalScriptActorOverrideInput= Class_ReplaceMethod( "ScriptActor", "OverrideInput",
function(self, input)
Shared.Message("OverrideInput called!")
originalScriptActorOverrideInput(self, input)
end
)<!--c2--></div><!--ec2-->
In console, there is no output and changing the contents of this function does nothing. The "ReplaceMethodInDerivedClasses" function DOES iterate over all child classes so that seems in order. I could not find references in the lua files for something that calls OverrideInput at the player level (aside from its children).
Using the handy find . | xargs grep 'searchstring' to scour /ns2/lua
{btw: TY}
Class_ReplaceMethod won't replace the function in child class's if its been overrided in child class's
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local function ReplaceMethodInDerivedClasses(className, methodName, method, original)
if _G[className][methodName] ~= original then
return
end<!--c2--></div><!--ec2-->
How do I specify the version I want my mod to use?
It is in the publisher UI. I'm not going to start including the archived builds until the final release though, since so much is still in flux with the SDK at the moment that it wouldn't work anyway (since the SDK isn't versioned, only the game code).
I understand it's not available yet....
I understand it's not available yet....<!--QuoteEnd--></div><!--QuoteEEnd-->
That would be an interesting feature even outside of the context of mods (since you could go back and play older builds). I will discuss it with the team.