Solved Set sleeper position

Discussion in 'Rust Development' started by theconezone, Sep 11, 2015.

  1. There have been a few threads on getting a sleeping player's position, but none on setting it.

    The following does not work for a given BasePlayer sleeper and Vector3 newPosition:

    I'm out of ideas at this point. I think maybe sleeping players are a type of container rather than a player, but even if they are I still have no idea how to move them.
     
  2. sleepers are players so you can forceplayerposition as if they were online players.
    you just have to look in all the plugins as there is a trick now to successfully change someones position. (search for lastPosition)
    Event Manager, Portgun, Teleportation system, etc... you can look in all those plugins.
     
  3. Thanks, I did search other plugins but I was searching for transform.position. Here is my resulting code for anyone else who needs to know this later (minus error checking, works on both sleepers and players):

    Code:
    using System;
    using System.Reflection;namespace Oxide.Plugins {   [Info("ExamplePlugin", "John Example", "0.0.1")]
       class ExamplePlugin : RustPlugin {     private FieldInfo lastPositionValueField;     protected void Loaded() {       //retrieve BasePlayer.lastPositionValue for later usage
           lastPositionValueField = typeof(BasePlayer).GetField("lastPositionValue", BindingFlags.NonPublic | BindingFlags.Instance);     }     //"fix" ForcePlayerPosition
         protected new void ForcePlayerPosition(BasePlayer player, Vector3 destination) {       //check if player is actively playing
           if (player.IsConnected() && !player.IsReceivingSnapshot()) {         //check if player is sleeping
             if (!player.IsSleeping()) {           //player is not sleeping, put player to sleep
               player.StartSleeping();         }         //Set position and send ForcePositionTo
             base.ForcePlayerPosition(player, destination);         //Send player into loading screen
             player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, true);
             player.UpdateNetworkGroup();
             player.SendNetworkUpdateImmediate(false);
             player.ClientRPCPlayer(null, player, "StartLoading");       } else {         //player is not connected, simply set the position
             player.transform.position = destination;       }       //Update player position
           lastPositionValueField.SetValue(player, destination);
           player.TransformChanged();       //check if we sent the player into a loading screen
           if (player.IsReceivingSnapshot()) {         //Send full update to client
             player.SendFullSnapshot();         //player is done loading, end loading screen
             player.SetPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot, false);
             player.ClientRPCPlayer(null, player, "FinishLoading");       }     }   }}
    
     
  4. Does this still work? How do I go about using this code?
     
  5. For anyone reading this, I'm pretty sure I ended up using NTeleportation to move sleepers instead! After using the Finder plugin to find them.