Jump to content

Context Add Option Starts Action


ORMtnMan

Recommended Posts

Heya guys,

 

Haven't asked advice here in a while but I hit a maddening snag.

 

So, I am adding context menu options. It is adding the options to the context menu correctly but it runs (kinda) through the script while adding and does nothing when I try to click the option.

 

Any thoughts?

Link to comment
Share on other sites

Could you paste the relevant part of the code? I usually have that phenomenom when I have a syntax error in the code.

Anything in console.txt?

 

 

Mind posting the code when you are able to?

 

 

Okay, so here is the first relevant piece of code:

 

    for i,v in ipairs(items) do --runs through all items in inventory and adds context menu options

        local testItem = v;

        if not instanceof(v, "InventoryItem") then

            testItem = v.items[1];

        end

        testData = testItem:getModData()

        if testData.reloadClass ~= nil then

        

        else

            ORGMLoadUtil:setUpLoadable(testItem, playerObj)

        end

        testData = testItem:getModData()

        if testData.reloadClass == 'ORGMLoadClass' then --a check to see if the item is an ORGM gun

            local unloadTest = testData.currentCapacity;

            if testData.roundChambered ~= nil and testData.roundChambered ==1 then

                unloadTest = unloadTest + 1

            end

            if testData.magInserted ~= nil and testData.magInserted == 1 and difficulty ~= 1 then

                --test to add eject mag option

                isReloadableMag = true;

            elseif testData.magInserted ~= nil and testData.magInserted ~= 1 and difficulty ~= 1 then

                isReloadable = true;

            elseif (difficulty == 1 or testData.loadStyle ~= 'magfed') and testData.currentCapacity < testData.maxCapacity then --test to add normal reload

                isReloadable = true;

            elseif unloadTest > 0 then --test to add unload option

                isUnloadable = true;

            end

            isLoading = ORGMLoadManager:loadStarted() --test to see if loading

            isRacking = ORGMLoadManager:rackingStarted() --test to see if racking

            isAction = isLoading or isRacking --combines the two

            isSlideOpenable = testData.slideOpen == 1; --checks to see if you can lock open the slide, for faster future reload action

            isSlideOpen = testData.slideOpened == 1; --checks to see if the slide is locked open so you can close it

            isBoltOpenable = testData.boltOpen == 1; --checks to see if you can open the bolt and leave it open

            isBoltOpen = testData.boltOpened == 1; --checks to see if the bolt is currently open to give you the option to close it.

            isOpen = testData.isOpen == 1; --checks if the gun is open currently

            isOpenable = testData.openClose == 1; --checks if the gun can open

            isRackable = testData.canRack == 1; --checks if the item is able to be racked

        end

        

        --Iterating an ammo search        

        testData = testItem:getModData()

        tablename = testData.ammoType

        tablenamemag = testData.magType

        ammoTable = _G[tablename] --awesome function to get a table name from a string

        magTable = _G[tablenamemag]

        if magTable ~= nil and difficulty ~= 1 then

            for i,v in ipairs(magTable) do --iterates adding an option to load for any mag type present

                local testMag = v;

                if playerObj:getInventory():FindAndReturn(testMag) ~= nil then

                    --looks to see if the mag is in your inventory

                    local reloadtextindex = ORGMLoadManager:ORGMindexfinder(testMag, Magindexlist);

                    local reloadtexttoadd = Magloadtext[reloadtextindex]

                    --finds the index and gets the reload text

                    if isReloadable and not isAction then --if the gun is reloadable and you are not performing an action, gives the option to reload

                        local reloadOption = context:addOption(reloadtexttoadd, items, ORGMLoadManager:startReloadFromUi(testItem, testMag), playerObj);

                    end

                end

            end

        end        

        if ammoTable ~= nil then

            if difficulty == 1 or testData.loadStyle ~= 'magfed' then

                for i,v in ipairs(ammoTable) do --iterates adding an option to load for any ammo type present

                    local testCal = v;

                    if playerObj:getInventory():FindAndReturn(testCal) ~= nil then

                        --looks to see if the ammo is in your inventory

                        local reloadtextindex = ORGMConversions:ORGMindexfinder(testCal, Ammoindexlist);

                        local reloadtexttoadd = Ammoloadtext[reloadtextindex]

                        --finds the index and gets the reload text

                        if isReloadable and not isAction then --if the gun is reloadable and you are not performing an action, gives the option to reload

                            local reloadOption = context:addOption(reloadtexttoadd, items, ORGMInventoryLoadMenu.OnReload(items, testCal, playerObj), playerObj);

                        end

                    end

                end

            end

        end

 

