Files
DayZScripts/Mod/RespawnEqument/init.c
Dcrclub d2632d04d4 refactor(RespawnEquipment): 添加isVIP参数以区分普通玩家和VIP玩家
在DefaultPlayerEquipment方法中添加isVIP参数,用于区分普通玩家和VIP玩家的装备处理逻辑。普通玩家的装备创建逻辑暂时留空,待后续实现。
2025-04-21 20:58:47 +08:00

176 lines
5.8 KiB
C

#include "$mission:Scripts/CustomRevivalSuit/config.c"
void main()
{
//INIT ECONOMY--------------------------------------
Hive ce = CreateHive();
if ( ce )
ce.InitOffline();
//DATE RESET AFTER ECONOMY INIT-------------------------
int year, month, day, hour, minute;
int reset_month = 9, reset_day = 20;
GetGame().GetWorld().GetDate(year, month, day, hour, minute);
if ((month == reset_month) && (day < reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month == reset_month + 1) && (day > reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month < reset_month) || (month > reset_month + 1))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
}
}
}
class CustomMission: MissionServer
{
override void OnInit()
{
super.OnInit();
GetCustomRevivalSuitCfg();
if ( g_CustomRevivalSuitCfg )
Print( "[复活套装]: 已加载" );
}
override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
{
Entity playerEnt;
playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
Class.CastTo( m_player, playerEnt );
GetGame().SelectPlayer( identity, m_player );
return m_player;
}
override void StartingEquipSetup( PlayerBase player, bool clothesChosen )
{
GetCustomRevivalSuitCfg();
if ( !player || !player.GetIdentity() ) return;
string steamid = player.GetIdentity().GetPlainId();
ref PlayerRevivalEquipmentData rev = g_CustomRevivalSuitCfg.GetPlayerRevivalEquipmentData( steamid );
bool isVIP = false;
if ( rev )
{
isVIP = true;
ProcessVIPEquipment( player, rev );
}
DefaultPlayerEquipment( player, clothesChosen, isVIP );
}
void ProcessVIPEquipment( PlayerBase player, ref PlayerRevivalEquipmentData equ_data )
{
if ( !equ_data ) return;
player.RemoveAllItems();
ItemBase equipment;
foreach ( string equ : equ_data.Equipments )
player.GetInventory().CreateInInventory( equ );
foreach ( string item : equ_data.ItemList )
player.GetInventory().CreateInInventory( item );
if ( !equ_data.WeaponData || equ_data.WeaponData.WeaponName == "" ) return;
Weapon_Base weapon = Weapon_Base.Cast( player.GetInventory().CreateInInventory( equ_data.WeaponData.WeaponName ) );
if ( !weapon ) return
foreach ( string attachment : equ_data.WeaponData.WeaponComponents )
{
if ( String( attachment ).ToType().IsInherited( Magazine ) )
{
Magazine wpn_mag = weapon.SpawnAttachedMagazine( attachment );
if ( wpn_mag )
wpn_mag.SetSynchDirty();
continue;
}
if ( weapon.GetInventory() )
ItemBase.Cast( weapon.GetInventory().CreateInInventory( attachment ) );
}
}
void SetRandomHealth(EntityAI itemEnt)
{
if (itemEnt)
{
float rndHlt = Math.RandomFloat( 0.50, 0.85 );
itemEnt.SetHealth01( "", "", rndHlt );
}
}
void DefaultPlayerEquipment( PlayerBase player, bool clothesChosen, bool isVIP )
{
EntityAI itemClothing;
EntityAI itemEnt;
ItemBase itemBs;
float rand;
if ( !isVIP )
{
// TODO: 这里给普通玩家创建装备. 以前在StartingEquipSetup中如何给玩家创建新的装备这里就如何写
// player.RemoveAllItems(); // 移除所有默认装备
// itemEnt = player.GetInventory().CreateInInventory( "" /*这里写服装代码 */ );
}
itemClothing = player.FindAttachmentBySlotName( "Body" );
if ( itemClothing )
{
SetRandomHealth( itemClothing );
itemEnt = itemClothing.GetInventory().CreateInInventory( "BandageDressing" );
if ( Class.CastTo( itemBs, itemEnt ) )
itemBs.SetQuantity( 2 );
string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
int rndIndex = Math.RandomInt( 0, 4 );
itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
SetRandomHealth( itemEnt );
ItemBase itemTop;
rand = Math.RandomFloatInclusive( 0.0, 1.0 );
if ( rand < 0.35 )
{
itemEnt = player.GetInventory().CreateInInventory( "Rag" );
itemTop = ItemBase.Cast( itemEnt );
itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
itemTop.SetCleanness(1);
}
else if ( rand > 0.65 )
{
itemEnt = player.GetInventory().CreateInInventory( "Rag" );
itemTop = ItemBase.Cast( itemEnt );
itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
itemTop.SetCleanness(1);
}
else
itemEnt = player.GetInventory().CreateInInventory( "Rag" );
// SetRandomHealth( itemEnt );
}
itemClothing = player.FindAttachmentBySlotName( "Legs" );
if ( itemClothing )
SetRandomHealth( itemClothing );
itemClothing = player.FindAttachmentBySlotName( "Feet" );
}
};
Mission CreateCustomMission(string path)
{
return new CustomMission();
}