Mod works locally but not on dedicated server



  • Hello,

    I am an absolute beginner in modding/scripting. But I tried to create a mod that removes ranged weapons from the game. I tried to learn from the GiantSlayers tutorial and Nabsters Chiv+ and I think I found a way on how to remove the ranged weapons: Simply remove them after spawning.

    It’s only one class and it works perfectly when I test it locally with bots. But on a dedicated server it doesn’t. You get the message that the weapon is removed from your loadout but you will still have it.

    This is the only class and the interesting function is the PerformOnSpawn:

    class CMTeamObjective extends AOCTeamObjective;
    
    static event class <gameinfo>SetGameType(string MapName, string Options, string Portal)
    {
        //returns this object's own class, so this class is setting itself to be the game type used
        return default.class;
    }
    
    function PerformOnFirstSpawn(Controller NewPlayer)
    {
            super(AOCGame).PerformOnFirstSpawn(NewPlayer);
    
            AOCPlayerController(NewPlayer).ReceiveChatMessage("", "Welcome to Chivalrous Melee!", EFAC_ALL, true, true, "#55CF04");
            AOCPlayerController(NewPlayer).ReceiveChatMessage("", "Unchivalrous weapons will be removed from your loadout.", EFAC_ALL, true, true, "#D4400F");
    }
    
    function PerformOnSpawn(Controller player)
    {
            local class <aocweapon>newPrimaryWeapon;
            local class <aocweapon>newAltPrimaryWeapon;
            local class <aocweapon>newSecondaryWeapon;
            local class <aocweapon>newTertiaryWeapon;
            local bool hadUnchivalrousWeapon;
    
            super(AOCGame).PerformOnSpawn(player);
    
            newPrimaryWeapon = AOCPlayerController(player).PrimaryWeapon;
            newAltPrimaryWeapon = AOCPlayerController(player).AltPrimaryWeapon;
            newSecondaryWeapon = AOCPlayerController(player).SecondaryWeapon;
            newTertiaryWeapon = AOCPlayerController(player).TertiaryWeapon;
            hadUnchivalrousWeapon = false;
    
            if (class<aocrangeweapon>(newPrimaryWeapon) != none)
            {
                    newPrimaryWeapon = class'AOCWeapon_None';
                    hadUnchivalrousWeapon = true;
            }
    
            if (class<aocrangeweapon>(newAltPrimaryWeapon) != none)
            {
                    newAltPrimaryWeapon = class'AOCWeapon_None';
                    hadUnchivalrousWeapon = true;
            }
    
            if (class<aocrangeweapon>(newSecondaryWeapon) != none)
            {
                    newSecondaryWeapon = class'AOCWeapon_None';
                    hadUnchivalrousWeapon = true;
            }
    
            if (class<aocrangeweapon>(newTertiaryWeapon) != none)
            {
                    newTertiaryWeapon = class'AOCWeapon_None';
                    hadUnchivalrousWeapon = true;
            }
    
            if (hadUnchivalrousWeapon)
            {
                    AOCPlayerController(player).ReceiveChatMessage("", "Removed an unchivalrous weapon from your loadout.", EFAC_ALL, true, true, "#D4400F");      
            }
    
            AOCPlayerController(player).SetWeapons(newPrimaryWeapon, newAltPrimaryWeapon, newSecondaryWeapon, newTertiaryWeapon);
            AOCPlayerController(player).SwitchToBestWeapon();
    }
    
    defaultproperties
    {
        ModDisplayString="Chivalrous Melee"
        ModeDisplayString="Team Objective"
    }</aocrangeweapon> </aocrangeweapon></aocrangeweapon></aocrangeweapon></aocweapon></aocweapon></aocweapon></aocweapon></gameinfo>
    

    Any help would be greatly appreciated!

    Cheers :)



  • It’s probably better to remove the weapons from the Family Info classes. Extend a class for each of the FamilyInfos for each faction (ex: CUSTOMFamilyInfo_Agatha_Archer extends AOCFamilyInfo_Agatha_Archer). On the default properties you type “NewPrimaryWeapons.Empty;” to remove the weapons and under that you list the weapons you want, starting from zero (ex:"NewPrimaryWeapons(0)=CWeapon=class’AOCWeapon_someweapon’ ").

    Then you have to tell your Custom Pawn class to use your Custom FamilyInfos in the Default Properties. (look for “AllClasses(ECLASS_Archer)=”)

    After that you just have to tell your Custom Game class to use your Custom Pawn class and you are done.



  • Nabster helped me fix this. Wasn’t really a problem with replication. The AreWeaponsValidForCurrentFamilyInfo() function prevented the loadout change and gave me a default loadout.

    Simple hack

    function bool AreWeaponsValidForCurrentFamilyInfo()
    {
        return true;
    }
    

Log in to reply