Skip to content

Instantly share code, notes, and snippets.

@treeherder
Created January 14, 2021 23:22
Show Gist options
  • Save treeherder/f9384afd8121a3beb4f67b844605fe06 to your computer and use it in GitHub Desktop.
Save treeherder/f9384afd8121a3beb4f67b844605fe06 to your computer and use it in GitHub Desktop.
modded class Cannabis
{
TrippingLights buzz;
override bool CanBeCooked()
{
return true;
}
override bool CanBeCookedOnStick()
{
return true;
}
override bool IsFruit()
{
return true;
}
override void OnConsume(float amount, PlayerBase consumer)
{
if( consumer.GetModifiersManager().IsModifierActive(newModifiers.MDF_CANNABIS))//effectively resets the timer
{
consumer.GetModifiersManager().DeactivateModifier( newModifiers.MDF_CANNABIS );
consumer.GetModifiersManager().DeactivateModifier( eModifiers.MDF_TEMPERATURE );
}
consumer.GetModifiersManager().ActivateModifier( newModifiers.MDF_CANNABIS );
consumer.GetModifiersManager().ActivateModifier( eModifiers.MDF_TEMPERATURE );
}
override void SetActions()
{
super.SetActions();
AddAction(ActionForceFeed);
AddAction(ActionEatSmall);
}
}
class CannabisMdfr: ModifierBase
{
private const float CANNABIS_BONE_PER_SEC = 0.25;
float m_Duration;
override void Init()
{
m_TrackActivatedTime = true;
m_IsPersistent = true;
m_ID = newModifiers.MDF_CANNABIS;
m_TickIntervalInactive = DEFAULT_TICK_TIME_INACTIVE;
m_TickIntervalActive = DEFAULT_TICK_TIME_ACTIVE;
m_Duration = 420;
}
override bool ActivateCondition(PlayerBase player)
{
return false;
}
override bool DeactivateCondition(PlayerBase player)
{
float attached_time = GetAttachedTime();
if ( attached_time > m_Duration )
{
return true;
}
else
{
return false;
}
}
override void OnReconnect(PlayerBase player)
{
OnActivate(player);
}
override void OnActivate(PlayerBase player)
{
player.SetImmunityBoosted(true);
if( player.GetNotifiersManager() )
player.GetNotifiersManager().ActivateByType(eNotifiers.NTF_PILLS);
if (PlayerBaseClient.Cast(player))
{
PlayerBaseClient.Cast(player).toggle_light(true);
}
}
override void OnDeactivate(PlayerBase player)
{
player.SetImmunityBoosted(false);
if( player.GetNotifiersManager() )
player.GetNotifiersManager().DeactivateByType(eNotifiers.NTF_PILLS);
PlayerBaseClient.Cast(player).toggle_light(false);
}
override void OnTick(PlayerBase player, float deltaT)
{
player.AddHealth("RightArm","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("RightHand","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("LeftArm","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("LeftHand","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("RightLeg","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("RightFoot","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("LeftLeg","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("LeftFoot","Health", CANNABIS_BONE_PER_SEC * deltaT);
player.AddHealth("Torso","Health", CANNABIS_BONE_PER_SEC * deltaT);
}
};
modded class PlayerBaseClient
{
ScriptedLightBase buzz;
void createlight()
{
//check if client-side
if (GetGame().IsClient() || !GetGame().IsMultiplayer())
{
// Create light
buzz = ScriptedLightBase.CreateLight(TrippingLights);
// Attach to player
buzz.AttachOnObject(this);
}
}
void toggle_light(bool state)
{
createlight();
buzz.SetEnabled(state);
}
void PlayerBase()
{
buzz.SetEnabled(false);
}
}
class TrippingLights extends PointLightBase
{
float m_Timer = 0;
void TrippingLights()
{
SetVisibleDuringDaylight(true);
SetRadiusTo(2);
SetBrightnessTo(Math.RandomFloat01());
SetCastShadow(false);
EnableSpecular(false);
EnableLinear(true);
SetFlareVisible(false);
}
override void OnFrameLightSource(IEntity other, float timeSlice)
{
if ( GetGame() && IsEnabled() )
{
float valS = Math.AbsFloat(Math.Sin(m_Timer * Math.PI2));
float valC = Math.AbsFloat(Math.Cos(m_Timer * Math.PI2));
float valT = Math.AbsFloat(Math.Tan(m_Timer * Math.PI2));
SetDiffuseColor(valS, valC, valT);
SetAmbientColor(valS, valC, valT);
m_Timer += timeSlice;
vector pos = GetGame().GetCurrentCameraPosition();
vector dir = GetGame().GetCurrentCameraDirection();
SetPosition(pos);
DayZPlayer plr = GetGame().GetPlayer();
if (plr)
{
vector pos_plr = plr.GetPosition() + Vector(0, 1.64, 0);
float distance = vector.Distance( pos_plr, pos );
Print(distance);
float radius = 20.0 + distance;
SetRadiusTo( radius );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment