Giter Club home page Giter Club logo

meta_target's Introduction

meta_target

Release

Please report bugs, incorrect readme instructions/examples, or any other issue you might find, right here on github issues.
You can also post any missing features from other targetting resources that you would like added through github issues.

Referencing:

Add the api to your resource fxmanifest.lua: client_script '@meta_target/lib/target.lua'
NOTE: You can use exports by the same function name if you choose (as the examples.lua file does).

Api functions:

ret nil             target.addPoint           (id, title, icon, point,      radius,     onInteract, items,      vars)
ret nil             target.addModel           (id, title, icon, model,      radius,     onInteract, items,      vars)
ret table[id,...]   target.addModels          (id, title, icon, models,     radius,     onInteract, items,      vars)
ret nil             target.addNetEnt          (id, title, icon, netId,      radius,     onInteract, items,      vars)
ret nil             target.addLocalEnt        (id, title, icon, entId,      radius,     onInteract, items,      vars)
ret nil             target.addInternalPoly    (id, title, icon, points,     options,    radius,     onInteract, items,      vars)
ret nil             target.addInternalBoxZone (id, title, icon, center,     length,     width,      options,    radius,     onInteract, items, vars)
ret function        target.addExternalPoly    (id, title, icon, radius,     onInteract, items,      vars)
ret function        target.addExternalBoxZone (id, title, icon, radius,     onInteract, items,      vars)
ret nil             target.addNetEntBone      (id, title, icon, netId,      bone,       radius,     onInteract, items,      vars)
ret table[id,...]   target.addNetEntBones     (id, title, icon, netId,      bones,      radius,     onInteract, items,      vars)
ret nil             target.addLocalEntBone    (id, title, icon, entId,      bone,       radius,     onInteract, items,      vars)
ret table[id,...]   target.addLocalEntBones   (id, title, icon, entId,      bones,      radius,     onInteract, items,      vars)
ret nil             target.addModelBone       (id, title, icon, model,      bone,       radius,     onInteract, items,      vars)
ret table[id,...]   target.addModelBones      (id, title, icon, models,     bones,      radius,     onInteract, items,      vars)
ret nil             target.remove             (id, ... [,id,id])

Argument info:

REQUIRED
id          - string              (unique identifier for this target)
title       - string              (ui title label)
icon        - string              (fontawesome icon for menu title [e.g: 'fas fa-user'])
onInteract  - string OR function  (callback function or event name to trigger when an item of this target is selected)
items       - table               (table of items, more information on item structure below in this document under "Item info:")
vars        - table               (a table of any additional data you want to pass along to your callback function/event)
OPTIONAL (Based on type)
any
radius - number (distance from player to raycast endCoord to interact with this target)
point
point - vector3 (target point)
model
model - string OR hash (name or hash of model)
models
models - table (table of strings or numbers/hashes)
netEnt
netId - number (network id from NetworkGetNetworkIdFromEntity(ent))
localEnt
entId - number (id for this entity)
internalPoly
points  - table (table of vector2 points to create the polyzone with)
options - table (options for the polyzone, more information on https://github.com/mkafrin/PolyZone)
internalBoxZone
center  - vector3 (center point for box zone)
length  - number  (length of box zone)
width   - number  (width of box zone)
options - table   (options for the box zone, more information on https://github.com/mkafrin/PolyZone)
netEntBone
netId - number (network id from NetworkGetNetworkIdFromEntity(ent))
bone  - string OR hash (name or hash of bone)
netEntBones
netId - number (network id from NetworkGetNetworkIdFromEntity(ent))
bones - table (table of bone names or bone hashes)
localEntBone
entId - number (id for this entity)
bone  - string OR hash (name or hash of bone)
localEntBones
entId - number (id for this entity)
bones - table (table of bone names or bone hashes)
modelBone
model - string OR hash (name or hash of model)
bone  - string OR hash (name or hash of bone)
modelBones
model - string OR hash (name or hash of model)
bones - table (table of string OR hash (name or hash of bone))

Item info:

REQUIRED
label - string (ui label for this option)
OPTIONAL
onInteract  - string OR function  (callback function or event name to trigger when this item specifically is selected)
anything    - any                 (literally any other data you want to pass through to your callback/event)

Example use:

netEnt

  -- NOTE: This example uses a callback event per option, and a single default callback function for any others

  AddEventHandler('myscript:handsUp',function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> hands_up          Hands Up
  end)

  AddEventHandler('myscript:openInventory',function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> open_inventory    Open Inventory
  end)

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> ragdoll           Ragdoll
  end

  local networkId = NetworkGetNetworkIdFromEntity(PlayerPedId())

  target.addNetEnt('my_netEnt_target', 'Network Entity', 'fas fa-user', networkId, 10.0, onInteract, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onSelect = 'myscript:handsUp'
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onSelect = 'myscript:openInventory'
    },
    {
      name = 'ragdoll',
      label = 'Ragdoll',
    }
  },{
    foo = 'bar'
  })

