[Release] Roleplay Commands

Roleplay Commands
This release is a basic script that adds needed roleplay commands to the server.

Commands:

  • /911
  • /dispatch
  • /twitter
  • /ooc
  • /me

Screenshot:
Screenshot_17

Download:
Roleplay Commands.rar (1.3 KB)

2 Likes

Looks nice I’ll try it out on my test server today

Oh my.
Why are you using:

AddEventHandler('chatMessage', function(source, name, msg)
	sm = stringsplit(msg, " ");
	if sm[1] == "/911" then
		CancelEvent()
		TriggerClientEvent('chatMessage', -1, "^5911: ^0(^1" .. GetPlayerName(source) .." ^0| ^1" ..source.."^0)", { 30, 144, 255 }, string.sub(msg,5))
	end
end)

Why not use RegisterCommand()

1 Like

oof… niceeee. Nice for your first.

1 Like

This is my first script so im just starting off with some basic stuff that found and I seen how to do that before I knew of RegisterCommand() . I might convert the script to use RegisterCommand()

RegisterCommand("911", function(source, args, raw)
    if #args <= 0 then return end
    local message = args[1]
    TriggerClientEvent('chatMessage', -1, "^5911: ^0(^1" .. GetPlayerName(source) .." ^0| ^1" ..source.."^0)", { 30, 144, 255 }, message)
end)

Easy as that!

1 Like

Okay, thanks for the info on how to do it properly. Ill convert the script to use that.

If I had a nickel…

This would only print the first argument, to make it print all arguments do:

RegisterCommand("911", function(source, args, raw)
    if #args <= 0 then return end
    local message = table.concat(args, " ")
    TriggerClientEvent('chatMessage', -1, "^5911: ^0(^1" .. GetPlayerName(source) .." ^0| ^1" ..source.."^0)", { 30, 144, 255 }, message)
end)
RegisterCommand("911", function(source, args, raw)

    local message = table.concat(args, ' ')
    TriggerClientEvent('chatMessage', -1, "^5911: ^0(^1" .. GetPlayerName(source) .." ^0| ^1" ..source.."^0)", { 30, 144, 255 }, message)
end)

works as well

1 Like

Updated the script to use RegisterCommand()

1 Like

Thanks for the advise, updated the script

An even better variant, using template stuff for the default chat:

Code:

function AddRoleplayChatCommand(chatCommandName, pattern)

    local templateName = string.format("rpc_%s", chatCommandName)
    TriggerEvent('chat:addTemplate', templateName, pattern)
    
    RegisterCommand(chatCommandName, function(source, args, raw)
	    local name  = GetPlayerName(source)
	    local message = table.concat(args, ' ')
	    TriggerEvent('chat:addMessage', { templateId = templateName, multiline = true, args = { name, message } })
	end)
end

AddRoleplayChatCommand("twitter", "^5Twitter: ^0(^1{0}^0): {1}")
AddRoleplayChatCommand("ooc", "^5OOC: ^0(^1{0}^0): {1}")
AddRoleplayChatCommand("911", "^5911: ^0(^1{0}^0): {1}")
AddRoleplayChatCommand("311", "^2311: ^0(^1{0}^0): {1}")
AddRoleplayChatCommand("dispatch", "^5Dispatch: ^0(^1{0}^0): {1}")
AddRoleplayChatCommand("me", "^8{0} {1}")
AddRoleplayChatCommand("do", "^9{0} {1}")

Example:

You can even use HTML/CSS to color the text instead of resorting to the upper carret stuff, even add images and stuff :stuck_out_tongue:

6 Likes

Added To my server, worked Great!
Really good job on the script

i am trying to add something like TriggerClientEvent("sendProximityMessageDo", -1, source, name.firstname .. " " .. name.lastname, table.concat(args, " "))
into the commands like tweet as i want to use the players actual name not their steam name but i keep getting either a lua error or not able to use the tweet command itself

Well first off you don’t do -1 and source, either one or the other, -1 is for everyone to see, source is just for you. Second, to use name.firstname & name.lastname you need to define them as a variable, so something like /setname Name1 Name2 then set the according args to whatever you call the name variables.

where would i add this im new to fivem plz help me thx

What? I didn’t give you anything to add, I just told you the correct information to achieve that, unless you have a framework, then you can just grab the name from the database.

we have a create char name resource that adds to DB and we use ESX as our framework

Then just grab the info from the database assign it to a variable and use it from there.

1 Like