Warping to a map

From The Stardew Modding Wiki
Jump to navigation Jump to search
    // Simple code for teleporting to a location. This location can be vanilla or custom
    // Search for the location
    GameLocation Location = Utility.fuzzyLocationSearch("LocationName");
    
    // Instead of creating a function here, an existing function can be used, e.g. if the same function is used multiple times
    Action TeleportFunction = delegate{
        //Insert here the coordinates you want to teleport to
        int X = 1;
        int Y = 1;
        
        //The direction you want the Farmer to face after the teleport
        // 0 = up, 1 = right, 2 = down, 3 = left
        int Direction = 1;
    
        //The teleport command itself
        Game1.warpFarmer(new LocationRequest(Location.NameOrUniqueName, Location.uniqueName.Value != null, Location), X, Y, Direction);
    };

    // Delayed action to be executed after a set time (here 0,1 seconds)
    // Teleporting without the delay may prove to be problematic
    DelayedAction.functionAfterDelay(TeleportFunction, 100);