HasterPaster

Specific player(s) spawn at specific coordinates in DayZ

Aug 12th, 2020 (edited)
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.33 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.             int rndHlt = Math.RandomInt(55,100);
  49.             itemEnt.SetHealth("","",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");//Creates random player
  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 itemTop;
  67.         EntityAI itemEnt;
  68.         ItemBase itemBs;
  69.         float rand;
  70.  
  71.         itemTop = player.FindAttachmentBySlotName("Body");
  72.  
  73.         if ( itemTop )
  74.         {
  75.             itemEnt = itemTop.GetInventory().CreateInInventory("Rag");
  76.             if ( Class.CastTo(itemBs, itemEnt ) )
  77.                 itemBs.SetQuantity(4);
  78.  
  79.             SetRandomHealth(itemEnt);
  80.  
  81.             string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  82.             int rndIndex = Math.RandomInt(0, 4);
  83.             itemEnt = itemTop.GetInventory().CreateInInventory(chemlightArray[rndIndex]);
  84.             SetRandomHealth(itemEnt);
  85.  
  86.             rand = Math.RandomFloatInclusive(0.0, 1.0);
  87.             if ( rand < 0.35 )
  88.                 itemEnt = player.GetInventory().CreateInInventory("Apple");
  89.             else if ( rand > 0.65 )
  90.                 itemEnt = player.GetInventory().CreateInInventory("Pear");
  91.             else
  92.                 itemEnt = player.GetInventory().CreateInInventory("Plum");
  93.  
  94.             SetRandomHealth(itemEnt);
  95.         }
  96.        
  97.         ///////////////////////////////////////////////////////////////////////////////////////////////////////
  98.         //    Player(s) with a specific SteamID or BI-UID will spawn at a set location. Code starts here.    //
  99.         ///////////////////////////////////////////////////////////////////////////////////////////////////////
  100.        
  101.         // Define the X and Z coordinates below where the player(s) will spawn when they respawn.
  102.         float xCoordinate = 7500;
  103.         float zCoordinate = 7500;
  104.        
  105.         // Enter the SteamID or the BI-UID for the player(s) you want to spawn at the above coordinates.
  106.         // Separate with a comma if you have more than one player.
  107.         ref TStringArray spawnPlayers = {"76561198000000001", "76561198000000002", "76561198000000003"};
  108.  
  109.         // Check if the current player is on the above list. If so, make him/her spawn at the specified coordinates.
  110.         // You don't need to edit anything here.
  111.         for (int i = 0; i < spawnPlayers.Count(); ++i )
  112.         {
  113.             if(player.GetIdentity().GetId() == spawnPlayers[i] || player.GetIdentity().GetPlainId() == spawnPlayers[i])
  114.             {
  115.                 float yCoordinate = GetGame().SurfaceY(xCoordinate, zCoordinate);
  116.                 vector spawnCoordinates = Vector(xCoordinate, yCoordinate, zCoordinate);
  117.                 player.SetPosition(spawnCoordinates);
  118.                
  119.                 break;
  120.             }
  121.         }
  122.         /////////////////////////////////////////////////////////////////////////////////////////////////////
  123.         //    Player(s) with a specific SteamID or BI-UID will spawn at a set location. Code ends here.    //
  124.         /////////////////////////////////////////////////////////////////////////////////////////////////////
  125.     }
  126. };
  127.  
  128. Mission CreateCustomMission(string path)
  129. {
  130.     return new CustomMission();
  131. }
Add Comment
Please, Sign In to add comment