1. Hey.

    I recently wrote a teleportation plugin, and it all works fine except for when a member of a clan tries to teleport to the member of another clan (or simply between the same clan).

    I get this error:
    Code:
    (InvalidOperationException: Operation is not valid due to the current state of the object)
    I'd rather not disclose the code, but it basically has a GUI with a list of players, you select a player and it teleports you to them (if they accepted). The teleportation function I used is from Nogrod's teleportation plugin.

    It works fine when someone not in a clan teleports to someone in a clan (and vice versa), but not for clan to clan teleportation.

    Any ideas?
     
    Last edited by a moderator: Oct 5, 2016
  2. Wulf

    Wulf Community Admin

    One of the lists you are trying to check/modify is in a state that can't be used. Without seeing a portion at least, hard to give much feedback.
     
  3. Could it be
    Code:
    BasePlayer.activePlayerList.SingleOrDefault(pla => pla.displayName.Contains(name));
    ?

    Apart from that I don't think there are any other lists that RustIO would be able to effect - the others are part of the plugin.
     
  4. Fixed it.

    Basically, the tp GUI would send the persons name to the TeleportToPlayer function via a console command. It would run "customteleportation {player name}". However, when in a clan, this would return "customteleportation teleport [test] PsychoTea".

    In the customteleportaiton command code, it would use args[2], which in this case, would return "[test]".

    Then in the TeleportToPlayer function, I would use BasePlayer.activePlayerList.SingleOrDefault(pla => pla.displayName.Contains(name));

    There are two problems here, first pla.displayName.Contains(name) will return every player that has "[test]" in their name (or every player in the "test" clan). Which leads into the second, the use of SingleOrDefault. Afaik, SingleOrDefault only expects one item to return from pla.displayName.Contains(name), so when it returns multiple it errors out and causes problems.

    The way I fixed this was to simply change the code in the customteleportaiton console command to take into account names with spaces in them, by adding the rest of the args after the first two ("customteleportation" and "teleport") to the "name" string.