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


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