localEnt

  -- NOTE: This example uses a callback function per option

  handsUp = function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_localEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> hands_up            Hands Up
  end

  openInventory = function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_localEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> open_inventory      Open Inventory
  end

  local localId = PlayerPedId()

  target.addLocalEnt('my_localEnt_target', 'Local Entity', 'fas fa-user', localId, 10.0, false, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onSelect = handsUp
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onSelect = openInventory
    },
  },{
    foo = 'bar'
  })

internalPoly

  -- NOTE: This example uses a single function callback for the entire target

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> pinkcage_target  Pink Cage
    print(itemData.name,itemData.label)     --> lock_door        Lock Door
  end

  local points = {
    vector2(328.41662597656,-189.42219543457),
    vector2(347.90512084961,-196.81504821777),
    vector2(336.11190795898,-227.95924377441),
    vector2(306.11798095703,-216.42715454102),
    vector2(314.41293334961,-194.19380187988),
    vector2(324.84567260742,-198.19834899902)
  }

  local options = {
    name="pink_cage",
    minZ=51.0,
    maxZ=62.0,
    debugGrid=false,
    gridDivisions=25
  }

  target.addInternalPoly('pinkcage_target', 'Pink Cage', 'fas fa-home', points, options, onInteract, {
    {
      name = 'lock_door',
      label = 'Lock Door'
    }
  },{
    foo = 'bar'
  })

internalBoxZone

  -- NOTE: This example uses a single function callback for the entire target

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> pinkcage_target  Pink Cage
    print(itemData.name,itemData.label)     --> lock_door        Lock Door
  end

  local center = vector3(328.41662597656,-189.42219543457,50.0000)
  local length = 20.0
  local width = 20.0

  local options = {
    name="box_zone",
    offset={0.0,0.0,0.0},
    scale={1.0,1.0,1.0}
  }

  target.addInternalPoly('pinkcage_target', 'Pink Cage', 'fas fa-home', center, length, width, options, onInteract, {
    {
      name = 'lock_door',
      label = 'Lock Door'
    }
  },{
    foo = 'bar'
  })

externalPoly

  -- NOTE: This example uses a single function callback for the entire target

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> pinkcage_target  Pink Cage
    print(itemData.name,itemData.label)     --> lock_door        Lock Door
  end

  local polyzone = PolyZone:Create({
    vector2(328.41662597656,-189.42219543457),
    vector2(347.90512084961,-196.81504821777),
    vector2(336.11190795898,-227.95924377441),
    vector2(306.11798095703,-216.42715454102),
    vector2(314.41293334961,-194.19380187988),
    vector2(324.84567260742,-198.19834899902)
  },{
    name="pink_cage",
    minZ=51.0,
    maxZ=62.0,
    debugGrid=false,
    gridDivisions=25
  })

  local setInside = target.addExternalPoly('pinkcage_target', 'Pink Cage', 'fas fa-home', onInteract, {
    {
      name = 'lock_door',
      label = 'Lock Door'
    }
  },{
    foo = 'bar'
  })

  polyzone:onPointInOut(PolyZone.getPlayerPosition,setInside,100)

