Jump to content

Recommended Posts

Hello friends, I'm starting out in this world of creating mods and I'm trying to learn, I made this code that generates gift items for players, but it doesn't do anything, absolutely nothing, it's on the server side, I placed it in the 3_game folder, it doesn't generate an error and it doesn't do anything Can anyone help me get it to run?

 

class GiftItem {
    int deliveryTime;
    ref array<string> items;
    ref array<string> attachments; // Lista de anexos para cada item
}

class GiftConfig {
    ref array<ref GiftItem> m_GiftItems;

    void LoadConfig() {
        string jsonPath = "$profile:GiftLetal/gift_config.json";

        if (FileExist(jsonPath)) {
            JsonFileLoader<GiftConfig>.JsonLoadFile(jsonPath, this);
            Print("[Gift] Gift config loaded successfully.");
        } else {
            Print("[Gift] Gift config file not found.");
        }
    }
}

class GiftManager {
    protected ref GiftConfig m_Config;

    void GiftManager() {
        m_Config = new GiftConfig();
        m_Config.LoadConfig();
    }

    void CheckConnectionTime() {
        if (GetGame().IsServer()) {
            PlayerBase player = GetPlayer();

            if (player) {
                int playerConnectionTime = GetPlayerConnectionTime(player);

                foreach (ref GiftItem giftItem : m_Config.m_GiftItems) {
                    if (playerConnectionTime >= giftItem.deliveryTime) {
                        string chosenItem = giftItem.items.GetRandomElement();
                        ref array<string> attachments = giftItem.attachments; // Obtenha a lista de anexos

                        string playerName = player.GetIdentity().GetName(); // Obtém o nome do jogador
                        GetGame().ChatPlayer(0, playerName + " receberá um presente em 10 segundos pelo seu tempo logado.", player); // Mensagem no chat global para o jogador

                        // Espera 10 segundos antes de entregar o presente
                        GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(PerformGiftDelivery, 10000, false, chosenItem, attachments, player);

                        break;
                    }
                }
            }
        }
    }

    void PerformGiftDelivery(string itemName, ref array<string> attachments, PlayerBase player) {
        if (player) {
            vector playerPos = player.GetPosition();
            vector playerDir = player.GetDirection();
            vector dropPos = playerPos + (playerDir * 2);

            EntityAI item = EntityAI.Cast(GetGame().CreateObject(itemName, dropPos));

            // Adiciona os anexos ao item
            foreach (string attachment : attachments) {
                item.GetInventory().CreateAttachment(attachment);
            }

            Print("[Gift] Dropped item " + itemName + " with attachments " + attachments + " in front of player.");
        } else {
            Print("[Gift] Unable to drop item. Player not found.");
        }
    }

    int GetPlayerConnectionTime(PlayerBase player) {
        
        return 120; // Retorna 1 hora (3600 segundos) como exemplo
    }
}

class PluginMain {
    ref GiftManager m_GiftManager;

    void PluginMain() {
        m_GiftManager = new GiftManager();
        GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(m_GiftManager.CheckConnectionTime, 0, true); // Chama a cada tick
    }
}

void main() {
    PluginMain pluginMain;
    pluginMain = new PluginMain();
}

PlayerBase GetPlayer() {
    if (GetGame() && GetGame().GetPlayer()) {
        return PlayerBase.Cast(GetGame().GetPlayer());
    } else {
        return null;
    }
}

 

Share this post


Link to post
Share on other sites
2 hours ago, comiekto said:

Hello friends, I'm starting out in this world of creating mods and I'm trying to learn, I made this code that generates gift items for players, but it doesn't do anything, absolutely nothing, it's on the server side, I placed it in the 3_game folder, it doesn't generate an error and it doesn't do anything Can anyone help me get it to run?

 


class GiftItem {
    int deliveryTime;
    ref array<string> items;
    ref array<string> attachments; // Lista de anexos para cada item
}

class GiftConfig {
    ref array<ref GiftItem> m_GiftItems;

