DayZ 1.24
Loading...
Searching...
No Matches
ActionRemoveSeed.c
Go to the documentation of this file.
2{
4
6 {
7 m_Text = "#take";
8 }
9
10 override typename GetInputType()
11 {
13 }
14
20
21 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
22 {
23 if (player.GetCommand_Vehicle())
24 return false;
25
27 if (Class.CastTo(garden_base, target.GetObject()))
28 {
29 Slot slot;
30
32 garden_base.GetActionComponentNameList(target.GetComponentIndex(), selections);
33 string selection;
34
35 for (int s = 0; s < selections.Count(); s++)
36 {
37 selection = selections[s];
38 slot = garden_base.GetSlotBySelection(selection);
39 if (slot)
40 break;
41 }
42
43 //Can only remove seed if slot is not watered to prevent VME
44 if (slot && slot.GetSeed())
45 {
46 if (slot.GetWateredState() != 0)
47 return false;
48
49 m_Seed = SeedBase.Cast(slot.GetSeed());
50
51 if (m_Seed)
52 {
53 if (player.GetInventory().CanAddEntityIntoInventory(m_Seed) && m_Seed.GetHierarchyRootPlayer() != player)
54 return true;
55 else
56 return player.GetInventory().CanAddEntityIntoHands(m_Seed);
57 }
58 }
59 }
60 return false;
61 }
62
64 {
65 bool success = true;
66
68
69 if (m_Seed)
70 {
71 action_data.m_Player.GetInventory().FindFreeLocationFor(m_Seed, FindInventoryLocationType.ANY, il);
72 if (action_data.m_Player.GetInventory().HasInventoryReservation(m_Seed, il))
73 success = false;
74 else
75 action_data.m_Player.GetInventory().AddInventoryReservationEx(m_Seed, il, GameInventory.c_InventoryReservationTimeoutMS);
76 }
77
78 if (success)
79 {
80 if (il)
81 action_data.m_ReservedInventoryLocations.Insert(il);
82 }
83
84 return success;
85 }
86
88 {
89 if (GetGame().IsMultiplayer() && GetGame().IsServer())
90 return;
91
92 PlayerBase player = action_data.m_Player;
93 float stackable;
95
96 //We place in inventory
97 if (!player.GetInventory().CanAddEntityIntoHands(m_Seed))
98 {
99 il = action_data.m_ReservedInventoryLocations.Get(0);
101 m_Seed.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
102
103 stackable = m_Seed.GetTargetQuantityMax(il.GetSlot());
104
105 if (stackable == 0 || stackable >= m_Seed.GetQuantity())
106 player.PredictiveTakeToDst(targetInventoryLocation, il);
107 else
108 m_Seed.SplitIntoStackMaxToInventoryLocationClient(il);
109 }
110 else
111 {
112 //We place in hands
114
115 stackable = m_Seed.GetTargetQuantityMax(-1);
116
117 if (stackable == 0 || stackable >= m_Seed.GetQuantity())
118 action_data.m_Player.PredictiveTakeEntityToHands(m_Seed);
119 else
120 {
121 il = new InventoryLocation;
122 il.SetHands(action_data.m_Player, m_Seed);
123 m_Seed.SplitIntoStackMaxToInventoryLocationClient(il);
124 }
125 }
126 }
127};
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:790
FindInventoryLocationType
flags for searching locations in inventory
override GetInputType()
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override bool InventoryReservation(ActionData action_data)
override void OnExecute(ActionData action_data)
override void CreateConditionComponents()
Super root of all classes in Enforce script.
Definition EnScript.c:11
script counterpart to engine's class Inventory
Definition Inventory.c:79
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:687
InventoryLocation.
const float SMALL
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.