Page MenuHomeFeedback Tracker

Allow us to add functions to classes with native functions through children classes.
New, UrgentPublic

Description

I completely understand why you would prevent us from modding classes that contain native functions; however, there needs to be away for us to add functions to some of these classes, or you would have to give us and use a child class as you do with EntityAI and ItemBase (We cannot change EntityAI, but the child ItemBase we can change). I really would like to add my own functions to the UIManager and UIScriptedMenu classes. Making a child of the base would force the modder to write specifically for my library, but the ability to write those functions into the already base game scripts would allow those to not have to learn a new base class for UI.

Would it be possible for you to make a modded child classes for us mod?

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 7
Category
General

Event Timeline

ukulelekid713 added a comment.EditedFeb 29 2020, 10:05 AM

My end goal is to have it like this:

modded class UIScriptedMenuChild
{
    protected ref map<int, ref RPCBase> rpcs;

    void UIScriptedMenuChild()
    {
        rpcs = new map<int, ref RPCBase>;
        
        InitRPCs();
    }

    void InitRPCs()
    {
    }

    void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
    {
        autoptr RPCBase rpc = rpcs.Get(rpc_type);

        if(rpc != null)
        {
            rpc.ExecuteRPC(sender, null, ctx, this);
            return;
        }
    }

    void AddRPC(typename type, int id)
    {
        ref RPCBase rpc = type.Spawn();

        if(rpc != null)
        {
            rpc.SetRPCType(id);
            rpcs.Insert(id, rpc);
        }
    }
}

modded class UIManagerChild
{
    void UIManagerChild()
    {
        GetDayZGame().Event_OnRPC.Insert( OnRPC );
    }

    void OnRPC(PlayerIdentity sender, Object target, int rpc_type, ParamsReadContext ctx)
    {
        UIScriptedMenu menu = GetMenu();

        while(menu)
        {
            if(menu.GetParentMenu())
            {
                menu = menu.GetParentMenu();
            }else{
                menu.OnRPC(sender, null, rpc_type, ctx);
                return;
            }
        }
    }
}

You wouldn't have to change any code which already uses the code from UIScriptedMenu since everything is written in the base class, but you'd have to change the constructor for where GetUIManager gets the moddable class instead of the non-moddable class.