Advertisement
Kiminaze

MarkerManager Docs / Example

Dec 29th, 2020 (edited)
1,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.24 KB | None | 0 0
  1. --[[
  2.     -------------------- MarkerManager Documentation and Example by Kiminaze --------------------
  3.  
  4.     Here you can find a complete documentation of what is possible with the MarkerManager.
  5.  
  6.     At the bottom you can find an example on how you could use it.
  7.  
  8.     Installation Instructions:
  9.         Put this folder somewhere in your resources-folder and put "start MarkerManager" into your
  10.         server.cfg. It should be ABOVE all scripts that use the MarkerManager. Other than that,
  11.         there are no dependencies and you can put it anywhere.
  12.         If you want to also see the example below ingame, you need to uncomment the line from the
  13.         fxmanifest.lua.
  14.  
  15.         If you want debug messages in the console: Go into the config.ini and set debugMode from
  16.         false to true.
  17.  
  18.     Critical Information:
  19.         Make sure to use names that can easily be distinguished for your markers! No marker should
  20.         have the same name! The newest one with the same name WILL override the last one. There is
  21.         also a debug message in the console if that should happen.
  22.         You could call them "ScriptName:FunctionName" (e.g. "GarageScript:SpawnVehicle",
  23.         "PoliceJob:OpenBossMenu" or "Racing:StartRace")
  24.  
  25.         If you want to also delete the markers when the script is stopped, you need to delete them
  26.         manually. The easiest way is to delete them in the EventHandler for "onResourceStop".
  27.         (see at the end of this script for an example)
  28.  
  29.         If you registered a marker with a function, make sure you also have an event with the SAME
  30.         name!
  31.  
  32.  
  33.  
  34.     List of all available events with their parameters (you can directly copy these into your
  35.     Lua-scripts and replace the variables):
  36.  
  37.     -- registers a new marker
  38.         TriggerEvent("MarkerManager:Register",
  39.             name,               -- string:  name of the marker (must be individual!)
  40.             viewDistance,       -- float:   view distance of the marker (in units / meters)
  41.             markerType,         -- int:     type id of the marker
  42.             position,           -- vector3: position of the marker
  43.             scale,              -- vector3: scale of the marker
  44.             color               -- vector4: color of the marker (Format: RGBA)
  45.         )
  46.  
  47.     -- registers a new marker but without the visual component (make sure to also register a function after this)
  48.         TriggerEvent("MarkerManager:RegisterNoMarker",
  49.             name,               -- string:  name of the interaction point (must be individual!)
  50.             position,           -- vector3: position of the interaction point
  51.             radius              -- float:   the radius of the interaction point
  52.         )
  53.  
  54.     -- register a new, advanced marker
  55.         TriggerEvent("MarkerManager:RegisterAdvanced",
  56.             name,               -- string:  name of the marker (must be individual!)
  57.             viewDistance,       -- float:   view distance of the marker (in meters)
  58.             markerType,         -- int:     type id of the marker
  59.             position,           -- vector3: position of the marker
  60.             rotation,           -- vector3: rotation of the marker
  61.             scale,              -- vector3: scale of the marker
  62.             color,              -- vector4: color of the marker (Format: RGBA)
  63.             bobUpAndDown,       -- bool:    should the marker bob up and down? (true / false)
  64.             faceCamera,         -- bool:    should the marker face the camera? (true / false)
  65.             rotating            -- bool:    should the marker be rotating? (true / false)
  66.         )
  67.  
  68.     -- deletes a marker
  69.         TriggerEvent("MarkerManager:Delete",
  70.             name                -- string:  name of the marker that should be deleted
  71.         )
  72.  
  73.     -- adds a function to an existing marker with a button press
  74.         TriggerEvent("MarkerManager:AddFunction",
  75.             name,               -- string:  name of the marker that should trigger this event
  76.             eventName,          -- string:  the name of the event that should be triggered when the button is pressed
  77.             helpText,           -- string:  the help text in the top left corner of the screen
  78.             button              -- int:     the button to press to execute the function
  79.         )
  80.        
  81.     -- adds a function to an existing marker that gets automatically triggered, when a player enters the marker
  82.         TriggerEvent("MarkerManager:AddEnterFunction",
  83.             name,               -- string:  name of the marker that should trigger this event
  84.             eventName           -- string:  the name of the event that should be triggered when the player enters
  85.         )
  86.        
  87.     -- adds a function to an existing marker that gets automatically triggered, when a player exits the marker
  88.         TriggerEvent("MarkerManager:AddExitFunction",
  89.             name,               -- string:  name of the marker that should trigger this event
  90.             eventName           -- string:  the name of the event that should be triggered when the player exits
  91.         )
  92.  
  93.     -- attaches an existing marker to an entity
  94.         TriggerEvent("MarkerManager:AttachToEntity",
  95.             name,               -- string:  the name of the marker that should be attached to an entity
  96.             entityId,           -- int:     the id of the entity
  97.             offset              -- vector3: the offset in relations to the entity as a vector3
  98.         )
  99.  
  100.     -- detaches an existing marker from any entity it is attached to
  101.         TriggerEvent("MarkerManager:Detach",
  102.             name                -- string:  the name of the marker that should be detached from an entity
  103.         )
  104.  
  105.     -- enables or disables a marker from showing (and its function)
  106.         TriggerEvent("MarkerManager:Enable",
  107.             name                -- string:  the name of the marker that should be enabled / disabled
  108.             enable              -- bool:    should the marker be enabled or disabled (true or false)
  109.         )
  110.  
  111.     -- changes the view distance of the marker
  112.         TriggerEvent("MarkerManager:ChangeViewDistance",
  113.             name                -- string:  the name of the marker that should have its value changed
  114.             viewDistance        -- float:   the new view distance
  115.         )
  116.        
  117.     -- changes the type of the marker
  118.         TriggerEvent("MarkerManager:ChangeType",
  119.             name                -- string:  the name of the marker that should have its value changed
  120.             type                -- int:     the new marker type
  121.         )
  122.  
  123.     -- changes the position of the marker
  124.         TriggerEvent("MarkerManager:ChangePosition",
  125.             name                -- string:  the name of the marker that should have its value changed
  126.             position            -- vector3: the new position
  127.         )
  128.  
  129.     -- changes the rotation of the marker
  130.         TriggerEvent("MarkerManager:ChangeRotation",
  131.             name                -- string:  the name of the marker that should have its value changed
  132.             rotation            -- vector3: the new rotation
  133.         )
  134.  
  135.     -- changes the scale of the marker
  136.         TriggerEvent("MarkerManager:ChangeScale",
  137.             name                -- string:  the name of the marker that should have its value changed
  138.             scale               -- vector3: the new scale
  139.         )
  140.  
  141.     -- changes the color of the marker
  142.         TriggerEvent("MarkerManager:ChangeColor",
  143.             name                -- string:  the name of the marker that should have its value changed
  144.             color               -- vector4: the new color
  145.         )
  146.  
  147.     -- changes if the marker should bob up and down
  148.         TriggerEvent("MarkerManager:ChangeBobUpAndDown",
  149.             name                -- string:  the name of the marker that should have its value changed
  150.             bobUpAndDown        -- bool:    the new bob up and down behaviour
  151.         )
  152.  
  153.     -- changes if the marker should face the camera
  154.         TriggerEvent("MarkerManager:ChangeFaceCamera",
  155.             name                -- string:  the name of the marker that should have its value changed
  156.             faceCamera          -- bool:    the new face camera behaviour
  157.         )
  158.  
  159.     -- changes if the marker should be rotating
  160.         TriggerEvent("MarkerManager:ChangeRotating",
  161.             name                -- string:  the name of the marker that should have its value changed
  162.             rotating            -- bool:    the new rotating behaviour
  163.         )
  164.  
  165.        
  166.     additional information can be found here:
  167.      - markers: https://docs.fivem.net/docs/game-references/markers/
  168.      - vector3: https://docs.fivem.net/docs/scripting-reference/runtimes/lua/functions/vector3/
  169.      - vector4: https://docs.fivem.net/docs/scripting-reference/runtimes/lua/functions/vector4/
  170.      - buttons: https://docs.fivem.net/docs/game-references/controls/
  171.    
  172. ]]
  173.  
  174. -- main loop
  175. Citizen.CreateThread(function()
  176.     CreateMarker()
  177.    
  178.     local bobMarker = true
  179.     while (true) do
  180.         Citizen.Wait(0)
  181.  
  182.         -- enable / disable the bobbing marker above your characters head
  183.         if (IsControlJustReleased(0, 21 --[[ Left Shift ]])) then
  184.             bobMarker = not bobMarker
  185.             TriggerEvent("MarkerManager:Enable", "MMECharMarker", bobMarker)
  186.         end
  187.     end
  188. end)
  189.  
  190. function CreateMarker()
  191.     -- register a simple marker for parking your vehicle
  192.     TriggerEvent("MarkerManager:Register",
  193.         "MMEParkMarker",                            -- name of the marker (must be individual!)
  194.         100.0,                                      -- view distance of the marker (in units / meters)
  195.         1,                                          -- type id of the marker
  196.         vector3(212.62, -797.9, 29.87),             -- position of the marker as a vector3
  197.         vector3(3, 3, 0.5),                         -- scale of the marker as a vector3
  198.         vector4(255, 0, 0, 255)                     -- color of the marker as a vector4 (Format: RGBA)
  199.     )
  200.     -- add the delete function to the marker
  201.     TriggerEvent("MarkerManager:AddFunction",
  202.         "MMEParkMarker",                            -- name of the marker (needs to be identical to the created marker!)
  203.         "ParkCar",                                  -- the name of the event that should be triggered
  204.         "Press ~INPUT_CONTEXT~ to park your car.",  -- the help text in the top left corner of the screen
  205.         51                                          -- the button to press to execute the function
  206.     )
  207.    
  208.     -- register a simple marker for spawning a vehicle
  209.     TriggerEvent("MarkerManager:Register",
  210.         "MMESpawnMarker",                           -- name of the marker (must be individual!)
  211.         100.0,                                      -- view distance of the marker (in units / meters)
  212.         1,                                          -- type id of the marker
  213.         vector3(229.63, -799.26, 29.57),            -- position of the marker as a vector3
  214.         vector3(3, 3, 0.5),                         -- scale of the marker as a vector3
  215.         vector4(0, 255, 0, 255)                     -- color of the marker as a vector4 (Format: RGBA)
  216.     )
  217.     -- add the spawn function to the marker
  218.     TriggerEvent("MarkerManager:AddFunction",
  219.         "MMESpawnMarker",                           -- name of the marker (needs to be identical to the created marker!)
  220.         "SpawnCar",                                 -- the name of the event that should be triggered
  221.         "Press ~INPUT_CONTEXT~ to spawn a car.",    -- the help text in the top left corner of the screen
  222.         51                                          -- the button to press to execute the function
  223.     )
  224.  
  225.     -- register a simple marker for teleporting the player (on enter)
  226.     TriggerEvent("MarkerManager:Register",
  227.         "MMETeleportMarker",
  228.         50.0,
  229.         1,
  230.         vector3(213.71, -809.16, 30.01),
  231.         vector3(3, 3, 0.5),
  232.         vector4(255, 255, 0, 255)
  233.     )
  234.     -- add the teleport function to the marker
  235.     TriggerEvent("MarkerManager:AddEnterFunction",
  236.         "MMETeleportMarker",
  237.         "TeleportPlayer"
  238.     )
  239.    
  240.     -- register a simple marker for showing the player an exit message (on exit)
  241.     TriggerEvent("MarkerManager:Register",
  242.         "MMEPlayerExitArea",
  243.         50.0,
  244.         1,
  245.         vector3(230.28, -811.99, 29.43),
  246.         vector3(3, 3, 0.5),
  247.         vector4(0, 0, 255, 255)
  248.     )
  249.     -- add the teleport function to the marker
  250.     TriggerEvent("MarkerManager:AddExitFunction",
  251.         "MMEPlayerExitArea",
  252.         "PlayerExitedArea"
  253.     )
  254.  
  255.     -- wait for player spawn
  256.     Citizen.Wait(5000)
  257.    
  258.     -- register an advanced marker that hovers over the player
  259.     TriggerEvent("MarkerManager:RegisterAdvanced",
  260.         "MMECharMarker",                            -- name of the marker (must be individual!)
  261.         100.0,                                      -- view distance of the marker (in meters)
  262.         0,                                          -- type id of the marker
  263.         vector3(0, 0, 0),                           -- position of the marker as a vector3
  264.         vector3(0, 0, 0),                           -- rotation of the marker as a vector3
  265.         vector3(0.25, 0.25, 0.25),                  -- scale of the marker as a vector3
  266.         vector4(255, 255, 255, 255),                -- color of the marker as a vector4 (Format: RGBA)
  267.         true,                                       -- bob up and down set to true
  268.         false,                                      -- should the marker face the camera?
  269.         false                                       -- should the marker be rotating?
  270.     )
  271.     -- attach the marker to the player ped
  272.     TriggerEvent("MarkerManager:AttachToEntity",
  273.         "MMECharMarker",                            -- the name of the marker (needs to be identical to the created marker!)
  274.         PlayerPedId(),                              -- the id of the entity
  275.         vector3(0, 0, 1.5)                          -- the offset in relations to the entity as a vector3
  276.     )
  277. end
  278.  
  279. -- event handler for the "ParkCar" function
  280. AddEventHandler("ParkCar", function()
  281.     local playerPed = PlayerPedId()
  282.     local vehicle = GetVehiclePedIsIn(playerPed)
  283.    
  284.     if (vehicle ~= 0) then
  285.         SetEntityAsMissionEntity(vehicle)
  286.         DeleteVehicle(vehicle)
  287.     end
  288. end)
  289.  
  290. -- event handler for the "SpawnCar" function
  291. AddEventHandler("SpawnCar", function()
  292.     local playerPed = PlayerPedId()
  293.     local coords    = GetEntityCoords(playerPed, true)
  294.     local head      = GetEntityHeading(playerPed)
  295.    
  296.     local model = `banshee`
  297.     RequestModel(model)
  298.     while not HasModelLoaded(model) do
  299.         Citizen.Wait(1)
  300.     end
  301.     local vehicle = CreateVehicle(model, 229.63, -799.26, 29.57, 156, true, false)
  302.     SetModelAsNoLongerNeeded(model)
  303.     SetVehicleOnGroundProperly(vehicle)
  304.        
  305.     SetPedIntoVehicle(playerPed, vehicle, -1)
  306.     SetVehicleEngineOn(vehicle, true, true)
  307. end)
  308.  
  309. -- event handler for the "TeleportPlayer" function
  310. AddEventHandler("TeleportPlayer", function()
  311.     local playerPed = PlayerPedId()
  312.  
  313.     SetEntityCoords(PlayerPedId(), 213.98, -808.8, 33.92)
  314. end)
  315.  
  316. -- event handler for the "PlayerExitedArea" function
  317. AddEventHandler("PlayerExitedArea", function()
  318.     SetNotificationTextEntry('STRING')
  319.     AddTextComponentSubstringPlayerName("Player left marker!")
  320.     DrawNotification(false, true)
  321. end)
  322.  
  323. -- event handler for removing all markers when the resource stops
  324. AddEventHandler("onResourceStop", function(resName)
  325.     if (resName == GetCurrentResourceName()) then
  326.         TriggerEvent("MarkerManager:Delete", "MMEParkMarker")
  327.         TriggerEvent("MarkerManager:Delete", "MMESpawnMarker")
  328.         TriggerEvent("MarkerManager:Delete", "MMECharMarker")
  329.         TriggerEvent("MarkerManager:Delete", "MMETeleportMarker")
  330.     end
  331. end)
  332.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement