Results 1 to 2 of 2

Thread: onObjectEnterContainer and improvements to onObjectLeaveContainer

  1. #1

    onObjectEnterContainer and improvements to onObjectLeaveContainer

    onObjectEnterContainer(container, obj) is the logical counterpart to onObjectLeaveContainer(container, obj) and it's odd that it's not already included.

    As for improvements, a way to prevent the object from entering/leaving the container would be incredibly useful. The simplest way to implement from a Lua perspective would be a simple `return false`, if false is returned then the object cannot enter/exit the container.

    Additionally, onObjectLeaveContainer's object's `held_by_color` variable is always nil for the tick that it's drawn, adding an additional argument seems to be an easy way around this: onObjectLeaveContainer( container, obj, drawn_by_color ), where drawn_by_color is nil if there is no user (ie it was drawn by script). There's a few ways to translate the argument to onObjectEnterContainer too, but not flawlessly so I'll leave that out of the suggestion for now.

    Here's a few quick examples that would make use of these suggestions:

    Code:
    -- Bag seal ( http://www.berserk-games.com/forums/showthread.php?4867-Bag-Suggestion )
    
    
    local sealed = false
    
    function onObjectLeaveContainer(bag, obj)
    	if bag==self and sealed then return false end
    end
    function onObjectEnterContainer(bag, obj)
    	if bag==self and sealed then return false end
    end
    function toggleSeal()
    	sealed = not sealed
    end
    
    
    -- GM-Only container
    
    
    function onObjectLeaveContainer( bag, obj, col )
    	if bag==self and col and (col~="Black") then -- Bag is this object; and pulled by color; and color is not Black
    		return false -- Do not allow pull
    	end
    end
    function onObjectEnterContainer( bag, obj, col ) -- Specifics of how col is determined TBC
    	if bag==self and ((not col) or (col~="Black")) then -- Bag is this object; and NOT dropped by color OR color is not Black
    		return false -- Do not allow drop
    	end
    end
    
    
    -- Container cooldown
    
    
    local nextPull = 0
    function onObjectLeaveContainer( bag, obj, col )
    	if bag==self then
    		if os.time()<nextPull then -- On cooldown
    			if col then
    				broadcastToColor("Container on cooldown, try again later", col, {1,0,0})
    			end
    			return false
    		end
    		
    		nextPull = os.timer()+10
    	end
    end

  2. #2
    Join Date
    Feb 2017
    Posts
    178
    Seconded, particularly for onObjectEnterContainer

Similar Threads

  1. onObjectLeaveContainer from an infinite bag
    By boulder- in forum Scripting Bug Reports
    Replies: 2
    Last Post: 06-30-2017, 01:55 PM
  2. held_by_color is nil in onObjectLeaveContainer
    By kccricket in forum Scripting Bug Reports
    Replies: 3
    Last Post: 05-18-2017, 07:39 AM
  3. held_by_color is nil in onObjectLeaveContainer
    By kccricket in forum Scripting
    Replies: 3
    Last Post: 05-13-2017, 03:36 PM
  4. Scripting improvements
    By DeJMan in forum Scripting
    Replies: 2
    Last Post: 04-05-2016, 01:02 PM
  5. Grid improvements
    By Judgernaut in forum General Discussion
    Replies: 3
    Last Post: 01-14-2015, 06:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •