Jump to content

Problems with retrieving world object


Soul Filcher

Recommended Posts

Hi,

 

In my mod I'm trying to add a bear trap, but not as a "real trap", and by that I mean it is not added to the trap list and is not meant to capture prey but to damage zombies and players. So far I can place it, but when I try to right-click on it I get the custom context menu shown twice, and when I click that I get an error and it doesn't call the function to actually pick it up. It is the first thing I'm trying to add beyond adding items and changing their distributions, so maybe I went with something way beyond my noob level. The code is mostly a frankenstein made from a few different sources.

 

[spoiler][code]ISSFHuntMenu = {};
ISSFHuntMenu.currentSquare = nil;
ISSFHuntMenu.sfbeartrap = nil;

ISSFHuntMenu.doSFHuntMenu = function(player, context, worldobjects, test)

    local removeBearTrap = nil

    if test and ISWorldObjectContextMenu.Test then return true end

        if getSpecificPlayer(player):getInventory():contains("BearTrap") then
            context:addOption(getText("ContextMenu_Place_BearTrap"), worldobjects, ISSFHuntMenu.onAddBearTrap, player)
        end

        for i,v in ipairs(worldobjects) do
                if v:getName() == "Bear Trap" then
                        sfbeartrap = v;
                context:addOption(getText("ContextMenu_Take_BearTrap"), sfbeartrap, ISSFHuntMenu.onRemoveBearTrap, player)
            end
        end
        return
end

function ISSFHuntMenu.onAddBearTrap(worldobjects, player)
    local bo = SFBearTrap:new("media/textures/constructedobjects_01_20.png", player);
    bo.player = player;
    getCell():setDrag(bo, player);
end

ISSFHuntMenu.onRemoveBearTrap = function(worldobjects, player, sfbeartrap)
    local playerObj = getSpecificPlayer(player)
    if luautils.walkAdj(playerObj, sfbeartrap:getSquare()) then
        ISTimedActionQueue.add(ISTakeBearTrap:new(playerObj, sfbeartrap, 60));
    end
end

Events.OnFillWorldObjectContextMenu.Add(ISSFHuntMenu.doSFHuntMenu);[/code][spoiler]

 

The error I get in game when I click to pick the trap is: Attempted index: GetSquare of non-table: null. I know it has something to do with how I made sfbeartrap = v and it being unable to determine the square it is on, but I don't understand enough to fix that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...