-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathclient.lua
More file actions
88 lines (71 loc) · 2.59 KB
/
client.lua
File metadata and controls
88 lines (71 loc) · 2.59 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- @desc Client-side /me handling
-- @author Elio
-- @version 3.0
local c = Config -- Pre-load the config
local lang = Languages[Config.language] -- Pre-load the language
local peds = {}
-- Localization
local GetGameTimer = GetGameTimer
-- @desc Draw text in 3d
-- @param coords world coordinates to where you want to draw the text
-- @param text the text to display
local function draw3dText(coords, text)
local camCoords = GetGameplayCamCoord()
local dist = #(coords - camCoords)
-- Experimental math to scale the text down
local scale = 200 / (GetGameplayCamFov() * dist)
-- Format the text
SetTextColour(c.color.r, c.color.g, c.color.b, c.color.a)
SetTextScale(0.0, c.scale * scale)
SetTextFont(c.font)
SetTextDropshadow(0, 0, 0, 0, 55)
SetTextDropShadow()
SetTextCentre(true)
-- Diplay the text
BeginTextCommandDisplayText("STRING")
AddTextComponentSubstringPlayerName(text)
SetDrawOrigin(coords, 0)
EndTextCommandDisplayText(0.0, 0.0)
ClearDrawOrigin()
end
-- @desc Display the text above the head of a ped
-- @param ped the target ped
-- @param text the text to display
local function displayText(ped, text)
local playerPed = PlayerPedId()
local playerPos = GetEntityCoords(playerPed)
local targetPos = GetEntityCoords(ped)
local dist = #(playerPos - targetPos)
local los = HasEntityClearLosToEntity(playerPed, ped, 17)
if dist <= c.dist and los then
local exists = peds[ped] ~= nil
peds[ped] = {
time = GetGameTimer() + c.time,
text = text
}
if not exists then
local display = true
while display do
Wait(0)
local pos = GetOffsetFromEntityInWorldCoords(ped, 0.0, 0.0, 1.0)
draw3dText(pos, peds[ped].text)
display = GetGameTimer() <= peds[ped].time
end
peds[ped] = nil
end
end
end
-- @desc Trigger the display of teh text for a player
-- @param text text to display
-- @param target the target server id
local function onShareDisplay(text, target)
local player = GetPlayerFromServerId(target)
if player ~= -1 or target == GetPlayerServerId(PlayerId()) then
local ped = GetPlayerPed(player)
displayText(ped, text)
end
end
-- Register the event
RegisterNetEvent('3dme:shareDisplay', onShareDisplay)
-- Add the chat suggestion
TriggerEvent('chat:addSuggestion', '/' .. lang.commandName, lang.commandDescription, lang.commandSuggestion)