meta-hub / fivem-target

Mostly re-written version of bt-target.
15 stars 7 forks source link

More examples #1

Closed benzon closed 3 years ago

benzon commented 3 years ago

Could you provice more info on how to work with the diffent poly zones ex.

PolyZone CircleZone BoxZone EntityZone ComboZone

Is the ones im thinking about more specific

meta-hub commented 3 years ago

Currently only polyzone is supported, will be adding support for the rest some time soon.

With this version, you must create the zone from your script:

local polyZone = PolyZone:Create(points,{
  name="test_poly",
  minZ=minZ,
  maxZ=maxZ,
  debugGrid=true,
  gridDivisions=25
})

We then create a set of target options for this polyzone:

onInteract = function(targetName,optionName,vars,entityHit)
  print("Interacted with ",targetName,optionName)
end

local targetOptions = {
  name = "test_target",
  label = "Test Target",
  icon = "fas fa-home",
  inside = false,
  onInteract = onInteract,
  options = {
    {
      name = "test_option",
      label = "Test Option"
    }
  }
}

When the AddPolyZone export is called, it will pass back a function:

local setInside = exports["fivem-target"]:AddPolyZone(targetOptions)

This function is responsible for allowing fivem-target to know whether the player is inside the polyzone, and whether or not this target can be interacted with via the menu. We call it any time the player has entered the polyzone:

polyZone:onPointInOut(PolyZone.getPlayerPosition,setInside)

I'm aware the system is not as straightforward as the original bt-target, but it was the most efficient way I could think of to allow the calling script access to the polyzones methods.

benzon commented 3 years ago

Okay - it's always about what is most efficient and performance friendly no doubt