externalBoxZone

  -- NOTE: This example uses a single function callback for the entire target

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> pinkcage_target  Pink Cage
    print(itemData.name,itemData.label)     --> lock_door        Lock Door
  end

  local boxzone = BoxZone:Create(vector3(123.4,345.6,678.9),20.0,20.0,{
    name="box_zone",
    offset={0.0,0.0,0.0},
    scale={1.0,1.0,1.0}
  })

  local setInside = target.addExternalBoxZone('pinkcage_target', 'Pink Cage', 'fas fa-home', onInteract, {
    {
      name = 'lock_door',
      label = 'Lock Door'
    }
  },{
    foo = 'bar'
  })

  boxzone:onPointInOut(PolyZone.getPlayerPosition,setInside,100)

modelBone

  -- NOTE: This example uses a single function callback for the entire target

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> my_buffalo_target   Buffalo
    print(itemData.name,itemData.label)     --> lock_door           Lock Door
  end

  target.addModelBone('my_buffalo_target', 'Buffalo', 'fas fa-car', GetHashKey('buffalo'), GetHashKey('chassis'), 10.0, onInteract, {
    {
      name = 'lock_door',
      label = 'Lock Door'
    }
  },{
    foo = 'bar'
  })

modelBones

  -- NOTE: This example uses a single function callback for the entire target

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> my_buffalo_target   Buffalo
    print(itemData.name,itemData.label)     --> lock_door           Lock Door
  end

  local bones = {
    'door_dside_f',
    'door_dside_r',
    'door_pside_f',
    'door_pside_r'
  }

  target.addModelBone('my_buffalo_target', 'buffalo', 'fas fa-car', GetHashKey('buffalo'), bones, 1.0, onInteract, {
    {
      name = 'lock_door',
      label = 'Lock Door'
    }
  },{
    foo = 'bar'
  })

netEntBone

  -- NOTE: This example uses a callback event per option, and a single default callback function for any others

  AddEventHandler('myscript:handsUp',function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> hands_up          Hands Up
  end)

  AddEventHandler('myscript:openInventory',function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> open_inventory    Open Inventory
  end)

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> ragdoll           Ragdoll
  end

  local networkId = NetworkGetNetworkIdFromEntity(PlayerPedId())
  local boneName = 'IK_L_Hand'

  target.addNetEntBone('my_netEnt_target', 'Network Entity', 'fas fa-user', networkId, boneName, 10.0, onInteract, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onSelect = 'myscript:handsUp'
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onSelect = 'myscript:openInventory'
    },
    {
      name = 'ragdoll',
      label = 'Ragdoll',
    }
  },{
    foo = 'bar'
  })

netEntBones

  -- NOTE: This example uses a callback event per option, and a single default callback function for any others

  AddEventHandler('myscript:handsUp',function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> hands_up          Hands Up
  end)

  AddEventHandler('myscript:openInventory',function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> open_inventory    Open Inventory
  end)

  function onInteract(targetData,itemData)
    print(targetData.name,targetData.label) --> my_netEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> ragdoll           Ragdoll
  end

  local networkId = NetworkGetNetworkIdFromEntity(PlayerPedId())
  local boneNames = {'IK_L_Hand','IK_R_Hand'}

  target.addNetEntBones('my_netEnt_target', 'Network Entity', 'fas fa-user', networkId, boneNames, 10.0, onInteract, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onSelect = 'myscript:handsUp'
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onSelect = 'myscript:openInventory'
    },
    {
      name = 'ragdoll',
      label = 'Ragdoll',
    }
  },{
    foo = 'bar'
  })

