DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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
16 {
19 }
20
21 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
22 {
23 if ( player.GetCommand_Vehicle() )
24 return false;
25
26 GardenBase garden_base;
27 if ( Class.CastTo( garden_base, target.GetObject() ) )
28 {
29 Slot slot;
30
31 array<string> selections = new array<string>;
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
63 override bool InventoryReservation(ActionData action_data)
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 {
74 success = false;
75 }
76 else
77 {
78 action_data.m_Player.GetInventory().AddInventoryReservationEx( m_Seed, il, GameInventory.c_InventoryReservationTimeoutMS );
79 }
80 }
81
82 if ( success )
83 {
84 if ( il )
85 action_data.m_ReservedInventoryLocations.Insert( il );
86 }
87
88 return success;
89 }
90
91 override void OnExecute( ActionData action_data )
92 {
93 if ( GetGame().IsMultiplayer() && GetGame().IsServer() )
94 return;
95
96 PlayerBase player = action_data.m_Player;
97 float stackable;
99
100 //We place in inventory
101 if ( !player.GetInventory().CanAddEntityIntoHands( m_Seed ) )
102 {
103 il = action_data.m_ReservedInventoryLocations.Get( 0 );
104 InventoryLocation targetInventoryLocation = new InventoryLocation;
105 m_Seed.GetInventory().GetCurrentInventoryLocation( targetInventoryLocation );
106
107 stackable = m_Seed.GetTargetQuantityMax( il.GetSlot() );
108
109 if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
110 {
111 player.PredictiveTakeToDst( targetInventoryLocation, il );
112 }
113 else
114 {
115 m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
116 }
117 }
118 else
119 {
120 //We place in hands
121 ClearInventoryReservationEx( action_data );
122
123 stackable = m_Seed.GetTargetQuantityMax( -1 );
124
125 if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
126 {
127 action_data.m_Player.PredictiveTakeEntityToHands( m_Seed );
128 }
129 else
130 {
131 il = new InventoryLocation;
132 il.SetHands( action_data.m_Player, m_Seed );
133 m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
134 }
135 }
136 }
137};
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
void ClearInventoryReservationEx(ActionData action_data)
Definition ActionBase.c:861
protected string m_Text
Definition ActionBase.c:49
class ActionTargets ActionTarget
FindInventoryLocationType
flags for searching locations in inventory
PlayerBase m_Player
Definition ActionBase.c:33
ref array< ref InventoryLocation > m_ReservedInventoryLocations
Definition ActionBase.c:35
override void CreateConditionComponents()
override bool InventoryReservation(ActionData action_data)
override void OnExecute(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override GetInputType()
Super root of all classes in Enforce script.
Definition EnScript.c:11
script counterpart to engine's class Inventory
Definition Inventory.c:77
const int c_InventoryReservationTimeoutMS
reservations
Definition Inventory.c:683
InventoryLocation.
proto native void SetHands(notnull EntityAI parent, EntityAI e)
sets current inventory location type to Hands
proto native int GetSlot()
returns slot id if current type is Attachment
const float SMALL
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.