it keeps going into other context menus I am adding, but those two are the ones I am currently having issues with.

 

Then it feeds into here:

function ORGMLoadManager:startReloadFromUi(item, ammo) --starts the reloading process

    if(self:reloadStarted() == false and self:rackingStarted() == false) then --makes sure there is no action going

        self.loadWeapon = item;

        self.reloadAmmo = ammo;

        if self.reloadAmmo.reloadClass ~= nil then --test to ignore this if it is not a magazine

            self.reloadMag = self:mostLoadedSearch2(ammo); --checks for the most loaded magazine if applicable

        else

            self.reloadMag = nil; --set to ignore if not a mag or clip

        end

        self.loadType = "reload";

        print(self.reloadAmmo)

        print(self.loadWeapon)

        self:startLoading();

    end

end

 

Then to the next bit

 

function ORGMLoadManager:startLoading() --starts the loading action

    local player = getPlayer()

    local moodles = player:getMoodles();

    local panicLevel = moodles:getMoodleLevel(MoodleType.Panic);

    local actionTime = 0

    self.loadable = ORGMLoadUtil:getLoadableWeapon(self.loadWeapon, player);

    self.loadableData = self.loadWeapon:getModData()

    if self.loadableData.openClose ~= 1 and self.loadableData.openClose == 1 and self.loadableData.isOpen ~= nil and self.loadableData.isOpen ~= 1 then

        actionTime = self.loadable.openCloseTime

    else

        actionTime = self.loadable.reloadTime

    end

    self.loadAction = ORGMLoadAction:new(self, player, self.loadType, player:getSquare(),

        (actionTime*player:getReloadingMod())+(panicLevel*30))

    print(self.loadAction)

    ISTimedActionQueue.add(self.loadAction)

end

And that is where I think it stops because it adds the action to the queue, goes though the timer sequence but does nothing.

Link to comment
Share on other sites

 

And that is where I think it stops because it adds the action to the queue, goes though the timer sequence but does nothing.

 

So you mean that the ORGMLoadAction:update function runs, but the ORGMLoadAction:perform does not?

 

 

So what happens is I right click on a weapon, the context menu items are added to the menu. It shows the time bar above the characters head once for each menu item added to the menu. It doesn't actually do the reloading, E.G. adding ammo to the gun and removing the ammo from inventory.

 

Clicking the item on the menu does nothing.

Link to comment
Share on other sites

so if the progress bar appears, the TA works, but the :perform function in the TA is not working.

But why is there a progress bar for adding items to the context menu? that confuses me a bit..

 

 

Anyway, can you post the code for the :perform function?

 

Trust me, I am just as confused...

 

function ORGMLoadAction:perform() --for performing the loading actions

    print(self.loadType)

    self.loadableData = self.loadWeapon:getModData()

    if self.loadType == "open" then --open the gun for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

    elseif self.loadableData.openClose ~= 1 and self.loadableData.openClose == 1 and self.loadableData.isOpen ~= nil and self.loadableData.isOpen ~= 1 then

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    elseif self.loadType == "reload" or self.loadType == "unload" then --if the loadType is unloading/reloading then is performs the loading action

        self.loadable:loadPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.reloadammo, self.loadType)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

        ISBaseTimedAction.perform(self)

    elseif self.loadType == "close" then --closes the gun if it is open for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    else --otherwise it must be a half-rack action

        self.loadable:halfRackPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.loadType)

        ISBaseTimedAction.perform(self)

    end

end

Link to comment
Share on other sites

 

so if the progress bar appears, the TA works, but the :perform function in the TA is not working.

But why is there a progress bar for adding items to the context menu? that confuses me a bit..

 

 

Anyway, can you post the code for the :perform function?

 

Trust me, I am just as confused...

 

function ORGMLoadAction:perform() --for performing the loading actions

    print(self.loadType)

    self.loadableData = self.loadWeapon:getModData()

    if self.loadType == "open" then --open the gun for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

    elseif self.loadableData.openClose ~= 1 and self.loadableData.openClose == 1 and self.loadableData.isOpen ~= nil and self.loadableData.isOpen ~= 1 then

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    elseif self.loadType == "reload" or self.loadType == "unload" then --if the loadType is unloading/reloading then is performs the loading action

        self.loadable:loadPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.reloadammo, self.loadType)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

        ISBaseTimedAction.perform(self)

    elseif self.loadType == "close" then --closes the gun if it is open for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    else --otherwise it must be a half-rack action

        self.loadable:halfRackPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.loadType)

        ISBaseTimedAction.perform(self)

    end

end

 

 

EDIT:

And just to reiterate the Timed Action is working but at the wrong time. It does the TA when I right click to bring up the context menu. not when I make the selection.

