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;
}
}