====== Drop an Object ====== It is fairly easy to get an object, but not as easy to drop an object. First, it must only be dropped in an actual zone. Second, it should (usually) be dropped in Player's current zone. One way that works is detailed in the instructions below. This way of dropping objects assumes that no zones overlap. Handling overlapping zones is left as an exercise for the reader. **Typographical Conventions**: * In the instructions below, "L>" at the beginning of a line is a shortcut that indicates a "Lua Statement" or "Lua Expression", depending on context. Some of these things can only be done with Lua statements. * Indentation is shown in the examples for increased readability but is not required. ===== Summary ===== * Create expression ''[[drop_object#Expressions|Is_Player_In_Zone]]''. * Call ''[[drop_object#Droppable?|Item_Event_Availability]]'' for every zone's ''Enter''/''Exit'' event. * Call ''[[drop_object#Drop the Object|Item_Drop]]'' for item's ''Drop'' event. * Call ''[[drop_object#Get the Object|Item_Get]]'' for item's ''Get'' event. ===== Expressions ===== First you will need to create the following expression: * Is_Player_In_Zone L> #Player.InsideOfZones > 0 ===== Droppable? ===== You want to make it so that you can only drop items in a zone. Remember, this only works for non-overlapping zones. You will want to call this function for ''Enter'' and ''Exit'' events for every zone where an item may be dropped. Enabling/disabling the ''Get'' event is left as an exercise to the reader, except as show below. * Item_Event_Availability L> for key,value in pairs(Player.Inventory) do L> if value.Commands["Drop"] then L> value.Commands["Drop"].Enabled = (#Player.InsideOfZones > 0) L> end L> end My cartridge calls ''Zone_Enter'' when every zone is entered, and ''Zone_Exit'' when every zone is exited. These functions take care of other accounting which may need to be done when entering a zone, so I need to check to see if this zone is a zone where an object can be dropped. * Item_Event_Availability L> for key,value in pairs(Player.Inventory) do L> if value.Commands["Drop"] then if Is_Player_In_Zone_Next_To_Bridge L> value.Commands["Drop"].Enabled = (#Player.InsideOfZones > 0) else endif L> end L> end The implementation of the expression ''Is_Player_In_Zone_Next_To_Bridge'' is unimportant for this example so it is not shown. You will need to create an expression appropriate for your cartridge anyway. ===== Drop the Object ===== This is the function that actually drops the item into the current (non-overlapping) zone. You will need to set the parameter name to ''item''. This uses the expression ''Is_Player_In_Zone'' created above. It also enables the ''Get'' event for the object just dropped. How to call this function will be show below. * Item_Drop if Is_Player_In_Zone L> item:MoveTo(Player.InsideOfZones[1]) L> item.Commands["Drop"].Enabled = false L> item.Commands["Get"].Enabled = true else endif All of this could be implemented in the item's ''Drop'' event. However, since that would nearly duplicate this same code in every event, it is easier to implement it once and call this function. In order to use use this function it must be called from the ''Drop'' event with the item being dropped, as follows: Call_function Item_Drop (item=Item:Fox) ''Fox'' is an item in my cartridge, but will be different for your cartridge. You may implement other effects of dropping an object either in ''Item_Drop'' (if it applies to most/all items) or in each individual item's ''Drop'' event. ===== Get the Object ===== While implementing ''Get'' is fairly easy, adding ''Drop'' slightly complicates it. You will need to set the parameter name to ''item''. It also enables the ''Drop'' event for the object just dropped, and disables ''Get'' event. How to call this function will be show below. * Item_Get Move_an_element Item:item => Player L> item.Commands["Get"].Enabled = false L> item.Commands["Drop"].Enabled = true All of this could be implemented in the item's ''Drop'' event. However, since that would nearly duplicate this same code in every event, it is easier to implement it once and call this function. And as above, in my cartridge I only want items able to be dropped if in certain zones: Move_an_element Item:item => Player L> item.Commands["Get"].Enabled = false if Is_Player_In_Zone_Next_To_Bridge L> item.Commands["Drop"].Enabled = true else endif In order to use use this function it must be called from the ''Get'' event with the item being gotten, as follows: Call_function Item_Get (item=Item:Fox) ''Fox'' is an item in my cartridge, but will be different for your cartridge. You may implement other effects of getting an object either in ''Item_Get'' (if it applies to most/all items) or in each individual item's ''Get'' event.