1. Hello...

    As the title suggests, I am trying to edit the existing RGive plugin (RGive (Random Item Give) for Rust | Oxide) to be able to receive player IDs as well as player names...

    I'm really new to plugin coding, and am hoping for some help so it doesn't take me forever...

    I think the relevant areas look like:

    void GiveRandomItem(BasePlayer player)
    {
    if (player == null)
    return; ...
    ...
    GiveRandomItem(player);
    return;

    -- can I do something like:

    void GiveRandomItem(BasePlayer (player or id))
    {
    if (player == null)
    return; ...
    ...
    GiveRandomItem(player or id);
    return;


    Or something similar?

    Are there other places that need changing too probably?


    Any help would be greatly appreciated!

    Thanks!

    <3
     
  2. Wulf

    Wulf Community Admin

    You'd need to change the method to accept a string or ulong, then lookup the player later if you need it.
     
  3. Okay, so, maybe I should've said I'm really REALLY new to plugin coding... haha.

    Is the method I want to change here?::

    BasePlayer GetPlayer(string searchedPlayer, BasePlayer player)
    {
    foreach (BasePlayer current in BasePlayer.activePlayerList)
    if (current.displayName.ToLower() == searchedPlayer.ToLower())
    return current;

    to, like,

    BasePlayer GetPlayer(string searchedPlayer, BasePlayer player)
    {
    foreach (BasePlayer current in BasePlayer.activePlayerList)
    if ((current.displayName.ToLower() == searchedPlayer.ToLower()) or (searchedPlayer == current.playerID))
    return current;


    I'm not quite sure how BasePlayer or "current" works, but it looks like the method (GetPlayer?) is taking in a string and I just need to pass it player.ID???

    Where the commands are...

    void cmdRGive(BasePlayer player, string cmd, string[] args)
    ...
    void ccmdRGive(ConsoleSystem.Arg arg)

    I'm not quite sure how these work and where things are getting passed in... but BasePlayer has the info for .playerID? and the args are getting passed as strings so playerID or Name should get stored the same?

    I'm confused. :(

    Any more help would be immensely appreciated. ( @Wulf ... thank you! )
     
  4. Code:
    if (current.displayName.ToLower() == searchedPlayer.ToLower() || current.UserIDString == searchedPlayer)
    Whole thing would be this:
    Code:
                foreach (BasePlayer current in BasePlayer.activePlayerList)
                    if (current.displayName.ToLower() == searchedPlayer.ToLower() || current.UserIDString == searchedPlayer)
                        return current;
     

  5. Works like a charm. Thanks! :D
     
  6. Correct me if I'm wrong, but you can also use LINQ style.

    Code:
    BasePlayer.activePlayerList.FirstOrDefault(
                    x => x.displayName.Equals(searchedName, StringComparison.CurrentCultureIgnoreCase) ||
                    x.userID.Equals(searchedId));
    Make sure to check IsValid() afterwards.

    Edit: W
     
  7. Code:
    BasePlayer player = BasePlayer.Find(searchedPlayer);
    if(player) return player;
    Easiest way. :cool: :D
    That way searchedPlayer can be the player's id, name, or ip.
     
  8. True. The Find Method is searching for the matching userid first, afterwards the displayName.