[Release] Roleplay Commands

roleplay

#1

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)


[Request] Chat commands
#2

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


#3

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()


#4

oof… niceeee. Nice for your first.


#5

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()


#6
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!


#7

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


#8

If I had a nickel…


#9

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)

#10
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


#11

Updated the script to use RegisterCommand()


#12

Thanks for the advise, updated the script


#13

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:


#15

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


#16

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


#17

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.


#18

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


#19

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.


#20

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


#21

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