TGRHavoc / live_map

A FiveM addon for live maps
https://docs.tgrhavoc.co.uk/livemap-resource/
59 stars 38 forks source link

Add dynamic blips #71

Open matsn0w opened 2 years ago

matsn0w commented 2 years ago

Is your feature request related to a problem? Please describe. We're building an online system for police roleplay that allows dispatchers to create a callout on a certain position on the map. When a callout is created, the players see this callout as a blip on their (in-game) map. A GPS route is created for them on the fly. We'd like to add these blip to the live map too.

Describe the solution you'd like It would be nice if it was possible to add and remove blips on the fly.

Describe alternatives you've considered I can add a blip with /blip, but this is only working after a restart of the resource.

TGRHavoc commented 2 years ago

Ooof, looks like I haven't documented the event...

There's an event called livemap:AddBlip on the server that takes a blip object as it's parameter. This should add a blip to the interface when it's called (as well as adding it to the blips.json file). It's a "static" blip (i.e it won't move like player's blips do) but, sounds like it could be what you're looking for.

The blip object is defined as

    A blip follows the format:
    {
        sprite = Number (required)

        pos = Table (required){
            x = Float (required)
            y = Float (required)
            z = Float (required)
        }

        name = String (optional)
        description = String (optional)
    }
matsn0w commented 2 years ago

Hi, thank you for pointing out, but I already discovered that. Except, it's not working :( I tought that it wasn't possible like so.

It's kinda weird. I add a blip like this when a callout is created:

client.lua

-- create a blip object for the live map
local live_map_blip = {
    name = "Callout",
    description = name,
    sprite = 61,
    pos = {
        x = x,
        y = y,
        z = 0
    }
}

TriggerServerEvent('livemap:AddBlip', live_map_blip)

It's not showing up on the map. When I refresh the blips via the controls menu, the new blip shows up in blips.json, but doesn't appear on the map... See screenshot:

image

For testing purposes, I haven't generated any other blips.

How are you updating the blips file? When the blip is added, it shows up in my browser console, but not in the actual file on my server? It's only there after stopping the resource lol 😀 Then when starting the resource again, the blip shows up on the map! (after a refresh of course).

I'm confused XD

Also, when switching servers (between local and production), the blips from the old server remain on the map. They disappear after a manual refresh. Will write an issue for that on the interface repo.

EDIT: https://github.com/TGRHavoc/live_map-interface/issues/81

Thank you for your incredible speedy support these days, it really helps :)

BTW, do you have a list of supported sprites?

TGRHavoc commented 2 years ago

When the blip is added, it shows up in my browser console, but not in the actual file on my server?

Yeah. If I recall correctly, the blips.json file should only be written to when the resource is stopped. It should appear on the interface as soon as it's created though.... It might a an issue on the interface, not sure. I'll have to have a look when I get some more free time (just had a bunch of tasks for work come through). Thanks for the interface issue, must have not implemented the whole "remove all blips when switching servers" logic that I had before the refactor :)

Thank you for your incredible speedy support these days, it really helps :) And thank you for the detailed bug reports. Some people don't use the template and expect me to work miracles.

As for sprites for the blips: https://github.com/TGRHavoc/live_map-interface/blob/develop/js/src/markers.js#L8

The "id" is what you're looking for. If a sprite doesn't have an "id" then, just add one (or however many down it is from the last one with an "id").

For example, "Store" has the id of "52".

matsn0w commented 2 years ago

Switched to adding it in server.lua:

-- create a blip object for the live map
local live_map_blip = {
    name = "Callout",
    description = name,
    sprite = 61,
    pos = {
        x = coords.x,
        y = coords.y,
        z = 0
    }
}

TriggerEvent('livemap:AddBlip', live_map_blip)

The blips now show after a manual 'refresh blips' in the interface, but is giving me a [WARN] LiveMap Sockets - Blip has no sprite...

matsn0w commented 2 years ago

As for sprites for the blips: https://github.com/TGRHavoc/live_map-interface/blob/develop/js/src/markers.js#L8

The "id" is what you're looking for. If a sprite doesn't have an "id" then, just add one (or however many down it is from the last one with an "id").

For example, "Store" has the id of "52".

Does that correspond to this?

I'm using 41 in-game (flashing red/blue), but I guess something like that isn't possible ;)

TGRHavoc commented 2 years ago

Does that correspond to this?

No, iirc, I got the blip IDs from Scripthook (https://github.com/crosire/scripthookvdotnet/blob/main/source/scripting_v3/GTA/BlipSprite.cs / https://gtamods.com/wiki/Blip_Sprite_IDs) but, removed the ones that I couldn't find on the texture sheet.

I'm using 41 in-game (flashing red/blue), but I guess something like that isn't possible ;)

Not unless you add an icon yourself (a GIF of a blue to red circle) and add the marker yourself using the ID 41 since, it's available. Tbf, It might be a good idea to make the blips on the interface use the same IDs and images as the ones documented on FiveM... I guess I would need to write a script to scrape the icons and the IDs because fuck writing that out by hand

DoJoMan18 commented 11 months ago
local live_map_blip = {
    name = "Callout",
    description = name,
    sprite = 61,
    pos = {
        x = coords.x,
        y = coords.y,
        z = 0
    }
}

TriggerEvent('livemap:AddBlip', live_map_blip)

Very late comment, but did you get it working? Its seems that the blip gets written directly to the blips.json. Server console is just responding with "[WARN] LiveMap Sockets - Blip has no sprite...". Indeed, when you refresh the webpage it reloads the blips.json and therefore seems to display the blip.

DoJoMan18 commented 11 months ago

I've just removed the validBlip from the livemap.js in the FiveM resource. Browser now gives a error: https://i.imgur.com/kgXjhaS.jpeg

The code i'm using:

` local pos = GetEntityCoords(PlayerPedId(), not IsPlayerDead(PlayerId()))

    local live_map_blip = {
        name = "Callout",
        description = "test1",
        sprite = 50,
        pos = {
            x = pos.x,
            y = pos.y,
            z = pos.z
        }
    }

    TriggerServerEvent('livemap:AddBlip', live_map_blip)`