forked from lbphone/lb-phone-app-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
71 lines (57 loc) · 2.19 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local identifier = "react-js-template"
CreateThread(function ()
while GetResourceState("lb-phone") ~= "started" do
Wait(500)
end
local function AddApp()
local added, errorMessage = exports["lb-phone"]:AddCustomApp({
identifier = identifier,
name = "React JS",
description = "Template app using react",
developer = "Breze",
defaultApp = true, -- OPTIONAL if set to true, app should be added without having to download it,
size = 59812, -- OPTIONAL in kb
-- price = 0, -- OPTIONAL, Make players pay with in-game money to download the app
images = {"https://example.com/photo.jpg"}, -- OPTIONAL array of images for the app on the app store
ui = GetCurrentResourceName() .. "/ui/dist/index.html", -- built version
-- ui = "http://localhost:3000", -- dev version
icon = "https://cfx-nui-" .. GetCurrentResourceName() .. "/ui/icon.png"
})
if not added then
print("Could not add app:", errorMessage)
end
end
AddApp()
AddEventHandler("onResourceStart", function(resource)
if resource == "lb-phone" then
AddApp()
end
end)
local directions = {"N", "NE", "E", "SE", "S", "SW", "W", "NW"}
local oldYaw, oldDirection
RegisterNUICallback("getDirection", function(data, cb)
cb(oldDirection)
end)
while true do
Wait(25)
local yaw = math.floor(360.0 - ((GetFinalRenderedCamRot(0).z + 360.0) % 360.0) + 0.5)
if yaw == 360 then
yaw = 0
end
-- get closest direction
if oldYaw ~= yaw then
oldYaw = yaw
oldDirection = yaw .. "° " .. directions[math.floor((yaw + 22.5) / 45.0) % 8 + 1]
exports["lb-phone"]:SendCustomAppMessage(identifier, {
type = "updateDirection",
direction = oldDirection
})
end
end
end)
RegisterNUICallback("drawNotification", function(data, cb)
BeginTextCommandThefeedPost("STRING")
AddTextComponentSubstringPlayerName(data.message)
EndTextCommandThefeedPostTicker(false, false)
cb("ok")
end)