-
-
Notifications
You must be signed in to change notification settings - Fork 16
Helper Functions for init.c
There are helper function to help you provide custom loadouts or skins to players based on their Affinity, Level, Humanity, or Stats
m_HeroesAndBandits.getPlayerSkin(PlayerID)
This will return the players skin based on what is defined in the BambiSkins, HeroSkins, or BanditSkins in the config file
m_HeroesAndBandits.GetPlayerAffinity(PlayerID)
This will return the players Affinity in a string usually bambi, hero, bandit but this can be configured by the server admins will return bambi(Default Level Affinity) if the player can't be found
m_HeroesAndBandits.GetPlayerHumanity(PlayerID)
This will return the players Humanity in a float value, it will return 0 if the player can't be found
m_HeroesAndBandits.GetPlayerLevelName(PlayerID)
Returns the Level Name in a string, if the player doesn't exist it will return the default level's name (usually Bambi) if the player can't be found
m_HeroesAndBandits.GetPlayerStat(PlayerID, ActionName)
Returns INT of the player stats for the Action specified, if a player or the player's stat doesn't exist it returns 0
m_HeroesAndBandits.updatePlayerTotals()
This will load and then recalculate all of the player's humanity based on the current action values. Since this will load all players into the local system, it is recommended to remove the code and restart the server once it finishes booting. To prevent any potential performance decreases especially on large population servers.
void main()
{
//INIT WEATHER BEFORE ECONOMY INIT------------------------
Weather weather = g_Game.GetWeather();
weather.MissionWeather(false); // false = use weather controller from Weather.c
weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
weather.GetRain().Set( 0, 0, 1);
weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);
//INIT ECONOMY--------------------------------------
Hive ce = CreateHive();
if ( ce )
ce.InitOffline();
//DATE RESET AFTER ECONOMY INIT-------------------------
int year, month, day, hour, minute;
int reset_month = 9, reset_day = 20;
GetGame().GetWorld().GetDate(year, month, day, hour, minute);
if ((month == reset_month) && (day < reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month == reset_month + 1) && (day > reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month < reset_month) || (month > reset_month + 1))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
}
}
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES START * * * * * * * * * * * * * *
// Remove the "//" to have my mod recalculate new humanity levels for players
//m_HeroesAndBandits.updatePlayerTotals();
/* * * * * * * * * * * * * HEROES AND BANDITS CHANGES END * * * * * * * * * * * * * * */
}
class CustomMission: MissionServer
{
void SetRandomHealth(EntityAI itemEnt)
{
if ( itemEnt )
{
int rndHlt = Math.RandomInt(55,100);
itemEnt.SetHealth("","",rndHlt);
}
}
override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
{
Entity playerEnt;
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES START * * * * * * * * * * * * * *
// To get the custom Skins you have to change characterName to m_HeroesAndBandits.getPlayerSkin(identity.GetPlainId())
playerEnt = GetGame().CreatePlayer(identity, m_HeroesAndBandits.getPlayerSkin(identity.GetPlainId()), pos, 0, "NONE"); //Creates random player
/* * * * * * * * * * * * * HEROES AND BANDITS CHANGES END * * * * * * * * * * * * * * */
Class.CastTo(m_player, playerEnt);
GetGame().SelectPlayer(identity, m_player);
return m_player;
}
override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
{
EntityAI itemTop;
EntityAI itemEnt;
ItemBase itemBs;
float rand;
itemTop = player.FindAttachmentBySlotName("Body");
if ( itemTop )
{
itemEnt = itemTop.GetInventory().CreateInInventory("Rag");
if ( Class.CastTo(itemBs, itemEnt ) )
itemBs.SetQuantity(4);
SetRandomHealth(itemEnt);
string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
int rndIndex = Math.RandomInt(0, 4);
itemEnt = itemTop.GetInventory().CreateInInventory(chemlightArray[rndIndex]);
SetRandomHealth(itemEnt);
rand = Math.RandomFloatInclusive(0.0, 1.0);
if ( rand < 0.35 )
itemEnt = player.GetInventory().CreateInInventory("Apple");
else if ( rand > 0.65 )
itemEnt = player.GetInventory().CreateInInventory("Pear");
else
itemEnt = player.GetInventory().CreateInInventory("Plum");
SetRandomHealth(itemEnt);
}
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES START * * * * * * * * * * * * * *
// Give hero or bandit specific load-outs
TStringArray bandanaMask = {"BandanaMask_BlackPattern","BandanaMask_CamoPattern","BandanaMask_GreenPattern", "BandanaMask_PolkaPattern"};
if(m_HeroesAndBandits.GetPlayerHeroOrBandit(player.GetIdentity().GetPlainId()) == "bandit")
{
player.GetInventory().CreateInInventory(bandanaMask.GetRandomElement());
} else if (m_HeroesAndBandits.GetPlayerHeroOrBandit(player.GetIdentity().GetPlainId()) == "hero") {
}
float playerHumanity = m_HeroesAndBandits.GetPlayerHumanity(player.GetIdentity().GetPlainId());
if(playerHumanity < -4001) // Player is level 2 bandit or higher
{
player.GetInventory().CreateInInventory("CourierBag"); // spawn with a Courier Bag
}
if (playerHumanity > 4001) //Player is level 2 Hero or higher
{
player.GetInventory().CreateInInventory("WaterproofBag_Green"); // spawn with a waterproof bag
}
if ( m_HeroesAndBandits.GetPlayerStat( player.GetIdentity().GetPlainId(), "Medic" ) > 100) //Player has made over 100 Medic Actions so giving them a first aid kit
{
EntityAI firstAidKit = player.GetInventory().CreateInInventory("FirstAidKit");
firstAidKit.GetInventory().CreateInInventory("TetracyclineAntibiotics");
firstAidKit.GetInventory().CreateInInventory("BandageDressing");
firstAidKit.GetInventory().CreateInInventory("BandageDressing");
firstAidKit.GetInventory().CreateInInventory("CharcoalTablets");
firstAidKit.GetInventory().CreateInInventory("BloodTestKit");
}
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES END * * * * * * * * * * * * * * *
}
};
Mission CreateCustomMission(string path)
{
return new CustomMission();
}
/**
* init.c
*
* DayZ Expansion Mod
* www.dayzexpansion.com
* © 2020 DayZ Expansion Mod Team
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
*
*/
#include "$CurrentDir:\\mpmissions\\Expansion.ChernarusPlus\\expansion\\ExpansionObjectSpawnTools.c"
#include "$CurrentDir:\\mpmissions\\Expansion.ChernarusPlus\\expansion\\missions\\MissionConstructor.c"
void main()
{
bool loadTraderObjects = false;
bool loadTraderNPCs = false;
string MissionWorldName = "empty";
GetGame().GetWorldName(MissionWorldName);
if (MissionWorldName != "empty")
{
//! Spawn mission objects and traders
FindMissionFiles(MissionWorldName, loadTraderObjects, loadTraderNPCs);
}
//INIT WEATHER BEFORE ECONOMY INIT------------------------
Weather weather = g_Game.GetWeather();
weather.MissionWeather(false); // false = use weather controller from Weather.c
weather.GetOvercast().Set( Math.RandomFloatInclusive(0.02, 0.1), 1, 0);
weather.GetRain().Set( 0, 1, 0);
weather.GetFog().Set( 0, 1, 0);
//INIT ECONOMY--------------------------------------
Hive ce = CreateHive();
if ( ce )
ce.InitOffline();
//DATE RESET AFTER ECONOMY INIT-------------------------
int year, month, day, hour, minute;
int reset_month = 8, reset_day = 10;
GetGame().GetWorld().GetDate(year, month, day, hour, minute);
if ((month == reset_month) && (day < reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month == reset_month + 1) && (day > reset_day))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
else
{
if ((month < reset_month) || (month > reset_month + 1))
{
GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
}
}
}
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES START * * * * * * * * * * * * * *
// Remove the "//" to have my mod recalculate new humanity levels for players
//m_HeroesAndBandits.updatePlayerTotals();
/* * * * * * * * * * * * * HEROES AND BANDITS CHANGES END * * * * * * * * * * * * * * */
}
/**@class CustomExpansionMission
* @brief This class handle expansion serverside mission
**/
class CustomMission: MissionServer
{
// ------------------------------------------------------------
// SetRandomHealth
// ------------------------------------------------------------
void SetRandomHealth(EntityAI itemEnt)
{
if ( itemEnt )
{
int rndHlt = Math.RandomInt(55,100);
itemEnt.SetHealth("","",rndHlt);
}
}
override void OnInit()
{
ExpansionMissionModule missionModule;
if ( Class.CastTo( missionModule, GetModuleManager().GetModule( ExpansionMissionModule ) ) )
{
missionModule.SetMissionConstructor( COMMissionConstructor );
}
super.OnInit();
}
// ------------------------------------------------------------
// Override PlayerBase CreateCharacter
// ------------------------------------------------------------
override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
{
Entity playerEnt;
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES START * * * * * * * * * * * * * *
// To get the custom Skins you have to change characterName to m_HeroesAndBandits.getPlayerSkin(identity.GetPlainId())
playerEnt = GetGame().CreatePlayer(identity, m_HeroesAndBandits.getPlayerSkin(identity.GetPlainId()), pos, 0, "NONE"); //Creates random player
/* * * * * * * * * * * * * HEROES AND BANDITS CHANGES END * * * * * * * * * * * * * * */
Class.CastTo(m_player, playerEnt);
GetGame().SelectPlayer(identity, m_player);
return m_player;
}
// ------------------------------------------------------------
// Override StartingEquipSetup
// ------------------------------------------------------------
override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
{
if ( !GetExpansionSettings().GetSpawn().StartingClothing.EnableCustomClothing )
{
EntityAI itemClothing;
EntityAI itemEnt;
ItemBase itemBs;
float rand;
itemClothing = player.FindAttachmentBySlotName( "Body" );
if ( itemClothing )
{
SetRandomHealth( itemClothing );
itemEnt = itemClothing.GetInventory().CreateInInventory( "Rag" );
if ( Class.CastTo( itemBs, itemEnt ) )
itemBs.SetQuantity( 4 );
SetRandomHealth( itemEnt );
string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
int rndIndex = Math.RandomInt( 0, 4 );
itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
SetRandomHealth( itemEnt );
rand = Math.RandomFloatInclusive( 0.0, 1.0 );
if ( rand < 0.35 )
itemEnt = player.GetInventory().CreateInInventory( "Apple" );
else if ( rand > 0.65 )
itemEnt = player.GetInventory().CreateInInventory( "Pear" );
else
itemEnt = player.GetInventory().CreateInInventory( "Plum" );
SetRandomHealth( itemEnt );
}
itemClothing = player.FindAttachmentBySlotName( "Legs" );
if ( itemClothing )
SetRandomHealth( itemClothing );
itemClothing = player.FindAttachmentBySlotName( "Feet" );
if ( itemClothing )
SetRandomHealth( itemClothing );
}
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES START * * * * * * * * * * * * * *
// Give hero or bandit specific load outs
TStringArray bandanaMask = {"BandanaMask_BlackPattern","BandanaMask_CamoPattern","BandanaMask_GreenPattern", "BandanaMask_PolkaPattern"};
if(m_HeroesAndBandits.GetPlayerHeroOrBandit(player.GetIdentity().GetPlainId()) == "bandit")
{
player.GetInventory().CreateInInventory(bandanaMask.GetRandomElement());
} else if (m_HeroesAndBandits.GetPlayerHeroOrBandit(player.GetIdentity().GetPlainId()) == "hero") {
}
float playerHumanity = m_HeroesAndBandits.GetPlayerHumanity(player.GetIdentity().GetPlainId());
if(playerHumanity < -4001) // Player is level 2 bandit or higher
{
player.GetInventory().CreateInInventory("CourierBag"); // spawn with a Courier Bag
}
if (playerHumanity > 4001) //Player is level 2 Hero or higher
{
player.GetInventory().CreateInInventory("WaterproofBag_Green"); // spawn with a waterproof bag
}
if ( m_HeroesAndBandits.GetPlayerStat( player.GetIdentity().GetPlainId(), "Medic" ) > 100) //Player has made over 100 Medic Actions so giving them a first aid kit
{
EntityAI firstAidKit = player.GetInventory().CreateInInventory("FirstAidKit");
firstAidKit.GetInventory().CreateInInventory("TetracyclineAntibiotics");
firstAidKit.GetInventory().CreateInInventory("BandageDressing");
firstAidKit.GetInventory().CreateInInventory("BandageDressing");
firstAidKit.GetInventory().CreateInInventory("CharcoalTablets");
firstAidKit.GetInventory().CreateInInventory("BloodTestKit");
}
// * * * * * * * * * * * * HEROES AND BANDITS CHANGES END * * * * * * * * * * * * * * *
}
};
Mission CreateCustomMission(string path)
{
return new CustomMission();
}