if you use the quotes the entire thing will be one argument, if you don't use them then every time a space is encountered a new argument starts so what you would do is loop the entire arguments array and add them to a single string.
Solved Using console args and commands? (Lua)
Discussion in 'Rust Development' started by LaserHydra, Mar 24, 2015.
-
When I use it in "" it just gives out the Syntax error:
Code:function PLUGIN:cmdAdminMsg(player, cmd, args) if player.net.connection.authLevel > 0 then if args.Length > 1 then local BroadcastText = tostring(args[0]) rust.SendChatMessage("LaserHydra", "ADMIN", "" .. BroadcastText) else rust.SendChatMessage(player, "ADMIN", "Syntax: /say TEXT") end else rust.SendChatMessage(player, "ADMIN", "" .. self.Config.NoPermissionMsg) end end
-
http://docs.oxidemod.org/#sendchatmessage
You are not using the rust.SendChatMessage() with the right arguments. -
Which part exactly do you mean? the , "" is because if I dont use it, it just co,bines the broadcastText with the Prefix.
Then it does not say "ADMIN: TheText"
but "ADMINTheText:"
or what do you mean?
If I replace that first SendChatMessage with a BroadcastChat without a playername it doesn't work either.
So which part do you mean? -
rust.SendChatMessage(player, name, message, userid)
rust.SendChatMessage("LaserHydra","ADMIN","".. BroadcastText)
Also you are appending "", basicly nothing, to the BroadcastText so that doesnt do anything.
If your BroadcastText is "Hello World!"
""..BroadcastText will still be "Hello World!" -
Ehm sorry i cant follow you so really... I have set the BroadcastText its the arg as you can see... Normally if im using SendChatmessage it like that im getting a Message like that:
ADMIN: HereWouldAppearTheBroadcastText
if Im using it without the ,"" it just looks like
ADMINHereWouldAppearTheBroadcastText: -
Your first SendChatMessage() function is missing a player argument. The player argument needs to be of the BasePlayer type, so using "LaserHydra" as the player argument wont work because thats a string.
-
Code:rust.BroadcastChat("ADMIN", "" .. RequestText)
RequestText is same as BroadcastText just replaced it... -
Code:
function PLUGIN:cmdAdminMsg(player, cmd, args) if player.net.connection.authLevel > 0 then if args.Length >= 1 then local BroadcastText = tostring(args[0]) rust.SendChatMessage(player, "ADMIN", BroadcastText) else rust.SendChatMessage(player, "ADMIN", "Syntax: /say TEXT") end else rust.SendChatMessage(player, "ADMIN", self.Config.NoPermissionMsg) end end
-
Now im still getting errors in this line:
Code:rust.SendChatMessage(player, "ADMIN", self.Config.NoPermissionMsg)
Code:[Oxide] 1:04 AM [Error] Failed to call hook 'cmdAdminRequest' on plugin 'AdminRequest' File: adminrequest.lua Line: 26 invalid arguments to method call: at NLua.Lua.ThrowExceptionFromError (Int32 oldTop) [0x00000] in :0 at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System.Type[] returnTypes) [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
-
Post the code where you set self.Config.NoPermissionMsg
-
Code:
function PLUGIN:LoadDefaultConfig() self.Config.NoPermissionMsg = self.Config.NoPermissionMsg or {"You have no permission to use this command!"} self:SaveConfig() end
-
Your self.Config.NoPermissionMsg is a table. You need to either make it a string and your function will work or change your function to work with a table.
-
-
-
ooookaaay ^^ Caps lock FTW
Thanks
[DOUBLEPOST=1427635948,1427588691][/DOUBLEPOST]Now if I need 2 different args? like /pm PLAYER MSG
? -
There is plenty to go off of in this thread to figure it out yourself. You will not learn if we keep handing out the code for you.
-
Yes i actually just mean the logic, to do that how is it even possible.
-
/command arg1 arg2 arg3 arg4
args[0] = arg1 from the command,
args[1] = arg2 from the command,
args[2] = arg3 from the command,
args[3] = arg4 from the command
So if you want to combine them all you would start combining from args[0] until the length of args -1. But if if your first argument is something different and you don't want it to be merged you store args[0] in a separate variable and then store everything from 1 to length - 1 in the other. -
I didn't understand that with the lenght.