Dosyalar
DayZScripts/Mod/RespawnEqument/init.c
T

200 satır
7.5 KiB
C

#include "$mission:Scripts/CustomRevivalSuit/config.c"
void main()
{
Hive ce = CreateHive();
if ( ce )
ce.InitOffline();
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( "[复活套装]: 已加载" );
}
//------------------------------------------------------------------
// 创建角色方法:在玩家首次加入或重生时调用
// 参数:
// identity - 玩家身份信息
// pos - 出生位置
// ctx - 上下文参数
// characterName - 角色名称
// 返回:PlayerBase - 创建的角色对象
//------------------------------------------------------------------
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;
}
//------------------------------------------------------------------
// 初始装备设置方法:在玩家重生时调用
// 功能:根据玩家身份加载VIP装备,并设置默认装备, 如果玩家不是VIP,则使用
// 默认的系统装备, 注意如果你要添加非VIP玩家的装备,
// 请在 DefaultPlayerEquipment 方法中添加.
// 参数:
// player - 玩家对象
// clothesChosen - 是否已选择服装
//------------------------------------------------------------------
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 );
if ( rev )
ProcessVIPEquipment( player, rev );
DefaultPlayerEquipment( player, clothesChosen );
}
//------------------------------------------------------------------
// 处理VIP装备方法:为VIP玩家设置自定义装备
// 参数:
// player - 玩家对象
// equ_data - VIP装备数据
// VIP玩家的出生装备处理方法, 这里根据josn配置的来生成, 不懂,请勿改动
//------------------------------------------------------------------
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 ) );
}
}
//------------------------------------------------------------------
// 设置随机健康值方法:为物品设置随机的健康值
// 参数:
// itemEnt - 物品实体
//------------------------------------------------------------------
void SetRandomHealth(EntityAI itemEnt)
{
if (itemEnt)
{
float rndHlt = Math.RandomFloat( 0.50, 0.85 );
itemEnt.SetHealth01( "", "", rndHlt );
}
}
//------------------------------------------------------------------
// 默认装备设置方法:为玩家设置默认的初始装备
// 参数:
// player - 玩家对象
// clothesChosen - 是否已选择服装
// 这里的代码是原版init.c中 StartingEquipSetup 方法中的内容, 只是换了个方法名字
//------------------------------------------------------------------
void DefaultPlayerEquipment( PlayerBase player, bool clothesChosen )
{
EntityAI itemClothing;
EntityAI itemEnt;
ItemBase itemBs;
float rand;
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();
}