Jump to content

Forums Announcement

Read-Only Mode for Announcements & Changelogs

Dear Survivors, we'd like to inform you that this forum will transition to read-only mode. From now on, it will serve exclusively as a platform for official announcements and changelogs.

For all community discussions, debates, and engagement, we encourage you to join us on our social media platforms: Discord, Twitter/X, Facebook.

Thank you for being a valued part of our community. We look forward to connecting with you on our other channels!

Stay safe out there,
Your DayZ Team

Ballroghdemon

Not compile - Init.c Event and message

Recommended Posts

 

I try to implement the code to identify the event of adding an object to the inventory, check it and if it matches the correct one send a notification, I have this code but I am not able to compile it, can you help me? thank you so much.

class CustomMission: MissionServer
{
    override void OnItemAddedToInventory(EntityAI item, InventoryLocation src, InventoryLocation dst, PlayerBase player)
    {
        super.OnItemAddedToInventory(item, src, dst, player);
        
        if (item.GetType() == "Kukri")
        {
            player.MessageStatus("¡Enhorabuena! Has recogido un kukri y lo has añadido a tu inventario.");
        }
    }
}
 

Share this post


Link to post
Share on other sites
9 minutes ago, Ballroghdemon said:

 

I try to implement the code to identify the event of adding an object to the inventory, check it and if it matches the correct one send a notification, I have this code but I am not able to compile it, can you help me? thank you so much.

class CustomMission: MissionServer
{
    override void OnItemAddedToInventory(EntityAI item, InventoryLocation src, InventoryLocation dst, PlayerBase player)
    {
        super.OnItemAddedToInventory(item, src, dst, player);
        
        if (item.GetType() == "Kukri")
        {
            player.MessageStatus("¡Enhorabuena! Has recogido un kukri y lo has añadido a tu inventario.");
        }
    }
}
 

The problem is that event handler "OnItemAddedToInventory" is event of PlayerBase class instance, nevertheless you trying to override it inside of instance of MissionServer class. That's wrong and impossible because of your mission is a player unit. There's only one way to override it - write a mod that will override PlayerBase.OnItemAddedToInventory, where you can implement your own overwritten version of that event handler. But I guss that you migh met another problem, item could be added with 2 ways: 1st is - ingame (you place it inventory or take a loot); 2nd is - you manually spawning it through the script and then you migh meet a problem that event will not fire as it expected (i mean not fired at all).

Share this post


Link to post
Share on other sites

 

Thank you very much for your help. Do you think it would be possible, at least with that degree of error, to detect the event and send the notification? I'm messing with how the class system works and I can't get it to compile correctly.

Estoy valorando esta alternativa

class CustomMission: MissionServer
{
    override void OnInitPhaseEvent(EventType type, Param params)
    {
        super.OnInitPhaseEvent(type, params);
        
        if (type == EventType.ON_INIT_PHASE_START)
        {
            if (GetGame().IsServer())
            {
                PlayerBase.Event_OnItemInInventory.Insert(OnItemInInventory);
            }
        }
    }

    void OnItemInInventory(PlayerBase player, EntityAI item)
    {
        if (item.GetType() == "Zen_Virus_Brain")
        {
            player.MessageStatus("¡Enhorabuena! Has recogido un kukri y lo has añadido a tu inventario.");
        }
    }
};

Mission CreateCustomMission(string path)
{
    return new CustomMission();
}

Share this post


Link to post
Share on other sites

I see. Let's look in example and try to understand the situation.

You wish to read W. Shakespeare, for example the Romeo and Guliet. Will you search the book on the shelf of books of Lev Tolstoy? Or will you search Shakespeare's "Sonnets" in the book with name: Lev Tolstoy Law and Peace?

That's exactly the same. Each class is separated and doing it's own jobs. That's why you can't override any class methods outside the parent class (without class inheritance).

 

I suggest you to understand the base of development on C# language, because Enfusion engine scripting is using the same logic for class definition and considering the Object Oriented Programming (OOP development pattern) as a base in understanding of development and codding.

Without understanding of that basics you'll not able to fast understanding how, why and what shall you do.

If you're familiar with scripting or know programming languages if would be better coz you'll faster will getting in.

If not well you have an interesting tasks to explore and brain hecking with...

Yet it's about 11:45pm to me and not really wish to start PC for brain hecking, but tomorrow I'll see what do i can do to help you with.

Share this post


Link to post
Share on other sites

Thank you very much, understood and I will try to go deeper into that language to see if I am able to compile it, perhaps what I am trying is complicated, at least for me, I appreciate at least your response and help. Thanks in advance. All the best.

Share this post


Link to post
Share on other sites

×