Skip to content

Commit

Permalink
feat: add utility events
Browse files Browse the repository at this point in the history
Added events to allow developers to
1. Add blipss to the map
2. Add data to players (strings and floats)
  • Loading branch information
TGRHavoc committed May 17, 2019
1 parent 0e22f14 commit cfe1843
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions live.lua
Expand Up @@ -8,8 +8,6 @@ clr.System.Reflection.Assembly.LoadFrom("resources/live_map/libs/Live Map.dll")
print("creating websocket")
local liveMap = clr.Havoc.Live_Map.LiveMap(liveMapPort, useSsl) -- Start the websocket

print("nil :" .. (liveMap == nil))

-- When the resource is stoped, close the websockett
AddEventHandler('onResourceStop', function(resourceName)
if resourceName == GetInvokingResource() then
Expand All @@ -19,11 +17,56 @@ end)
-- Keep the locations in the DLL up-to-date with the player's actual location
RegisterServerEvent("live_map:updatePositions")
AddEventHandler("live_map:updatePositions", function(newX, newY, newZ)
liveMap.addPlayer(GetPlayerName(source), newX, newY, newZ) -- Adds or updates the player's location
local ids = GetPlayerIdentifiers(source)
--[[
below could be written as
liveMap.addFloat(ids[1], newX)
liveMap.addFloat(ids[1], newY)
liveMap.addFloat(ids[1], newZ)
]]
liveMap.addPlayer(ids[1], GetPlayerName(source), newX, newY, newZ) -- Adds or updates the player's location
end)

RegisterServerEvent("live_map:addBlip")
AddEventHandler("live_map:addBlip", function(blipName, blipDesc, blipType, x, y, z)
print("checking type: " .. type(blipType))

if type(blipType) ~= "string" and type(blipType) == "number" then
print("blipType " .. blipType .. " is a number.. Converting")
blipType = BLIP_IDS[blipType]
end
-- blipType should now be a string we can use..
print("live_map: Adding blip to map. Name=\"".. blipName .. "\", type=\"" .. blipType .. "\"")
liveMap.addBlip(blipName, blipDesc, blipType, x, y, z)
end)

RegisterServerEvent("live_map:clientAddString")
AddEventHandler("live_map:clientAddString", function(key, s)
TriggerEvent("live_map:addString", source, key, s)
end)
RegisterServerEvent("live_map:clientAddFloat")
AddEventHandler("live_map:clientAddFloat", function(key, f)
TriggerEvent("live_map:addFloat", source, key, f)
end)

AddEventHandler("live_map:addString", function(plrId, key, s)
local ids = GetPlayerIdentifiers(plrId)

print("live_map: Adding string with key \"" .. key .. "\" and val of \"" .. s .. "\"")
liveMap.addPlayerString(ids[1], key, s)
end)

AddEventHandler("live_map:addFloat", function(plrId, key, f)
local ids = GetPlayerIdentifiers(plrId)
print("id: " .. ids[1])
print("live_map: Adding float with key \"" .. key .. "\" and val of \"" .. f .. "\"")
liveMap.addPlayerFloat(ids[1], key, f)
end)

-- When a player disconnects, make sure the websocket knows..
AddEventHandler("playerDropped", function()
liveMap.removePlayer(GetPlayerName(source))
local ids = GetPlayerIdentifiers(source)
liveMap.removePlayer(ids[1])
end)

-- Send the blips from blips.lua to the DLL.
Expand Down

0 comments on commit cfe1843

Please sign in to comment.