localEntBone

  -- NOTE: This example uses a callback function per option

  handsUp = function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_localEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> hands_up            Hands Up
  end

  openInventory = function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_localEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> open_inventory      Open Inventory
  end

  local localId = PlayerPedId()
  local boneName = 'IK_L_Hand'  

  target.addLocalEnt('my_localEnt_target', 'Local Entity', 'fas fa-user', localId, boneName, 10.0, false, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onSelect = handsUp
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onSelect = openInventory
    },
  },{
    foo = 'bar'
  })

localEntBones

  -- NOTE: This example uses a callback function per option

  handsUp = function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_localEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> hands_up            Hands Up
  end

  openInventory = function(targetData,itemData)
    print(targetData.name,targetData.label) --> my_localEnt_target  Network Entity
    print(itemData.name,itemData.label)     --> open_inventory      Open Inventory
  end

  local localId = PlayerPedId()
  local boneNames = {'IK_L_Hand','IK_R_Hand'}

  target.addLocalEnt('my_localEnt_target', 'Local Entity', 'fas fa-user', localId, boneNames, 10.0, false, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onSelect = handsUp
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onSelect = openInventory
    },
  },{
    foo = 'bar'
  })

vehicle

onSelect = function(targetData, itemData)
  print(targetData.name,targetData.label) --> vehicle  Vehicle
    print(itemData.name,itemData.label)   --> blow_up  Blow Up
end

-- without vars, resource and canInteract
exports["meta_target"]:addVehicle("vehicle", "Vehicle", "fas fa-car", 2.5, onSelect, {
  {
    name = "blow_up",
    label = "Blow Up"
  }
})

-- with vars, resource, canInteract
exports["meta_target"]:addVehicle("vehicle", "Vehicle", "fas fa-car", 2.5, onSelect, {
  {
    name = "blow_up",
    label = "Blow Up"
  }
}, {
  foo = "bar"
}, GetCurrentResourceName(), function(target,pos,ent,endPos,modelHash,isNetworked,netId,targetDist,entityType)
  return true
end)

remove

  target.removeTarget('pinkcage_target')

meta_target's People

Contributors

baziforyou avatar meta-hub avatar minipunch avatar senlar avatar taavi-au avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

meta_target's Issues

meta-target

converting mf-housing-v3 for meta-target, using the remove export to remove the points etc, this doesnt seem to fully work correctly, e.g I can just move from the door and it doesnt remove the options for the door, yeah the polyZone optins show up, after leaving the polyZone of the first house and creating another and going to the door it doubles up on the options, unless this is a me issue of not doing it correclty

for example

Housing.CreateTargetPoint = function(name,targetOption,targetIndex,position,vars)
  if Config.TargetOptions[targetOption] and Config.TargetOptions[targetOption][targetIndex] then
    exports["meta-target"]:addPoint({
      id = name,
      title = Config.TargetOptions[targetOption][targetIndex].label,
      icon = Config.TargetOptions[targetOption][targetIndex].icon,
      point = position,
      radius = 2.5,
      onSelect = Housing.OnInteract,
      items = Config.TargetOptions[targetOption][targetIndex].options,
      vars = vars
    })
  end
end

addPlayer doesn't work if player ped is frozen

is it just our death script or can anyone else confirm this also happens to them ?

it looks like it just doesn't detect the 'downed' person for some reason

our death script just sets their ped as just frozen with 1 health

Feature Request: Pass entity ID onSelect

Return entity ID when interacting with an entity.
Example, would like to create an interaction for any tent object so allow people to sleep in it. When onSelect fires, I need it to pass the entity back so I can get rotation and POS of entity and attach the ped to it, or teleport them inside.

addModels

Cant seem to use addModels on latest version, just doesnt seem to like models

image

polyzone issue

Just downloaded a fresh latest version of meta_target and i have been converting mf-housing-v3 to meta_target but for some reason whenever I enter the polyzone and try to target the floor or wherever, I get this error in my F8 Console

image

no example for how to use .addVehicle

I would like to be able to use this on any vehicle model without having to explicitly define it with .addModel

