{"slug":"objects/composites","category":"objects","title":"Composites","kind":"markdown","intro":"","body":"## COMPOSITES\n\nComposites are scenarios for herb pickup.\n\n## Example of using:\n```lua\n-- COMPOSITES ARE SCENARIOS FOR HERB PICKUP.\n\nlocal composite_scenario_id = -1\nlocal composite_coords_x = 0\nlocal composite_coords_y = 0\nlocal composite_coords_z = 0\n\nCitizen.CreateThread(function()\n    while true do\n        Citizen.Wait(0)\n        if Citizen.InvokeNative(0x91AEF906BCA88877,0, 0x17BEC168) then   -- pressed E\n            local composite_name = \"COMPOSITE_LOOTABLE_EVERGREEN_HUCKLEBERRY_DEF\"\n            local composite_name_hash = GetHashKey(composite_name)\n            local ped = PlayerPedId()\n            local ped_coords = GetEntityCoords(ped)\n            local x,y,z = table.unpack(ped_coords)\n            local forward_fix = 5\n            local forwardX=GetEntityForwardX(ped)\n            local forwardY=GetEntityForwardY(ped)\n            composite_coords_x = x+(forwardX*forward_fix)\n            composite_coords_y = y+(forwardY*forward_fix)\n            composite_coords_z = z\n\n            Citizen.InvokeNative(0x73F0D0327BFA0812,composite_name_hash);  -- request COMPOSITE\n            local i = 1\n            while not Citizen.InvokeNative(0x5E5D96BE25E9DF68,composite_name_hash) and i < 500 do  -- has COMPOSITE loaded\n                i = i + 1\n                Citizen.Wait(0)\n            end\n            if Citizen.InvokeNative(0x5E5D96BE25E9DF68,composite_name_hash) then -- has COMPOSITE loaded\n                -- create COMPOSITE: herb entity and scenario attached to it\n                composite_scenario_id = Citizen.InvokeNative(0x5B4BBE80AD5972DC,composite_name_hash, composite_coords_x, composite_coords_y, composite_coords_z, 0.0, 0, Citizen.PointerValueInt(), -1,Citizen.ReturnResultAnyway())\n            end\n        end\n    end\nend)\n\n-- IF YOU CREATED TOO MANY COMPOSITES, GAME CAN BE CRUSHED. TO AVOID THIS, DONT FORGET TO DELETE UNNECESSARY SCENARIOS.\nCitizen.CreateThread(function()\n    while true do\n        Citizen.Wait(2000)\n        if composite_scenario_id ~= -1 then\n            local ped_coords = GetEntityCoords(PlayerPedId(),1,1)\n            if #(ped_coords - vector3(composite_coords_x,composite_coords_y,composite_coords_z)) > 40 then  -- if distance from ped bigger then 40 meters\n                Citizen.InvokeNative(0x5758B1EE0C3FD4AC,composite_scenario_id,0)  -- delete COMPOSITE scenario\n                composite_scenario_id = -1\n            end\n        end\n    end\nend)\n\n```","tables":[],"sourceUrl":"https://github.com/femga/rdr3_discoveries/tree/477aaaccadb7f0c042286611d9939009636cff12/objects/composites","rows":[]}