Jump to content
nolanri

Add a context option for right clicking on player

Recommended Posts

Spoiler

SleepInCars.doMenu = function(player, context, items)
    
    for i,v in ipairs(items) do
        local tempitem = v;
        if not instanceof(v, "InventoryItem") then
            tempitem = v.items[1];
        end
        if (tempitem:getModData().isCar == true) then
            context:addOption("Sleep in this Vehicle", worldobjects, SleepInCars.onSleep, player, sleep);
        end
    
    end
    
    
end
SleepInCars.onSleep = function(item, player)
    local playerObj = getSpecificPlayer(player);
    if(item ~= nil) then setGcar(item) end;
    DriveCarsSaveBodyDamage(playerObj);
    ISTimedActionQueue.clear(playerObj)
    ISWorldObjectContextMenu.onSleepWalkToComplete(player)
end

Events.OnFillInventoryObjectContextMenu.Add(SleepInCars.doMenu);

 

I have made a context menu entry for inventory items. But now i need to add right click context menu for right click on players, Is there an event similar to this but for players?

Share this post


Link to post
Share on other sites

You're just inserting a item into the right click context menu if the area clicked contains a player. That doesn't need to be done in Java, as EUDOXIO tried to point out.

 

Look at ISWorldObjectContextMenu.lua and see how the medical check panel is called.

Share this post


Link to post
Share on other sites

Well i dont really know lua or java, and so many year now since i did some programming, but the bases are kinda the same, so thanks Bot, for naming what i was pointing out :D

Edited by EUDOXIO

Share this post


Link to post
Share on other sites

I still have a problem though. since ISWorldObjectContextMenu already creates a menu when you right click on the ground.  I can't just create a new menu, but i have to add to that menu that gets created. 

In my code in first post for item context menu, this uses an event that returns the context object. 

So I dont know how I can fetch the context menu object that gets created on right clicks on the ground so that I can add an option to it.

Share this post


Link to post
Share on other sites

Take a look at ISBuildMenu.lua to see how the game handles populating this menu. It uses this event: Events.OnFillWorldObjectContextMenu.Add(blarg:arg) which provides the menu as a parameter. New items and sub-menus can then be added to it when it's called.

Share this post


Link to post
Share on other sites
12 minutes ago, Butter Bot said:

Take a look at ISBuildMenu.lua to see how the game handles populating this menu:

 

 


 

function blarg.arg(player, context, worldobjects, test)

 

base_menu =  context:addOption("Option name", worldobjects, nil)

. . .

 

end

 

Events.OnFillWorldObjectContextMenu.Add(blarg.arg)

 

I am now a believer that you are who you say you are.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...