init.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "$mission:Scripts/CustomRevivalSuit/config.c"
  2. void main()
  3. {
  4. //INIT ECONOMY--------------------------------------
  5. Hive ce = CreateHive();
  6. if ( ce )
  7. ce.InitOffline();
  8. //DATE RESET AFTER ECONOMY INIT-------------------------
  9. int year, month, day, hour, minute;
  10. int reset_month = 9, reset_day = 20;
  11. GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  12. if ((month == reset_month) && (day < reset_day))
  13. {
  14. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  15. }
  16. else
  17. {
  18. if ((month == reset_month + 1) && (day > reset_day))
  19. {
  20. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  21. }
  22. else
  23. {
  24. if ((month < reset_month) || (month > reset_month + 1))
  25. {
  26. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  27. }
  28. }
  29. }
  30. }
  31. class CustomMission: MissionServer
  32. {
  33. override void OnInit()
  34. {
  35. super.OnInit();
  36. GetCustomRevivalSuitCfg();
  37. if ( g_CustomRevivalSuitCfg )
  38. Print( "[复活套装]: 已加载" );
  39. }
  40. override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
  41. {
  42. Entity playerEnt;
  43. playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
  44. Class.CastTo( m_player, playerEnt );
  45. GetGame().SelectPlayer( identity, m_player );
  46. return m_player;
  47. }
  48. override void StartingEquipSetup( PlayerBase player, bool clothesChosen )
  49. {
  50. GetCustomRevivalSuitCfg();
  51. if ( !player || !player.GetIdentity() ) return;
  52. string steamid = player.GetIdentity().GetPlainId();
  53. ref PlayerRevivalEquipmentData rev = g_CustomRevivalSuitCfg.GetPlayerRevivalEquipmentData( steamid );
  54. if ( rev )
  55. ProcessVIPEquipment( player, rev );
  56. DefaultPlayerEquipment( player, clothesChosen );
  57. }
  58. void ProcessVIPEquipment( PlayerBase player, ref PlayerRevivalEquipmentData equ_data )
  59. {
  60. if ( !equ_data ) return;
  61. player.RemoveAllItems();
  62. ItemBase equipment;
  63. foreach ( string equ : equ_data.Equipments )
  64. player.GetInventory().CreateInInventory( equ );
  65. foreach ( string item : equ_data.ItemList )
  66. player.GetInventory().CreateInInventory( item );
  67. if ( !equ_data.WeaponData || equ_data.WeaponData.WeaponName == "" ) return;
  68. Weapon_Base weapon = Weapon_Base.Cast( player.GetInventory().CreateInInventory( equ_data.WeaponData.WeaponName ) );
  69. if ( !weapon ) return
  70. foreach ( string attachment : equ_data.WeaponData.WeaponComponents )
  71. {
  72. if ( String( attachment ).ToType().IsInherited( Magazine ) )
  73. {
  74. Magazine wpn_mag = weapon.SpawnAttachedMagazine( attachment );
  75. if ( wpn_mag )
  76. wpn_mag.SetSynchDirty();
  77. continue;
  78. }
  79. if ( weapon.GetInventory() )
  80. ItemBase.Cast( weapon.GetInventory().CreateInInventory( attachment ) );
  81. }
  82. }
  83. void SetRandomHealth(EntityAI itemEnt)
  84. {
  85. if (itemEnt)
  86. {
  87. float rndHlt = Math.RandomFloat( 0.50, 0.85 );
  88. itemEnt.SetHealth01( "", "", rndHlt );
  89. }
  90. }
  91. void DefaultPlayerEquipment( PlayerBase player, bool clothesChosen )
  92. {
  93. EntityAI itemClothing;
  94. EntityAI itemEnt;
  95. ItemBase itemBs;
  96. float rand;
  97. itemClothing = player.FindAttachmentBySlotName( "Body" );
  98. if ( itemClothing )
  99. {
  100. SetRandomHealth( itemClothing );
  101. itemEnt = itemClothing.GetInventory().CreateInInventory( "BandageDressing" );
  102. if ( Class.CastTo( itemBs, itemEnt ) )
  103. itemBs.SetQuantity( 2 );
  104. string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  105. int rndIndex = Math.RandomInt( 0, 4 );
  106. itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
  107. SetRandomHealth( itemEnt );
  108. ItemBase itemTop;
  109. rand = Math.RandomFloatInclusive( 0.0, 1.0 );
  110. if ( rand < 0.35 )
  111. {
  112. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  113. itemTop = ItemBase.Cast( itemEnt );
  114. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  115. itemTop.SetCleanness(1);
  116. }
  117. else if ( rand > 0.65 )
  118. {
  119. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  120. itemTop = ItemBase.Cast( itemEnt );
  121. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  122. itemTop.SetCleanness(1);
  123. }
  124. else
  125. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  126. // SetRandomHealth( itemEnt );
  127. }
  128. itemClothing = player.FindAttachmentBySlotName( "Legs" );
  129. if ( itemClothing )
  130. SetRandomHealth( itemClothing );
  131. itemClothing = player.FindAttachmentBySlotName( "Feet" );
  132. }
  133. };
  134. Mission CreateCustomMission(string path)
  135. {
  136. return new CustomMission();
  137. }