HasterPaster

Delete all occurrences of an object on the server

Jun 13th, 2021 (edited)
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.52 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.     //Delete all occurrences of an object on the server - Start
  42.     int isActiveDeleteObjects = 1;
  43.     string deleteObjectName = "GardenPlot";
  44.  
  45.     if (isActiveDeleteObjects == 1)
  46.     {
  47.         array<Object> objects = new array<Object>;
  48.         GetGame().GetObjectsAtPosition("7500 0 7500", 10000, objects, null);
  49.  
  50.         foreach(Object obj: objects)
  51.         {
  52.             if ( obj.GetType() == deleteObjectName )
  53.             {
  54.                 GetGame().ObjectDelete( obj );
  55.             }
  56.         }
  57.     }
  58.     //Delete all occurrences of an object on the server - End
  59. }
  60.  
  61. class CustomMission: MissionServer
  62. {
  63.     void SetRandomHealth(EntityAI itemEnt)
  64.     {
  65.         if ( itemEnt )
  66.         {
  67.             float rndHlt = Math.RandomFloat( 0.45, 0.65 );
  68.             itemEnt.SetHealth01( "", "", rndHlt );
  69.         }
  70.     }
  71.  
  72.     override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
  73.     {
  74.         Entity playerEnt;
  75.         playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
  76.         Class.CastTo( m_player, playerEnt );
  77.  
  78.         GetGame().SelectPlayer( identity, m_player );
  79.  
  80.         return m_player;
  81.     }
  82.  
  83.     override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
  84.     {
  85.         EntityAI itemClothing;
  86.         EntityAI itemEnt;
  87.         ItemBase itemBs;
  88.         float rand;
  89.  
  90.         itemClothing = player.FindAttachmentBySlotName( "Body" );
  91.         if ( itemClothing )
  92.         {
  93.             SetRandomHealth( itemClothing );
  94.            
  95.             itemEnt = itemClothing.GetInventory().CreateInInventory( "Rag" );
  96.             if ( Class.CastTo( itemBs, itemEnt ) )
  97.                 itemBs.SetQuantity( 4 );
  98.  
  99.             SetRandomHealth( itemEnt );
  100.  
  101.             string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  102.             int rndIndex = Math.RandomInt( 0, 4 );
  103.             itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
  104.             SetRandomHealth( itemEnt );
  105.  
  106.             rand = Math.RandomFloatInclusive( 0.0, 1.0 );
  107.             if ( rand < 0.35 )
  108.                 itemEnt = player.GetInventory().CreateInInventory( "Apple" );
  109.             else if ( rand > 0.65 )
  110.                 itemEnt = player.GetInventory().CreateInInventory( "Pear" );
  111.             else
  112.                 itemEnt = player.GetInventory().CreateInInventory( "Plum" );
  113.  
  114.             SetRandomHealth( itemEnt );
  115.         }
  116.        
  117.         itemClothing = player.FindAttachmentBySlotName( "Legs" );
  118.         if ( itemClothing )
  119.             SetRandomHealth( itemClothing );
  120.        
  121.         itemClothing = player.FindAttachmentBySlotName( "Feet" );
  122.     }
  123. };
  124.  
  125. Mission CreateCustomMission(string path)
  126. {
  127.     return new CustomMission();
  128. }
Add Comment
Please, Sign In to add comment