1. Well,
    the title may explain the problem badly but well.
    What I want to know is, how I am able to use like, if I got a custom command which just runs like
    rust.RunServerCommand("airdrop.toplayer", playername)
    how can I set that if I put anything behind my actual /airdrop command, I am using this as the Arg "playername" or how do I even so stuff like that /airdrop is the main command and if I add a "help" for example so Im writing /airdrop help, how am i able to create those?
    Im very sorry about my well I think bad explanation because I actually don't know how to call those commands which got extra Args...
    Hope you still understand and can help me :v
    Laser
     
  2. Wulf

    Wulf Community Admin

    Code:
    rust.RunServerCommand("airdrop.toplayer \"player name\"") 
     
  3. and how to I declare the Arg i add to the /airdrop command as "player name"? :v so The Playername I use after /airdrop
    for example /airdrop LaserHydra, it should give out airdrop.toplayer LaserHydra, but if I would put in Garry it should give out airdrop.toplayer Garry
     
  4. Wulf

    Wulf Community Admin

    The argument you use depends on which hook or function you use it ib. Generally it would be player.displayName, but in some places it could be connection.username or others.
     
  5. I mean if I now got my line
    command.AddChatCommand("airdrop", self.Object, "cmdAirdrop")

    and this as function:

    Code:
    function PLUGIN:cmdAirdrop(player)
    if player.net.connection.authLevel == 0 then return end
    rust.BroadcastChat("Airdrop summoned by", player.displayName)
    rust.RunServerCommand("airdrop.player", "playername")
    end
    how can i set that it also uses the text I write after the airdrop?

    so if I use the command like that:

    /airdrop Garry

    the function is basicly just like that: (well I don't mean that It should change the "playername" to "garry" but just work as It would be - well you should really kow what I mean )
    The airdrop isnt supposed to be spawned onto the player who used the command. That would be player.displayName then if im right...
    As used for the Chat Message

    Code:
    function PLUGIN:cmdAirdrop(player)
    if player.net.connection.authLevel == 0 then return end
    rust.BroadcastChat("Airdrop summoned by", player.displayName)
    rust.RunServerCommand("airdrop.player", "Garry")
    end
     
  6. You would need to read the args argument in the function.
    cmdAirdrop(player, cmd, args)
    args contains everything written after the actual command. You then use the name and search the baseplayer with it.
     
  7. so what do I add i
    So if I understood it right,
    I need to write the function like this?:

    Code:
    function PLUGIN:cmdAirdrop(player, cmd, args)
    if player.net.connection.authLevel == 0 then return end
    rust.BroadcastChat("Airdrop summoned by", player.displayName)
    rust.RunServerCommand("airdrop.toplayer", args)
    
    Or did I just understand it totally wrong? :c
    or do I need to add something to the "args", like args.something :v

    -Laser
    [DOUBLEPOST=1427227771][/DOUBLEPOST]-> Well it doesnt seem right....

    Code:
    [Oxide] 9:09 PM [Error] Failed to call hook 'cmdMassdrop' on plugin 'Airdrops'
    File: airdrops.lua Line: 31 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 
    I tried using cmd.args and just args

    Code:
    function PLUGIN:cmdMassdrop(player, cmd, args)
    if player.net.connection.authLevel < 1 then return end
    rust.BroadcastChat("AIRDROP", cmd.args, "Airdrops summoned by", player.displayName)
    rust.RunServerCommand("massdrop", cmd.args)
    end
    Code:
    function PLUGIN:cmdMassdrop(player, cmd, args)
    if player.net.connection.authLevel < 1 then return end
    rust.BroadcastChat("AIRDROP", args, "Airdrops summoned by", player.displayName)
    rust.RunServerCommand("massdrop", args)
    end
    [DOUBLEPOST=1427231801][/DOUBLEPOST]-> Update ->

    I just tried looking into the code of a plugin with a smillilar function and came to the "authlevel" plugin.

    After I looked at it my function looked like this:
    Code:
    function PLUGIN:cmdAirdrop(player, cmd, args)
        if args.Length ~= 2 then
            local targetPlayer = global.BasePlayer.Find(args[0])
            if player.net.connection.authLevel == 0 then return end
            rust.BroadcastChat("Airdrop summoned by", player.displayName)
            rust.RunServerCommand("airdrop", targetPlayer)
        else
            rust.RunServerCommand("event.run", "")
        end
    end
    But when I do /airdrop,
    the console gives out:

    Code:
    [Oxide] 10:08 PM [Error] Failed to call hook 'cmdAirdrop' on plugin 'Airdrops' (IndexOutOfRangeException: Array index is out of range.)
    [Oxide] 10:08 PM [Debug] at NLua.MetaFunctions.GetMethodInternal (LuaState luaState) [0x00000] in :0
    at NLua.MetaFunctions.GetMethod (LuaState luaState) [0x00000] in :0
    at (wrapper native-to-managed) NLua.MetaFunctions:GetMethod (KeraLua.LuaState)
    at (wrapper managed-to-native) KeraLua.NativeMethods:LuaNetPCall (intptr,int,int,int)
    at KeraLua.Lua.LuaNetPCall (IntPtr luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [0x00000] in :0
    at NLua.LuaLib.LuaPCall (LuaState luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [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 
    -Laser
     
  8. Wulf

    Wulf Community Admin

    Do you have plugins installed that provide the "airdrop" and "event.run" commands?
     
  9. yes the event.run Is always in it as I know, just from Rust base, and the airdrop commands are of the Plugin "Airdrop Control"
     
  10. Wulf

    Wulf Community Admin

    Try the below code. You are using the rust functions wrong in your example.
    Code:
    function PLUGIN:cmdAirdrop(player, cmd, args)
        if args.Length ~= 2 then
            local targetPlayer = global.BasePlayer.Find(args[0])
            if player.net.connection.authLevel == 0 then return end
            rust.BroadcastChat("Airdrop summoned by " .. player.displayName)
            rust.RunServerCommand("airdrop " .. targetPlayer)
        else
            rust.RunServerCommand("event.run")
        end
    end
     
  11. Thanks, how do I know when to use , and when .. ?
     
  12. Wulf

    Wulf Community Admin

    They are entirely different things. The comma is used in functions where it accepts multiple parameters and such, the .. is used to connect variables to strings and such.
     
  13. okay, so in this case its used to convert a variable to a string? ^_^
    Because as i know the RunServerCommand and the Broadcast Chat work with multiple.. Like rust.BroadcastChat("TEST", "This is a testmessage")
     
  14. Wulf

    Wulf Community Admin

    Yes, but the way you were using rust.BroadcastChat was wrong. The format is "chat name", chat message", "steam id", with the first and last parameters being optional. It doesn't accept multiple messages, so using it the way you had before would result in your chat message being the chat name, and the player name being the chat message.
     
  15. Thanks for that, but I still got problems ^^

    Now if I run it it gives me this error:
    Code:
    [Oxide] 6:42 PM [Error] Failed to call hook 'cmdAirdrop' on plugin 'Airdrops'
    File: airdrops.lua Line: 93 attempt to concatenate local 'targetPlayer' (a userdata value):
    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 
    Thats just my function:

    Code:
    function PLUGIN:cmdAirdrop(player, cmd, args)
        if args.Length ~= 2 then
            local targetPlayer = global.BasePlayer.Find(args[0])
            if player.net.connection.authLevel == 0 then return end
            rust.BroadcastChat("AIRDROP", "Airdrop for a specific player summoned by "  .. player.displayName)
            rust.RunServerCommand("airdrop " .. targetPlayer)
        else
            rust.BroadcastChat("AIRDROP", "Airdrop summoned by " .. player.displayName)
            rust.RunServerCommand("event.run")
        end
    end
    -------

    You know I got that

    Code:
       else
            rust.RunServerCommand("event.run")
    which is supposed to, if I only type /airdrop without a playername to summon a normal random airdrop.
    That doesnt get triggered if I type /airdrop

    And gives out that old error again...

    Code:
    [Oxide] 6:45 PM [Error] Failed to call hook 'cmdAirdrop' on plugin 'Airdrops' (IndexOutOfRangeException: Array index is out of range.)
    [Oxide] 6:45 PM [Debug] at NLua.MetaFunctions.GetMethodInternal (LuaState luaState) [0x00000] in :0
    at NLua.MetaFunctions.GetMethod (LuaState luaState) [0x00000] in :0
    at (wrapper native-to-managed) NLua.MetaFunctions:GetMethod (KeraLua.LuaState)
    at (wrapper managed-to-native) KeraLua.NativeMethods:LuaNetPCall (intptr,int,int,int)
    at KeraLua.Lua.LuaNetPCall (IntPtr luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [0x00000] in :0
    at NLua.LuaLib.LuaPCall (LuaState luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [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 
    and I also did it with the massdrop, but that does not work either...
    Code:
    function PLUGIN:cmdMassdrop(player, cmd, args)
        if player.net.connection.authLevel < 1 then return end
        if args.Length ~= 2 then
            local dropAmount = string.lower(args[1])
            if dropAmount < 2 then return end
            rust.BroadcastChat("AIRDROP" .. dropAmount, "Airdrops summoned by" .. player.displayName)
            rust.RunServerCommand("massdrop" .. dropAmount)
        else
            rust.SendChatMessage(player, "AIRDROP", "Syntax = /massdrop [AMOUNT]")
        end
    end
    Error:

    Code:
    [Oxide] 6:46 PM [Error] Failed to call hook 'cmdMassdrop' on plugin 'Airdrops' (IndexOutOfRangeException: Array index is out of range.)
    [Oxide] 6:46 PM [Debug] at NLua.MetaFunctions.GetMethodInternal (LuaState luaState) [0x00000] in :0
    at NLua.MetaFunctions.GetMethod (LuaState luaState) [0x00000] in :0
    at (wrapper native-to-managed) NLua.MetaFunctions:GetMethod (KeraLua.LuaState)
    at (wrapper managed-to-native) KeraLua.NativeMethods:LuaNetPCall (intptr,int,int,int)
    at KeraLua.Lua.LuaNetPCall (IntPtr luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [0x00000] in :0
    at NLua.LuaLib.LuaPCall (LuaState luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [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 
    Im not sure what im doing wrong now :eek:
     
  16. You are trying to use a userdata as a string. Try
    Code:
    function PLUGIN:cmdAirdrop(player, cmd, args)
        if args.Length ~= 2 then
            local targetPlayer = global.BasePlayer.Find(args[0])
            if player.net.connection.authLevel == 0 then return end
            rust.BroadcastChat("AIRDROP", "Airdrop for a specific player summoned by "  .. player.displayName)
            rust.RunServerCommand("airdrop " .. targetPlayer.displayName)
        else
            rust.BroadcastChat("AIRDROP", "Airdrop summoned by " .. player.displayName)
            rust.RunServerCommand("event.run")
        end
    end
     
  17. Wulf

    Wulf Community Admin

    Good catch, I didn't notice that. ;)
     
  18. Thanks Domestos!
    Whats about the Massdrop error? Ive gone over it about 20 times now and didnt find anything. I don't know if im just to tired to see it or if eh I don't know what else :v
    -Laser
    [DOUBLEPOST=1427486554][/DOUBLEPOST]+ Also I noticed that whatever I put behind that "else" it wont work... It just says
    Code:
    [Oxide] 9:02 PM [Error] Failed to call hook 'cmdAirdrop' on plugin 'Airdrops' (IndexOutOfRangeException: Array index is out of range.)
    [Oxide] 9:02 PM [Debug] at NLua.MetaFunctions.GetMethodInternal (LuaState luaState) [0x00000] in :0
    at NLua.MetaFunctions.GetMethod (LuaState luaState) [0x00000] in :0
    at (wrapper native-to-managed) NLua.MetaFunctions:GetMethod (KeraLua.LuaState)
    at (wrapper managed-to-native) KeraLua.NativeMethods:LuaNetPCall (intptr,int,int,int)
    at KeraLua.Lua.LuaNetPCall (IntPtr luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [0x00000] in :0
    at NLua.LuaLib.LuaPCall (LuaState luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [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 
    But really, I have tried to add functions there or just rust.SendChatMessage(player, "If you see this it works") and it didn't work...
     
  19. Your code:
    Code:
    if args.Length ~= 2 then
            local dropAmount = string.lower(args[1])
            if dropAmount < 2 then return end
            rust.BroadcastChat("AIRDROP" .. dropAmount, "Airdrops summoned by" .. player.displayName)
            rust.RunServerCommand("massdrop" .. dropAmount)
        else
    You are checking if args a different amount of values of 2, keep in mind that this will have it run without, with one and with 3 or more arguments, so you will want to limit that to what you need, so in your case that is 1 so you want an args.Length == 1 as your if-statement.
    Secondly, args is an array of strings (string[ ]) and an array is zero-based. This means it starts counting at 0 and not at 1. So you would have to put args[0] in your dropAmount. Also keep in mind that it is a string and a number so you should cast it with the tonumber() function in lua so you would have something like this: local dropAmount = tonumber(args[0])

    If you change these things then it should no longer throw the error.
     
  20. Thanks that works just fine!
    I really appreciate your help :) All of you.
    -Laser
    [DOUBLEPOST=1427580447,1427492640][/DOUBLEPOST]One more thing to this subject.
    If I now want multibple args to be an output. For example for a Admin Messaging plugin...
    So that I do like /admin Hello, I got a question!
    and I get ADMIN REQUEST: Hello, I got a question!
    because if I use it as before it just writes the first word. Do I need to put the Text in "" for that or does it also work without anyhow?