Trying to replace PlayingTeam:AddTeamResources with custom logic. But it's not working.

IronsoulIronsoul Join Date: 2011-03-12 Member: 86048Members
Hello, I'm trying to make a mod for NS2 and I'm having a fair bit of difficulty hooking into this function. I'm not entirely sure what I'm doing wrong.

Here's the code for my ModShared.lua as well as the code for my ModPlayingTeam.lua (which only replaces one function, well is trying to). My logic isn't complete naturally but I'm just trying to test it and get it working before moving forward. Modifying the function in the original file (well a duplicate file with PlayingTeam.lua as the name so ns2 loads it) works, so the logic itself works but I can't seem to hook into it without replacing the entire original file.

ModShared.lua:
if Server then
   Script.Load("lua/Server.lua")
elseif Client then
   Script.Load("lua/Client.lua")
elseif Predict then
   Script.Load("lua/Predict.lua")
end
 

Script.Load("lua/Class.lua")
 

-- Load mod files here.
Script.Load("lua/UberShotgun.lua")

if Server then
   Script.Load("lua/ModPlayingTeam.lua")
end

ModPlayingTeam.lua
function PlayingTeam:AddTeamResources(amount, isIncome)

    if amount > 0 and isIncome then
        self.totalTeamResourcesCollected = self.totalTeamResourcesCollected + amount
    end
    
    self:SetTeamResources(self.teamResources + amount * 2)
    
end

What am I doing wrong?

Comments

  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    Working under the assumption you are using the mod framework, you need to call:
    Class_Reload( "PlayingTeam", {})
    
    In your ModPlayingTeam.lua file (at the end after all your changes are done). You will also need to be sure that anything using PlayingTeam class is loading your file and not vanilla.
  • IronsoulIronsoul Join Date: 2011-03-12 Member: 86048Members
    That seems to have done the trick. Thank you very much.

    You're statement "You will also need to be sure that anything using PlayingTeam class is loading your file and not vanilla." I'm not too sure I understand what you mean by that.
Sign In or Register to comment.