HasterPaster

God mode for X minutes when spawning in DayZ

Jan 8th, 2021
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.49 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.         int godModeTimerMS = godModeTimer * 60000;
  115.        
  116.         string message = "You now have god mode for " + godModeTimer + " minutes.";
  117.         GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DisplayMessage, 10000, false, player, message);
  118.        
  119.         GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(RemoveGodMode, godModeTimerMS, false, player);
  120.        
  121.         int warningTime = godModeTimerMS - 10000;
  122.         message = "Your god mode will be removed in 10 seconds.";
  123.         GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(DisplayMessage, warningTime, false, player, message);
  124.     }
  125.    
  126.     void RemoveGodMode(PlayerBase player)
  127.     {
  128.         player.SetAllowDamage(true);
  129.         DisplayMessage(player, "Your god mode has been removed.");
  130.     }
  131.    
  132.     void DisplayMessage(PlayerBase player, string message)
  133.     {
  134.         Param1<string> m_MessageParam = new Param1<string>(message);
  135.         GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, m_MessageParam, true, player.GetIdentity());
  136.     }
  137.     // Code for god mode upon spawning ends here. Don't paste anything else into init.c. 
  138. };
  139.  
  140. Mission CreateCustomMission(string path)
  141. {
  142.     return new CustomMission();
  143. }
Advertisement
Add Comment
Please, Sign In to add comment