Hallo zusammen,
ich bin an der Erstellung einer Mod die Crafting Rezepte darstellt. Dies ermöglicht eine individuelle Erstellung von Rezepten via json im config Ordner.
Die Funktion ist so weit gegeben, das "Buch" öffnet sich über die Tasteneingabe und lässt sich ebenso wieder über eine erneute Tasteneingabe schließen.
Der Grundaufbau basiert auf der anderen Mod "Crafting-Werkbank" die ebenso ein UI Menü nutzt und auch genutzt wird.
Problembeschreibung:
- Der neue Mod "Crafting-Buch" verhindert, dass die "Crafting-Werkbank" Mod das UI layout komplett laden und ausführen kann, sowie alle Funktionen gehen.
- Das UI Menü der "Crafting-Werkbank" verschwindet nicht mehr nach der Bedienung der Abbruch Taste.
Falls mir hierbei jemand helfen könnte wäre das wirklich super.
PBO´s kann ich hier aus meinem aktuellen Kenntnisstand nicht hochladen, jedoch wenn sich hier jemand auskennt kann ich die nötigen Codes auch hier teilen.
Lg Kame
Gerne auch via Discord.
Hier ggf. ein Einblick der den möglichen Konflikt (meiner Meinung nach) zeigen könnte.
////////////////////////////////////////////////////////////
Mod NEU
////////////////////////////////////////////////////////////
modded class PlayerBase
{
ref CIBCraftClasses m_CIBCraftClasses;
override void OnRPC(PlayerIdentity sender, int CIBrpc_type, ParamsReadContext ctx)
{
super.OnRPC(sender, rpc_type, ctx);
if (GetGame().IsClient() !GetGame().IsMultiplayer())
{
if (rpc_type == CIBc.SERVER_SEND_MAIN_DATA_CIB)
{ApplyServerData(ctx);}
else if (rpc_type == CIBc.SERVER_SEND_CLOSE_MENU_CIB)
{g_CIBManager.CIBClose();}
}
}
void ApplyServerData(ParamsReadContext ctx)
{
Param1<ref CIBCraftClasses> CIBrpb;
if (!ctx.Read(CIBrpb)) return;
m_CIBCraftClasses = CIBrpb.param1;
}
override void Init()
{
if ( !GetGame().IsServer() ||!GetGame().IsMultiplayer() )
{
if ( g_CIBServerManager && g_CIBServerManager.m_CIBCraftClasses )
{
m_CIBCraftClasses = g_CIBServerManager.m_CIBCraftClasses;
}
}
super.Init();
}
}
Alles anzeigen
modded class MissionGameplay
{
override void OnInit()
{
super.OnInit();
g_CIBManager = new CIBManager();
}
override void OnKeyPress( int key )
{
super.OnKeyPress( key );
g_CIBManager.HandleKeyPress( key );
}
}
Alles anzeigen
class CIBManager
{
ref CIBCraftHud m_CIBCraftHud;
ref array<EntityAI> m_CIBAllItems;
ref map<string,int> m_CIBExItems;
void CIBManager()
{
m_CIBExItems = new map<string, int>();
m_CIBAllItems = new array<EntityAI>();
}
void HandleKeyPress( int key )
{
switch (key)
{
case KeyCode.KC_ESCAPE:
CIBClose();
break;
case KeyCode.KC_J:
CIBRequest();
break;
}
}
void CIBRequest()
{
if (m_CIBCraftHud GetGame().GetUIManager().GetMenu()) return;
m_CIBCraftHud = new CIBCraftHud();
GetGame().GetUIManager().ShowScriptedMenu( m_CIBCraftHud, NULL );
}
void CIBClose()
{
if ( GetGame().GetUIManager().GetMenu() && m_CIBCraftHud)
{
GetGame().GetUIManager().Back();
}
}
}
ref CIBManager g_CIBManager;
Alles anzeigen
////////////////////////////////////////////////////////////
Mod ALT
////////////////////////////////////////////////////////////
modded class PlayerBase
{
ref CraftClasses m_CraftClasses;
ref array<EntityAI> CargoItems;
ref map<string, int> DeletItems;
ItemBase m_Workbench;
int NumberOfItemsInvolved;
float RewardHealth;
bool CanCraft;
void PlayerBase()
{
CargoItems = new array<EntityAI>();
DeletItems = new map<string, int>();
CanCraft = true;
}
bool CanCraft()
{
return CanCraft;
}
void SetCraftDelay()
{
CanCraft = false;
GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( AllowCraft, 2000, false);
}
void AllowCraft()
{
CanCraft = true;
}
override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
{
super.OnRPC(sender, rpc_type, ctx);
if (GetGame().IsClient() !GetGame().IsMultiplayer())
{
if (rpc_type == CRPc.SERVER_SEND_MAIN_DATA)
{ApplyServerData(ctx);}
else if (rpc_type == CRPc.SERVER_SEND_CLOSE_MENU)
{g_CraftManager.CloseCraft();}
}
if (GetGame().IsServer() !GetGame().IsMultiplayer())
{
if (rpc_type == CRPc.CLIENT_REQUEST_CRAFT_ITEMS)
CraftItems(ctx);
}
}
void ApplyServerData(ParamsReadContext ctx)
{
Param1<ref CraftClasses> rpb;
if (!ctx.Read(rpb)) return;
m_CraftClasses = rpb.param1;
}
void CraftItems(ParamsReadContext ctx)
{
RewardHealth = 0.0;
NumberOfItemsInvolved = 0;
Param2<CraftItem, ItemBase> rpb;
if (!ctx.Read(rpb)) return;
m_Workbench = rpb.param2;
if ( !GetGame().IsMultiplayer() )
{
m_Workbench = g_CraftManager.GetWB();
}
Print(m_Workbench);
if (!ScanItems(rpb.param1)) return;
DeleteIngredients(rpb.param1, rpb.param2);
}
void DeleteIngredients(CraftItem arr, ItemBase work)
{
CraftItem crtItems = arr;
ItemBase workbench = work;
ItemBase cargoItemIB;
CargoBase cargoBase;
int cargoCount;
cargoBase = workbench.GetInventory().GetCargo();
cargoCount = cargoBase.GetItemCount();
for (int k = 0; k < cargoCount; k++)
{
EntityAI crgEnt = cargoBase.GetItem(k);
if (crgEnt && (!crgEnt.IsRuined() crgEnt.IsWeapon()))
{
CargoItems.Insert(crgEnt);
}
}
for (int i = 0; i < crtItems.CraftComponents.Count(); i++)
{
CraftComponent cc = crtItems.CraftComponents.Get(i);
cargoItemIB = ItemBase.Cast(GetGame().CreateObject(cc.Classname, vector.Zero, false));
if (cargoItemIB)
{
if ((QuantityConversions.HasItemQuantity(cargoItemIB) == 0) cargoItemIB.IsInherited(Magazine))
{
ItemWithoutQuantity(cc);
}
else
{
ItemWithCount(cc, workbench);
}
GetGame().ObjectDelete(cargoItemIB);
}
}
CargoItems.Clear();
DeletItems.Clear();
GiveResults(arr);
}
void GiveResults(CraftItem itemData)
{
CraftItem cragtItem = itemData;
ItemBase itemReward;
ItemBase tempIB;
Magazine pileReward;
string resultType;
float needQuantity;
float q_cur, q_min, q_max;
resultType = cragtItem.Result;
needQuantity = cragtItem.ResultCount;
tempIB = ItemBase.Cast(GetGame().CreateObject(resultType, vector.Zero, false));
if (!tempIB)
return;
QuantityConversions.GetItemQuantity(tempIB, q_cur, q_min, q_max);
tempIB.Delete();
if (!q_max) q_max = 1;
while (needQuantity)
{
if (q_max < needQuantity)
{
itemReward = ItemBase.Cast(GetGame().CreateObject(resultType, this.GetPosition(), false));
needQuantity -= q_max;
}
else
{
itemReward = ItemBase.Cast(GetGame().CreateObject(resultType, this.GetPosition(), false));
if (Class.CastTo(pileReward, itemReward))
{
pileReward.ServerSetAmmoCount(needQuantity);
}
else
{
itemReward.SetQuantity(needQuantity);
}
needQuantity = 0;
}
}
if (itemData.ComponentsDontAffectHealth == 0 && NumberOfItemsInvolved > 0)
{
RewardHealth = RewardHealth / NumberOfItemsInvolved;
//itemReward.SetHealth01("","",RewardHealth);
}
}
void ItemWithoutQuantity(CraftComponent cc)
{
int amount = cc.Amount;
string name = cc.Classname;
int count = CargoItems.Count();
for (int i = 0; i < count; i++)
{
EntityAI ent = CargoItems.Get(i);
if (ent && (ent.GetType() == name))
{
ItemBase item = ItemBase.Cast(ent);
if (item)
{
RewardHealth = RewardHealth + item.GetHealth01();
NumberOfItemsInvolved = NumberOfItemsInvolved + 1;
if (cc.Destroy)
GetGame().ObjectDelete(item);
else
item.AddHealth(cc.Changehealth);
amount--;
if (!amount) break;
}
}
}
}
void ItemWithCount(CraftComponent cc, ItemBase workbench)
{
int amount = cc.Amount;
string name = cc.Classname;
int count = CargoItems.Count();
for (int i = 0; i < count; i++)
{
EntityAI ent = CargoItems.Get(i);
if (ent && (ent.GetType() == name))
{
ItemBase item = ItemBase.Cast(ent);
if (item)
{
RewardHealth = RewardHealth + item.GetHealth01();
NumberOfItemsInvolved = NumberOfItemsInvolved + 1;
if (cc.Destroy)
{
if (item.GetQuantity() > amount)
{
item.AddQuantity(-amount);
break;
}
else
{
amount -= item.GetQuantity();
GetGame().ObjectDelete(item);
}
}
else
{
if (item.GetQuantity() > amount)
{
item.AddQuantity(-amount);
ItemBase tempItm = ItemBase.Cast(workbench.GetInventory().CreateInInventory(item.GetType()));
if (!tempItm)
tempItm = ItemBase.Cast(GetGame().CreateObject(item.GetType(), workbench.GetPosition(), false));
tempItm.SetQuantity(amount);
tempItm.AddHealth(cc.Changehealth);
break;
}
else
{
amount -= item.GetQuantity();
item.AddHealth(cc.Changehealth);
}
}
}
}
}
}
bool ScanItems(CraftItem arr)
{
if (!m_Workbench)
{
return false;
}
if (!m_Workbench.HasAnyCargo())
{
return false;
}
CargoBase cargoBase;
int cargoCount;
int quant;
cargoBase = m_Workbench.GetInventory().GetCargo();
cargoCount = cargoBase.GetItemCount();
for (int c = 0; c < cargoCount; c++)
{
ItemBase cargoItemIB;
if ( Class.CastTo(cargoItemIB, cargoBase.GetItem(c)) && cargoItemIB.IsItemBase() )
{
if (cargoItemIB.IsRuined()) continue;
if (cargoItemIB.HasQuantity())
{
quant = cargoItemIB.GetQuantity();
}
else
{
quant = 1;
}
if (!DeletItems.Contains(cargoItemIB.GetType()))
{
DeletItems.Insert(cargoItemIB.GetType(), quant);
}
else
{
int nowQuant = DeletItems.Get(cargoItemIB.GetType());
DeletItems.Set(cargoItemIB.GetType(), (nowQuant + quant));
}
}
}
for (int i = 0; i < arr.CraftComponents.Count(); i++)
{
CraftComponent cc = arr.CraftComponents.Get(i);
int count = DeletItems.Get(cc.Classname);
if ( count < cc.Amount )
{return false;}
}
DeletItems.Clear();
return true;
}
override void Init()
{
if ( !GetGame().IsServer() ||!GetGame().IsMultiplayer() )
{
if ( g_CraftServerManager && g_CraftServerManager.m_CraftClasses )
{
m_CraftClasses = g_CraftServerManager.m_CraftClasses;
}
}
super.Init();
}
}
Alles anzeigen
modded class MissionGameplay
{
override void OnInit()
{
super.OnInit();
g_CraftManager = new CraftManager();
}
override void OnKeyPress( int key )
{
super.OnKeyPress( key );
g_CraftManager.OnKeyPress( key );
}
}
Alles anzeigen
class CraftManager
{
ref CraftHud m_CraftHud;
ref array m_AllItems;
SCZWorkbench m_Workbench;
ref map m_ExItems;
void CraftManager()
{
m_ExItems = new map();
m_AllItems = new array();
}
void SetWorkbench(SCZWorkbench wb)
{
m_Workbench = wb;
}
SCZWorkbench GetWB()
{
return m_Workbench;
}
void OnKeyPress( int key )
{
switch (key)
{
case KeyCode.KC_ESCAPE:
CloseCraft();
break;
}
}
void RequestCraft()
{
if (m_CraftHud GetGame().GetUIManager().GetMenu()) return;
m_CraftHud = new CraftHud();
GetGame().GetUIManager().ShowScriptedMenu( m_CraftHud, NULL );
}
void CloseCraft()
{
if ( GetGame().GetUIManager().GetMenu() && m_CraftHud)
{
GetGame().GetUIManager().Back();
GetWB().RPCSingleParam(CRPc.CLIENT_REQUEST_FREE_WB, new Param1(GetWB()), true, null);
SetWorkbench(null);
}
}
static void SelfChatMessage( string message )
{
GetGame().GetMission().OnEvent(ChatMessageEventTypeID, new ChatMessageEventParams(0, "", message, ""));
}
void DeleteEntities()
{
for (int i = 0; i < m_AllItems.Count(); i++)
{
if (m_AllItems.Get(i))
GetGame().ObjectDeleteOnClient(m_AllItems.Get(i));
}
m_AllItems.Clear();
}
}
ref CraftManager g_CraftManager;
Alles anzeigen