Advertisement
iKurdo

init.c plus

Feb 3rd, 2023 (edited)
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.59 KB | Gaming | 0 0
  1. static void SpawnObject(string type, vector position, vector orientation)
  2. {
  3.     auto obj = GetGame().CreateObjectEx(type, position, ECE_SETUP | ECE_UPDATEPATHGRAPH | ECE_CREATEPHYSICS);
  4.     obj.SetPosition(position);
  5.     obj.SetOrientation(orientation);
  6.     obj.SetOrientation(obj.GetOrientation());
  7.     obj.SetFlags(EntityFlags.STATIC, false);
  8.     obj.Update();
  9.     obj.SetAffectPathgraph(true, false);
  10.     if (obj.CanAffectPathgraph()) GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(GetGame().UpdatePathgraphRegionByObject, 100, false, obj);
  11. }
  12. void main()
  13. {
  14.     //INIT WEATHER BEFORE ECONOMY INIT------------------------
  15.     Weather weather = g_Game.GetWeather();
  16.  
  17.     weather.MissionWeather(false);    // false = use weather controller from Weather.c
  18.  
  19.     weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
  20.     weather.GetRain().Set( 0, 0, 1);
  21.     weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);
  22.  
  23.     //INIT ECONOMY--------------------------------------
  24.     Hive ce = CreateHive();
  25.     if ( ce )
  26.         ce.InitOffline();
  27.  
  28.     //DATE RESET AFTER ECONOMY INIT-------------------------
  29.     int year, month, day, hour, minute;
  30.     int reset_month = 9, reset_day = 20;
  31.     GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  32.  
  33.     if ((month == reset_month) && (day < reset_day))
  34.     {
  35.         GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  36.     }
  37.     else
  38.     {
  39.         if ((month == reset_month + 1) && (day > reset_day))
  40.         {
  41.             GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  42.         }
  43.         else
  44.         {
  45.             if ((month < reset_month) || (month > reset_month + 1))
  46.             {
  47.                 GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  48.             }
  49.         }
  50.     }
  51.  
  52. // Add your BuilderItems or DayZ Editor Code Here for building and item placement
  53.  
  54. class CONFIG
  55. {
  56.     // Character Creation
  57.     const int MELEE_CHANCE                          = 80;       // Chance of getting a melee weapon. Out of 100. default is 100%. To Disable set to 0
  58.     const int BACKPACK_CHANCE                       = 85;       // Chance of getting a backpack. Out of 100. default is 100%. To Disable set to 0
  59.    
  60.     // Seasonal Settings
  61.     const bool CHRISTMAS                            = false;    // Enables christmas gear on spawn. To Disable set to false
  62.  
  63.     // Spawn Clothing Config   
  64.     static ref const array<string> GEAR_TOPS        = {"DZNC_Hoodie", "DZNC_Hoodie_Green", "DZNC_Hoodie_Grey", "DZNC_Hoodie_Blue", "DZNC_Hoodie_Red", "DZNC_Hoodie_TieDye"};
  65.     static ref const array<string> GEAR_PANTS       = {"CargoPants_Black", "CargoPants_Blue", "CargoPants_Green", "CargoPants_Grey"};
  66.     static ref const array<string> GEAR_GLOVES      = {"WorkingGloves_Black", "WorkingGloves_Brown", "WorkingGloves_Beige" , "WorkingGloves_Yellow"};
  67.     static ref const array<string> GEAR_SHOES       = {"AthleticShoes_Black", "AthleticShoes_Green", "AthleticShoes_Blue", "AthleticShoes_Brown", "AthleticShoes_Grey"};
  68.     static ref const array<string> GEAR_MELEE       = {"StoneKnife", "KitchenKnife", "SteakKnife"};
  69.     static ref const array<string> GEAR_BACKPACK    = {"TaloonBag_Blue", "TaloonBag_Green", "TaloonBag_Orange", "TaloonBag_Violet"};
  70.     static ref const array<string> CHEMLIGHT        = {"Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red"};
  71.     static ref const array<string> FOOD             = {"PeachesCan", "SpaghettiCan", "TacticalBaconCan", "BakedBeansCan"};
  72.     static ref const array<string> DRINK            = {"SodaCan_Cola", "SodaCan_Pipsi", "SodaCan_Spite", "SodaCan_Kvass"};
  73.     static ref const array<string> MEDICAL          = {"Bandage", "BandageDressing", "Rag"};
  74. };
  75.  
  76. class CustomMission: MissionServer
  77. {
  78.     // Global Variables
  79.     EntityAI itemTop;
  80.     EntityAI itemEnt, Char_Bag, Char_Gloves, Char_Top, Char_Pants, Char_Shoes, Char_Chemlight, Char_Melee, attachment;
  81.     ItemBase itemBs;
  82.  
  83.     // Convert variables to string
  84.     string  RandomMelee;
  85.     string  RandomBag;
  86.     string  RandomChemlight
  87.  
  88.     // Use for randomizing items chances.
  89.     int randNum = Math.RandomInt( 0, 100 );
  90.    
  91.     // Set how many bandages or rags player starts with.
  92.     const int MEDICAL_AMOUNT = 4;  
  93.  
  94.     // Set Character Health
  95.     void SetRandomHealth(EntityAI itemEnt)
  96.     {
  97.         if ( itemEnt )
  98.         {
  99.             float rndHlt = Math.RandomFloat( 0.75, 100 );
  100.             itemEnt.SetHealth( "", "", rndHlt );
  101.         }
  102.     }
  103.  
  104.     // Set Character into game
  105.     override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
  106.     {
  107.         Entity playerEnt;
  108.         playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
  109.         Class.CastTo( m_player, playerEnt );
  110.         GetGame().SelectPlayer( identity, m_player );
  111.         return m_player;
  112.     }
  113.  
  114.     override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
  115.     {  
  116.        
  117.         // Start By Removing all default items regardess of name or state
  118.         player.RemoveAllItems();
  119.  
  120.         // Get Player Name
  121.         bool playerNameIsSurvivor = false;
  122.         string characterName = player.GetIdentity().GetName();
  123.         characterName.ToLower();
  124.  
  125.         // Does player name contain Survivor
  126.         if ( characterName.Contains("survivor") )
  127.         {
  128.             playerNameIsSurvivor = true;
  129.         }
  130.        
  131.         // If Player is Named Survivor Remove All Gear
  132.         if ( playerNameIsSurvivor )
  133.         {
  134.             player.RemoveAllItems();   
  135.             GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(SurvivorDetected, 5000, true, player);
  136.         }
  137.    
  138.         // If Xmas is toggled on.  Use Christmas Clothing Set! Else use random custom hoodie, or other top
  139.         if ( CONFIG.CHRISTMAS ) {
  140.             player.GetInventory().CreateInInventory( "SantasHat" );
  141.             player.GetInventory().CreateInInventory( "SantasBeard" );
  142.             player.GetInventory().CreateInInventory( "DZNC_Xmas_Sweater");
  143.         } else {
  144.             Char_Top = player.GetInventory().CreateInInventory( CONFIG.GEAR_TOPS.GetRandomElement());
  145.         }
  146.  
  147.         // Set Random Base Clothing Loadout
  148.         Char_Pants    = player.GetInventory().CreateInInventory( CONFIG.GEAR_PANTS.GetRandomElement());
  149.         Char_Shoes    = player.GetInventory().CreateInInventory( CONFIG.GEAR_SHOES.GetRandomElement());
  150.         Char_Gloves   = player.GetInventory().CreateInInventory( CONFIG.GEAR_GLOVES.GetRandomElement());
  151.  
  152.         // Find player shirt slot
  153.         itemTop = player.FindAttachmentBySlotName("Body");
  154.  
  155.         // If Shirt or Jacket is attached
  156.         if ( itemTop )
  157.             {
  158.             // Give 4 Random Medical Items
  159.             itemEnt = player.GetInventory().CreateInInventory( CONFIG.MEDICAL.GetRandomElement());
  160.             if ( Class.CastTo(itemBs, itemEnt ) )
  161.             itemBs.SetQuantity(MEDICAL_AMOUNT);
  162.             // Give Random Food and Drink Items
  163.             itemEnt = player.GetInventory().CreateInInventory( CONFIG.FOOD.GetRandomElement());
  164.             itemEnt = player.GetInventory().CreateInInventory( CONFIG.DRINK.GetRandomElement());
  165.         }
  166.  
  167.         // Set character Melee Weapon and add it to quickbar (Can reuse for other weapons)
  168.         // Does the player get a Melee Weapon?
  169.         if ( randNum <= CONFIG.MELEE_CHANCE ) {
  170.             // Get melee weapon
  171.             RandomMelee = CONFIG.GEAR_MELEE.GetRandomElement();
  172.             // Create in inventory
  173.             Char_Melee = player.GetInventory().CreateInInventory( RandomMelee );
  174.             // Assign to quick bar
  175.             player.SetQuickBarEntityShortcut( Char_Melee, 0, true );
  176.             // Put item in hands (OPTIONAL)
  177.             if ( GetGame().IsMultiplayer() ) { 
  178.                 player.ServerTakeEntityToHands( Char_Melee );
  179.             } else {
  180.                 player.LocalTakeEntityToHands( Char_Melee );
  181.             }
  182.         }
  183.  
  184.         // Set character Backpack and attach Chemlight
  185.         // Does the player get a Melee Weapon?
  186.         if ( randNum <= CONFIG.BACKPACK_CHANCE ) {
  187.             // Get Backpack and Chemlight
  188.             // NOTE: Remember to add what ever variable use here as a string in the Global Variables
  189.             RandomBag = CONFIG.GEAR_BACKPACK.GetRandomElement();
  190.             RandomChemlight = CONFIG.CHEMLIGHT.GetRandomElement();
  191.             // Create in inventory
  192.             Char_Bag = player.GetInventory().CreateInInventory( RandomBag );
  193.             // Attach Chemlight
  194.             attachment.GetInventory().CreateAttachment( RandomChemlight );
  195.         }      
  196.     }
  197.    
  198.     // Send player message if they have Survivor as a name
  199.     protected void SurvivorDetected(PlayerBase player)
  200.     {
  201.         sendPlayerMessage(player, "Since your name is 'Survivor', you spawn NAKED!");
  202.         sendPlayerMessage(player, "If you give yourself a name, you get starter pack with clothes, backpack, basic gear!");
  203.         sendPlayerMessage(player, "Because we are an RP Server it is highly reccomended that you pick a character name.");
  204.     }
  205.    
  206.     protected void sendPlayerMessage(PlayerBase player, string message)    
  207.     {
  208.         if((player) && (message != ""))
  209.         {
  210.             Param1<string> Msgparam;
  211.             Msgparam = new Param1<string>(message);
  212.             GetGame().RPCSingleParam(player, ERPCs.RPC_USER_ACTION_MESSAGE, Msgparam, true, player.GetIdentity());
  213.             GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Remove(SurvivorDetected);
  214.         }
  215.     }
  216. };
  217.  
  218. Mission CreateCustomMission(string path)
  219. {
  220.     return new CustomMission();
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement