Jump to content

Mouse right clicking how to find the object?


Kenneth

Recommended Posts

It seems to me I can get non moving objects using.

local function getWorldObjectWhenRightClicking(player, context, worldObjects, test)
    print("player",player)
    print("context ",context)
    print("worldObject ",worldObjects)
    print("test ",test)
    for i, v in pairs(worldObjects) do
        print("i ",i, " v ",v)
        v:removeFromSquare()
    end
end
Events.OnFillWorldObjectContextMenu.Add(getWorldObjectWhenRightClicking)
 
But I can't find the vehicle. Even when I click on zombie it doesn't remove the zombie.
Edited by Kenneth
Link to comment
Share on other sites

1 hour ago, Kenneth said:

It seems to me I can get non moving objects using.

local function getWorldObjectWhenRightClicking(player, context, worldObjects, test)
    print("player",player)
    print("context ",context)
    print("worldObject ",worldObjects)
    print("test ",test)
    for i, v in pairs(worldObjects) do
        print("i ",i, " v ",v)
        v:removeFromSquare()
    end
end
Events.OnFillWorldObjectContextMenu.Add(getWorldObjectWhenRightClicking)
 
But I can't find the vehicle. Even when I click on zombie it doesn't remove the zombie.

 

It's because vehicles are no iso objects due to their special character. Since worldObjects will only contain isoObjects, it won't contain any vehicles, even if vehicles have a defined base square.

I didn't made much with vehicles, but as far is I know the usual way is to use IsoCell:getVehicles() which will give you a ArrayList of all vehicles on the cell object.

 

For example you could do:

local function getWorldObjectWhenRightClicking(player, context, worldObjects, test)
  local oPlayer = getSpecificPlayer(player)
  local oCell = oPlayer:getCell()
  local aVehicles = oCell:getVehicles()
  local square

  for _,v in pairs(worldObjects) do
    square = v:getSquare()
    break
  end

  for i=0, aVehicles:size() - 1 do
    local oVehicle = aVehicles:get(i)
    local oVehiclesBaseSquare = oVehicle:getSquare()
    if oVehiclesBaseSquare == square then
      if isClient() then
        sendClientCommand(oPlayer, 'vehicle', 'remove', { vehicle = oVehicle:getId() })
      else
        oVehicle:permanentlyRemove()
      end
      print('removed vehicle: ' .. tostring(oVehicle))
      break
    end
  end
end

Events.OnFillWorldObjectContextMenu.Add(getWorldObjectWhenRightClicking)

 

This is quick and dirty of and not failsafe yet.

And honestly, idk whether this is the proper way to do that, but as first solution at least it works.

 

 

// Edit: Just took a quick look how TIS did this for the debug menu. You can use the ObjectPicker for that. Didn't even think at it.

vehicle = IsoObjectPicker.Instance:PickVehicle(getMouseXScaled(), getMouseYScaled())
Edited by stuck1a
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...