    void LoadConfig() {
        string jsonPath = "$profile:GiftLetal/gift_config.json";

        if (FileExist(jsonPath)) {
            JsonFileLoader<GiftConfig>.JsonLoadFile(jsonPath, this);
            Print("[Gift] Gift config loaded successfully.");
        } else {
            Print("[Gift] Gift config file not found.");
        }
    }
}

class GiftManager {
    protected ref GiftConfig m_Config;

    void GiftManager() {
        m_Config = new GiftConfig();
        m_Config.LoadConfig();
    }

    void CheckConnectionTime() {
        if (GetGame().IsServer()) {
            PlayerBase player = GetPlayer();

            if (player) {
                int playerConnectionTime = GetPlayerConnectionTime(player);

                foreach (ref GiftItem giftItem : m_Config.m_GiftItems) {
                    if (playerConnectionTime >= giftItem.deliveryTime) {
                        string chosenItem = giftItem.items.GetRandomElement();
                        ref array<string> attachments = giftItem.attachments; // Obtenha a lista de anexos

                        string playerName = player.GetIdentity().GetName(); // Obtém o nome do jogador
                        GetGame().ChatPlayer(0, playerName + " receberá um presente em 10 segundos pelo seu tempo logado.", player); // Mensagem no chat global para o jogador

                        // Espera 10 segundos antes de entregar o presente
                        GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(PerformGiftDelivery, 10000, false, chosenItem, attachments, player);

                        break;
                    }
                }
            }
        }
    }

    void PerformGiftDelivery(string itemName, ref array<string> attachments, PlayerBase player) {
        if (player) {
            vector playerPos = player.GetPosition();
            vector playerDir = player.GetDirection();
            vector dropPos = playerPos + (playerDir * 2);

            EntityAI item = EntityAI.Cast(GetGame().CreateObject(itemName, dropPos));

            // Adiciona os anexos ao item
            foreach (string attachment : attachments) {
                item.GetInventory().CreateAttachment(attachment);
            }

            Print("[Gift] Dropped item " + itemName + " with attachments " + attachments + " in front of player.");
        } else {
            Print("[Gift] Unable to drop item. Player not found.");
        }
    }

    int GetPlayerConnectionTime(PlayerBase player) {
        
        return 120; // Retorna 1 hora (3600 segundos) como exemplo
    }
}

class PluginMain {
    ref GiftManager m_GiftManager;

    void PluginMain() {
        m_GiftManager = new GiftManager();
        GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(m_GiftManager.CheckConnectionTime, 0, true); // Chama a cada tick
    }
}

void main() {
    PluginMain pluginMain;
    pluginMain = new PluginMain();
}

PlayerBase GetPlayer() {
    if (GetGame() && GetGame().GetPlayer()) {
        return PlayerBase.Cast(GetGame().GetPlayer());
    } else {
        return null;
    }
}

 

Actually as I know the gift boxes generated from the cfgrandomptesets.xml (locations for events); cfgspawnabletypes.xml (contents of boxes and chances) and in the types.xml - to not allow em got despawned...

I still can't understand why for it's required the mod...?

Share this post


Link to post
Share on other sites

This mod gives the gift to the player, every x time he remains logged in and drops the item at his position, warning him 10 seconds before

Share this post


Link to post
Share on other sites

and I want to do this to learn a little about scripting in dayz

 

Share this post


Link to post
Share on other sites
1 hour ago, comiekto said:

and I want to do this to learn a little about scripting in dayz

 

Everything what you shall know about scripting for DayZ with Examples is hidden in mods from Steam Workshop and in you game client.

Download DayZ Tools, get to folder: Steam\steamapps\common\DayZ\dta

In that folder theres a file: scripts.pbo -> unpack it with your PBO Manager/tool there you may find the config.bin -> it could be converted to config.cpp (classes definitions for ingame objects), also in subfolders theres other files *.c

Open them up with your prefered notepad/IDE (if you don't have one - DON'T USE WINDOWS NOTEPAD, it's for folks who prefer to shoot own legs).

Those scripts can give the examples and understanding how all of it works and how you can tweak the game or make her more like you wish to see 🙂

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×