I see there are functions for .addVehicle in main.lua but there is no example usage in the docs

Any way we can get this added?

meta_target

Weird issue on the latest version seems to be occurring some of the time to some player and not to others, I never got it on one of my characters but got it on my second chat

I attempted to open a target and none options showed up but the eye got stuck on my screen and this error appeared, seems to do with the api function ['point']

image

multiple options showing

unsure why, on latest version I am adding models for dumpster diving and the export is the same as I had it previously and it seems to just add like 5-10 options instead of just the one, have a look at the image below

local models = {
    "prop_cs_dumpster_01a",
    "p_dumpster_t",
    "prop_snow_dumpster_01",
    "prop_dumpster_01a",
    "prop_dumpster_02a",
    "prop_dumpster_02b",
    "prop_dumpster_3a",
    "prop_dumpster_4a",
    "prop_dumpster_4b",
}

exports["meta_target"]:addModels({
    id = "dumpsters",
    title = "Dumpster",
    icon = "fas fa-dumpster",
    models = models,
    radius = 2,
    onInteract = searchDumpsterTest,
    items = {
        {
            name = "search_dumpster",
            label = "Search Dumpster"
        }
    }
})

image

Target not clearing, can still be accessed far away

So if you target something but don't click into the menu and turn off the target... then walk away and press TAB plus click your mouse quickly you can get the interaction to still show and be usable.

Press TAB to show interaction, then let go of tab without doing anything else.
image

Walk away, any distance you'd like...
Press TAB and QUICKLY CLICK LEFT MOUSE and you'll still have the last interaction option available.
image
You can click on it and it will still let you into the inventory or whatever it was.

how to open

how to open target as having issues pressing left alt dosnt open it

Job lock

There is no lock for the job any one can use it even if i have set it to a job in the qtarget zone

Add support for player targets

qtarget had support for player targets, it is useful for certain things and it would be a nice addition here.

From qtarget (https://overextended.github.io/qtarget/player)

-- Player targets
if entityType == 1 and IsPedAPlayer(entity) then
CheckEntity(hit, Players, entity, distance)
local function AddPlayer(parameters)
	local distance, options = parameters.distance or Config.MaxDistance, parameters.options
	SetOptions(Players, distance, options)
end
exports('Player', AddPlayer)

Rename to meta_target to avoid errors in exports

Using exports can lead to errors with a dash character in resource name.

exports.meta-target:addInternalBoxZone

Results in an invalid syntax error. I know there are other ways to call exports but I suggest renaming to avoid these potential issues for users.

Add support for job restrictions

Add option for job and rank restriction on the main interaction and options. Allow jobs to be sent as key value pairs with the value being the minimum rank to interact.
{ambulance = 0, police = 3}

Example: Below is a use case where there is one interaction created that has an overall restriction to only allow police or ambulance to see the interaction. Then, each interaction has further limitations.

Hands up can only be done by police, then rank matches the access rank so there are no further rank restrictions.
Open Inventory can only be done by police, but it HAS a restriction on the higher rank so only rank 3 and up can do it.
Ragdoll can only be done by ambulance job.
High Five can be done by any police or ambulance since it is restricted to just those two jobs at the top level.

If we didn't include the top level restriction, then the job restrictions would still apply on each option, but High Five could be done by anyone.

  target.addNetEnt('my_netEnt_target', 'Network Entity', 'fas fa-user', networkId, 10.0, onInteract,{police = 0, ambulance = 0}, {
    {
      name = 'hands_up',
      label = 'Hands Up',
      onInteract = 'myscript:handsUp',
      jobs = {police = 0}
    },
    {
      name = 'open_inventory',
      label = 'Open Inventory',
      onInteract = 'myscript:openInventory',
      jobs = {police = 3}
    },
    {
      name = 'ragdoll',
      label = 'Ragdoll',
      jobs = {ambulance = 0}
    },
    {
      name = 'highfive',
      label = 'High Five'
    }
  },{
    foo = 'bar'
  })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.