HasterPaster

God mode for X minutes when spawning in DayZ #2

Jan 8th, 2021
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.71 KB | None | 0 0
  1. void main()
  2. {
  3.     //INIT WEATHER BEFORE ECONOMY INIT------------------------
  4.     Weather weather = g_Game.GetWeather();
  5.  
  6.     weather.MissionWeather(false);    // false = use weather controller from Weather.c
  7.  
  8.     weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
  9.     weather.GetRain().Set( 0, 0, 1);
  10.     weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);
  11.  
  12.     //INIT ECONOMY--------------------------------------
  13.     Hive ce = CreateHive();
  14.     if ( ce )
  15.         ce.InitOffline();
  16.  
  17.     //DATE RESET AFTER ECONOMY INIT-------------------------
  18.     int year, month, day, hour, minute;
  19.     int reset_month = 9, reset_day = 20;
  20.     GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  21.  
  22.     if ((month == reset_month) && (day < reset_day))
  23.     {
  24.         GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  25.     }
  26.     else
  27.     {
  28.         if ((month == reset_month + 1) && (day > reset_day))
  29.         {
  30.             GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  31.         }
  32.         else
  33.         {
  34.             if ((month < reset_month) || (month > reset_month + 1))
  35.             {
  36.                 GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. class CustomMission: MissionServer
  43. {
  44.     void SetRandomHealth(EntityAI itemEnt)
  45.     {
  46.         if ( itemEnt )
  47.         {
  48.             float rndHlt = Math.RandomFloat( 0.45, 0.65 );
  49.             itemEnt.SetHealth01( "", "", rndHlt );
  50.         }
  51.     }
  52.  
  53.     override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
  54.     {
  55.         Entity playerEnt;
  56.         playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
  57.         Class.CastTo( m_player, playerEnt );
  58.  
  59.         GetGame().SelectPlayer( identity, m_player );
  60.  
  61.         return m_player;
  62.     }
  63.  
  64.     override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
  65.     {
  66.         EntityAI itemClothing;
  67.         EntityAI itemEnt;
  68.         ItemBase itemBs;
  69.         float rand;
  70.  
  71.         itemClothing = player.FindAttachmentBySlotName( "Body" );
  72.         if ( itemClothing )
  73.         {
  74.             SetRandomHealth( itemClothing );
  75.            
  76.             itemEnt = itemClothing.GetInventory().CreateInInventory( "Rag" );
  77.             if ( Class.CastTo( itemBs, itemEnt ) )
  78.                 itemBs.SetQuantity( 4 );
  79.  
  80.             SetRandomHealth( itemEnt );
  81.  
  82.             string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  83.             int rndIndex = Math.RandomInt( 0, 4 );
  84.             itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
  85.             SetRandomHealth( itemEnt );
  86.  
  87.             rand = Math.RandomFloatInclusive( 0.0, 1.0 );
  88.             if ( rand < 0.35 )
  89.                 itemEnt = player.GetInventory().CreateInInventory( "Apple" );
  90.             else if ( rand > 0.65 )
  91.                 itemEnt = player.GetInventory().CreateInInventory( "Pear" );
  92.             else
  93.                 itemEnt = player.GetInventory().CreateInInventory( "Plum" );
  94.  
  95.             SetRandomHealth( itemEnt );
  96.         }
  97.        
  98.         itemClothing = player.FindAttachmentBySlotName( "Legs" );
  99.         if ( itemClothing )
  100.             SetRandomHealth( itemClothing );
  101.        
  102.         itemClothing = player.FindAttachmentBySlotName( "Feet" );
  103.     }
  104.  
  105.     // Code for god mode upon spawning starts here. Only paste this code into init.c
  106.     override void InvokeOnConnect(PlayerBase player, PlayerIdentity identity)
  107.     {
  108.         super.InvokeOnConnect(player, identity);
  109.         player.SetAllowDamage(false);
  110.  
  111.         // Set in minutes for how long you want the player to have god mode upon spawning into the game. Don't edit anything else unless you know what you are doing.
  112.         int godModeTimer = 1;
  113.        
  114.         // Convert to milliseconds.
  115.         int godModeTimerMS = godModeTimer * 60000;
  116.        
  117.         // Call the method for removing god mode after "godModeTimerMS" milliseconds.
  118.         GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(RemoveGodMode, godModeTimerMS, false, player);
  119.        
  120.         // First warning message: 30 seconds
  121.         int warningTime = godModeTimerMS - 30000;
  122.         string message = "Your god mode will be removed in 30 seconds.";
  123.         GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DisplayMessage, warningTime, false, player, message);
  124.        
  125.         // Second warning message: 10 seconds
  126.         warningTime = godModeTimerMS - 10000;
  127.         message = "Your god mode will be removed in 10 seconds.";
  128.         GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DisplayMessage, warningTime, false, player, message);     
  129.     }
  130.    
  131.     void RemoveGodMode(PlayerBase player)
  132.     {
  133.         player.SetAllowDamage(true);
  134.         DisplayMessage(player, "Your god mode has been removed.");
  135.     }
  136.    
  137.     void DisplayMessage(PlayerBase player, string message)
  138.     {
  139.         Param1<string> m_MessageParam = new Param1<string>(message);
  140.         GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, m_MessageParam, true, player.GetIdentity());
  141.     }
  142.     // Code for god mode upon spawning ends here. Don't paste anything else into init.c. 
  143. };
  144.  
  145. Mission CreateCustomMission(string path)
  146. {
  147.     return new CustomMission();
  148. }
Advertisement
Add Comment
Please, Sign In to add comment