Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
# 3D /me
A FiveM script written in LUA that implements the /me command with 3D printing.
# Standalone 3D /me & /do command
# Creds @Eblio modified @n0tst3
A FiveM script written in LUA that implements the /me & /do command with 3D printing.

## ME Command
The /me command allows you to display a specific action above the head of a player. It's particularly used for actions that couldn't have been done in game in a roleplay context.
example: /me waves

<img src=https://imgur.com/lJZbcGA.png>
<img src=https://i.imgur.com/MfjAHdw.png>

## DO Command
The /do command is used primarily in serious roleplay servers and is used to describe something in your enviroment or state a fact in roleplay. It is also used if you want to ask something roleplay wise.
example: /do is the door open?

<img src=https://i.imgur.com/tdysqaj.png>

## Installation
* Download the resource ;
* Drag and drop it into your resources folder ;
* Add ```ensure 3dme``` to your server configuration file.
* To Change language; Edit Config.lua > line 8
* Add ```ensure 3d-me-do``` to your server configuration file.

## How to use
* In the chat, type /me followed by your action.
* /me & /do in chat.

## Options
| Parameter | Line | Suggestion |
| --- | --- | --- |
| Color of the text | ```config.lua``` : line 6 | ```color = { r = 230, g = 230, b = 230, a = 255 }``` |
| Font of the text | ```config.lua``` : line 7 | ```font = 0``` ([available fonts](https://imgur.com/a/oV3ciWs)) |
| Time on screen | ```config.lua``` : line 8 | ```time = 5000``` |
| Language | ```config.lua``` : line 4 | ```language = 'en'``` |

## Updates
To see the previous changelogs, please refer to the [FiveM forum post](https://forum.cfx.re/t/release-me-but-the-text-is-3d-printed/).

#### V3.0
* A lot of refactoring ;
* Some major optimizations ;
* Multiple `/me` do not stack anymore but get replaced ;
## n0tst3 edit
Added de lang, trans for do command
Added /do for a more immersive rp experience

## Note
* This may not work if are you using a custom chat resource ;
* This could conflict with other /me scripts (disable them) ;
* This script is fully standalone.
70 changes: 31 additions & 39 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,88 +1,80 @@
-- @desc Client-side /me handling
-- @author Elio
-- @version 3.0
-- edit by n0tst3
local Config = Config
local Languages = Languages
local c, lang = Config, Languages[Config.language]

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 function displayText(ped, text, yOffset)
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
text = text,
yOffset = yOffset
}

if not exists then
local display = true
if not peds[ped].exists then
peds[ped].exists = 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
Citizen.CreateThread(function()
while GetGameTimer() <= peds[ped].time do
local pos = GetOffsetFromEntityInWorldCoords(ped, 0.0, 0.0, peds[ped].yOffset)
draw3dText(pos, peds[ped].text)
Citizen.Wait(0)
end

peds[ped] = nil
peds[ped] = nil
end)
end
end
end

local function onDoShareDisplay(text, target)
local player = GetPlayerFromServerId(target)
if player ~= -1 or target == GetPlayerServerId(PlayerId()) then
local ped = GetPlayerPed(player)
displayText(ped, "~b~* " .. lang.doPrefix .. text .. " ", 0.45)
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 function onMeShareDisplay(text, target)
local player = GetPlayerFromServerId(target)
if player ~= -1 or target == GetPlayerServerId(PlayerId()) then
local ped = GetPlayerPed(player)
displayText(ped, text)
displayText(ped, "~r~** " .. lang.mePrefix .. text .. " **", 0.7)
end
end

-- Register the event
RegisterNetEvent('3dme:shareDisplay', onShareDisplay)
RegisterNetEvent('3ddo:shareDisplay', onDoShareDisplay)
RegisterNetEvent('3dme:shareDisplay', onMeShareDisplay)

-- Add the chat suggestion
TriggerEvent('chat:addSuggestion', '/' .. lang.commandName, lang.commandDescription, lang.commandSuggestion)
TriggerEvent('chat:addSuggestion', '/' .. lang.doCommandName, lang.doCommandDescription, lang.doCommandSuggestion)
TriggerEvent('chat:addSuggestion', '/' .. lang.meCommandName, lang.meCommandDescription, lang.meCommandSuggestion)
50 changes: 37 additions & 13 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
-- edit by n0tst3
-- @desc Shared config file
-- @author Elio
-- @version 2.0

-- Global configuration
Config = {
language = 'en',
language = 'de',
color = { r = 230, g = 230, b = 230, a = 255 }, -- Text color
font = 0, -- Text font
time = 5000, -- Duration to display the text (in ms)
Expand All @@ -15,21 +16,44 @@ Config = {
-- Languages available
Languages = {
['en'] = {
commandName = 'me',
commandDescription = 'Display an action above your head.',
commandSuggestion = {{ name = 'action', help = '"scratch his nose" for example.'}},
prefix = 'the person '
doCommandName = 'do',
doCommandDescription = 'Describe or respond in roleplay.',
doCommandSuggestion = {{ name = 'action', help = '"Is the door open??" for example.'}},
doPrefix = ' ' , -- Add prefix if required. i.e "The Person"
meCommandName = 'me',
meCommandDescription = 'Displays an action or emote your character is performing.',
meCommandSuggestion = {{ name = 'action', help = '"shoves his hand in his back pocket" for example.'}},
mePrefix = ' ' -- Add prefix if required. i.e "The Person"
},
['fr'] = {
commandName = 'me',
commandDescription = 'Affiche une action au dessus de votre tête.',
commandSuggestion = {{ name = 'action', help = '"se gratte le nez" par exemple.'}},
prefix = 'l\'individu '
doCommandName = 'do',
doCommandDescription = 'Décrivez ou répondez dans le jeu de rôle..',
doCommandSuggestion = {{ name = 'action', help = '"La porte est-elle ouverte??" par exemple.'}},
doPrefix = ' ' , -- Add prefix if required. i.e "The Person"
meCommandName = 'me',
meCommandDescription = 'Affiche une action ou une emote que votre personnage effectue.',
meCommandSuggestion = {{ name = 'action', help = '"met sa main dans sa poche arrièret" par exemple.'}},
mePrefix = ' ' -- Add prefix if required. i.e "The Person"
},
['de'] = {
doCommandName = 'do',
doCommandDescription = 'Beschreiben oder antworten Sie im Rollenspiel.',
doCommandSuggestion = {{ name = 'action', help = '"Ist die Tür offen??" zum Beispiel.'}},
doPrefix = ' ' , -- Add prefix if required. i.e "The Person"
meCommandName = 'me',
meCommandDescription = 'Zeigt eine Aktion oder ein Emote an, das Ihr Charakter ausführt.',
meCommandSuggestion = {{ name = 'action', help = '"schiebt seine Hand in seine Gesäßtasche" zum Beispiel.'}},
mePrefix = ' ' -- Add prefix if required. i.e "The Person"
},
['dk'] = {
commandName = 'me',
commandDescription = 'Viser en handling over hovedet.',
commandSuggestion = {{ name = 'Handling', help = '"Tager en smøg op ad lommen" for eksempel.'}},
prefix = 'Personen '
doCommandName = 'do',
doCommandDescription = 'Beskriv eller svar i rollespil',
doCommandSuggestion = {{ name = 'action', help = '"Er døren åpen?" For eksempel.'}},
doPrefix = ' ' , -- Add prefix if required. i.e "The Person"
meCommandName = 'me',
meCommandDescription = 'Viser en handling eller følelse karakteren din utfører',
meCommandSuggestion = {{ name = 'action', help = '"dytter hånden i baklommen" For eksempel.'}},
mePrefix = ' ' -- Add prefix if required. i.e "The Person"
},
}

8 changes: 5 additions & 3 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
fx_version 'cerulean'
game 'gta5'

author 'Elio'
description '/me command but it\'s 3D printed'
version '3.0'
author '@Elio - Edit @n0tst3'
description '/me command with /do '
version '3.1 n0tst3 edit'

shared_script 'config.lua'
client_script 'client.lua'
server_script 'server.lua'

lua54 'yes'
21 changes: 13 additions & 8 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
-- @desc Server-side /me handling
-- @author Elio
-- @version 3.0

-- edit by n0tst3
-- Pre-load the language
local Config = Config
local Languages = Languages
local lang = Languages[Config.language]

-- @desc Handle /me command
local function onDoCommand(source, args)
local text = table.concat(args, " ")
TriggerClientEvent('3ddo:shareDisplay', -1, text, source)
end

local function onMeCommand(source, args)
local text = "* " .. lang.prefix .. table.concat(args, " ") .. " *"
local text = table.concat(args, " ")
TriggerClientEvent('3dme:shareDisplay', -1, text, source)
end

-- Register the command
RegisterCommand(lang.commandName, onMeCommand)
-- Register the commands
RegisterCommand(lang.doCommandName, onDoCommand)

RegisterCommand(lang.meCommandName, onMeCommand)