Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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
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() != eWateredState.DRY)
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 OnExecuteClient(ActionData action_data)
92 {
93 super.OnExecuteClient(action_data);
94
95 PlayerBase player = action_data.m_Player;
96 float stackable;
98
99 //We place in inventory
100 if ( !player.GetInventory().CanAddEntityIntoHands( m_Seed ) )
101 {
102 il = action_data.m_ReservedInventoryLocations.Get( 0 );
103 InventoryLocation targetInventoryLocation = new InventoryLocation;
104 m_Seed.GetInventory().GetCurrentInventoryLocation( targetInventoryLocation );
105
106 stackable = m_Seed.GetTargetQuantityMax( il.GetSlot() );
107
108 ClearInventoryReservationEx(action_data);
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 stackable = m_Seed.GetTargetQuantityMax( -1 );
123
124 if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
125 {
126 action_data.m_Player.PredictiveTakeEntityToHands( m_Seed );
127 }
128 else
129 {
130 il = new InventoryLocation;
131 il.SetHands( action_data.m_Player, m_Seed );
132 m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
133 }
134 }
135 }
136};
ActionBase ActionData
Definition actionbase.c:30
class ActionTargets ActionTarget
string m_Text
Definition actionbase.c:64
ref CCIBase m_ConditionItem
Definition actionbase.c:70
ref CCTBase m_ConditionTarget
Definition actionbase.c:71
void ClearInventoryReservationEx(ActionData action_data)
override void CreateConditionComponents()
override bool InventoryReservation(ActionData action_data)
override void OnExecuteClient(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:81
const int c_InventoryReservationTimeoutMS
reservations
Definition inventory.c:714
InventoryLocation.
proto native int GetSlot()
returns slot id if current type is Attachment
proto native void SetHands(notnull EntityAI parent, EntityAI e)
const float SMALL
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
FindInventoryLocationType
flags for searching locations in inventory