Link to comment
Share on other sites

 

 

so if the progress bar appears, the TA works, but the :perform function in the TA is not working.

But why is there a progress bar for adding items to the context menu? that confuses me a bit..

 

 

Anyway, can you post the code for the :perform function?

 

Trust me, I am just as confused...

 

function ORGMLoadAction:perform() --for performing the loading actions

    print(self.loadType)

    self.loadableData = self.loadWeapon:getModData()

    if self.loadType == "open" then --open the gun for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

    elseif self.loadableData.openClose ~= 1 and self.loadableData.openClose == 1 and self.loadableData.isOpen ~= nil and self.loadableData.isOpen ~= 1 then

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    elseif self.loadType == "reload" or self.loadType == "unload" then --if the loadType is unloading/reloading then is performs the loading action

        self.loadable:loadPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.reloadammo, self.loadType)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

        ISBaseTimedAction.perform(self)

    elseif self.loadType == "close" then --closes the gun if it is open for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    else --otherwise it must be a half-rack action

        self.loadable:halfRackPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.loadType)

        ISBaseTimedAction.perform(self)

    end

end

 

 

EDIT:

And just to reiterate the Timed Action is working but at the wrong time. It does the TA when I right click to bring up the context menu. not when I make the selection.

 

 

 

AAH, I totally missed that bit. I also found the issue due to this:

 

  ISTimedActionQueue.add(self.loadAction)

 

this is called from ORGMLoadManager:startLoading().

startLoading is called in startReloadFromUi.

startReloadFromUi is called here:

local reloadOption = context:addOption(reloadtexttoadd, items, ORGMLoadManager:startReloadFromUi(testItem, testMag), playerObj);

You are actually calling startReloadFromUi here and using its RETURN value as the third parameter to context:addOption. I'm not 100% sure how to pass options to the function in there, but something like this might work:

local reloadOption = context:addOption(reloadtexttoadd, ORGMLoadManager, ORGMLoadManager.startReloadFromUi, testItem, testMag);

Note the . before startReloadFromUi instead of the : that was there before.

 

Hope that helps!

Link to comment
Share on other sites

 

 

 

so if the progress bar appears, the TA works, but the :perform function in the TA is not working.

But why is there a progress bar for adding items to the context menu? that confuses me a bit..

 

 

Anyway, can you post the code for the :perform function?

 

Trust me, I am just as confused...

 

function ORGMLoadAction:perform() --for performing the loading actions

    print(self.loadType)

    self.loadableData = self.loadWeapon:getModData()

    if self.loadType == "open" then --open the gun for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

    elseif self.loadableData.openClose ~= 1 and self.loadableData.openClose == 1 and self.loadableData.isOpen ~= nil and self.loadableData.isOpen ~= 1 then

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    elseif self.loadType == "reload" or self.loadType == "unload" then --if the loadType is unloading/reloading then is performs the loading action

        self.loadable:loadPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.reloadammo, self.loadType)

        self.mgr.loadable = self.loadable

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

        ISBaseTimedAction.perform(self)

    elseif self.loadType == "close" then --closes the gun if it is open for reloading

        self.loadable:openClosePerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon)

        self.mgr.loadable = self.loadable

        ISBaseTimedAction.perform(self)

        self.mgr:stopLoadSuccess() --a check to see if the gun can continue after the first action

    else --otherwise it must be a half-rack action

        self.loadable:halfRackPerform(self.character, self.square, self.mgr:getDifficulty(), self.loadWeapon, self.loadType)

        ISBaseTimedAction.perform(self)

    end

end

 

 

EDIT:

And just to reiterate the Timed Action is working but at the wrong time. It does the TA when I right click to bring up the context menu. not when I make the selection.

 

 

 

AAH, I totally missed that bit. I also found the issue due to this:

 

  ISTimedActionQueue.add(self.loadAction)

 

this is called from ORGMLoadManager:startLoading().

startLoading is called in startReloadFromUi.

startReloadFromUi is called here:

local reloadOption = context:addOption(reloadtexttoadd, items, ORGMLoadManager:startReloadFromUi(testItem, testMag), playerObj);

You are actually calling startReloadFromUi here and using its RETURN value as the third parameter to context:addOption. I'm not 100% sure how to pass options to the function in there, but something like this might work:

local reloadOption = context:addOption(reloadtexttoadd, ORGMLoadManager, ORGMLoadManager.startReloadFromUi, testItem, testMag);

Note the . before startReloadFromUi instead of the : that was there before.

 

Hope that helps!

 

 

I think that got me where I needed to go! Onto the next stack trace lol

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...