Hey folks,
i'm trying to update and modify an existing Plugin to get it work with Valheim. But i'm totally new to this and i doing something wrong without knowing what.
Original Plugin from Orf1:
using System;
using System.Collections.Generic;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins
{
[Info("Teleport", "Orf1", "1.0.1")]
[Description("Lets players with permission teleport to any specified position.")]
class Teleport : CovalencePlugin
{
private void Init()
{
permission.RegisterPermission("teleport.use", this);
LoadDefaultMessages();
}
[Command("teleport")]
private void SetCommand(IPlayer player, string command, string[] args)
{
if (player.HasPermission("teleport.use"))
{
if (args.Length == 3)
{
try
{
float x = Int32.Parse(args[0]);
float y = Int32.Parse(args[1]);
float z = Int32.Parse(args[2]);
var newPos = new GenericPosition(x, y, z);
player.Teleport(newPos);
string message = lang.GetMessage("Success", this, player.Id);
player.Message(message);
}
catch (FormatException)
{
string message = lang.GetMessage("InvalidUsage", this, player.Id);
player.Message(message);
}
}
else
{
string message = lang.GetMessage("InvalidUsage", this, player.Id);
player.Message(message);
}
}
else
{
string message = lang.GetMessage("NoPermission", this, player.Id);
player.Message(message);
}
}
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Success"] = "You have teleported successfully.",
["NoPermission"] = "You do not have permission to use this command!",
["InvalidUsage"] = "Invalid usage. /teleport [x] [y] [z]"
}, this);
}
}
}
My modified Version (trying to update from Oxide to uMod and make it work with Valheim):
using System;
using System.Collections.Generic;
using uMod.Common;
using uMod.Game.Valheim;
namespace uMod.Plugins
{
[Info("Teleport-Valheim", "bodyXY", "0.1")]
[Description("Lets players with permission teleport to any specified position.")]
class Teleport : Plugin
{
private void Init()
{
permission.RegisterPermission("teleport.use", this);
LoadDefaultMessages();
}
[Command("teleport")]
private void SetCommand(ValheimPlayer player, string[] args)
{
if (player.HasPermission("teleport.use"))
{
if (args.Length == 3)
{
try
{
float x = int.Parse(args[0]);
float y = int.Parse(args[1]);
float z = int.Parse(args[2]);
Position newPos = new Position(x, y, z);
player.Teleport(newPos);
string message = lang.GetMessage("Success", this, player.Id);
player.Message(message);
}
catch (FormatException)
{
string message = lang.GetMessage("InvalidUsage", this, player.Id);
player.Message(message);
}
}
else
{
string message = lang.GetMessage("InvalidUsage", this, player.Id);
player.Message(message);
}
}
else
{
string message = lang.GetMessage("NoPermission", this, player.Id);
player.Message(message);
}
}
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Success"] = "You have teleported successfully.",
["NoPermission"] = "You do not have permission to use this command!",
["InvalidUsage"] = "Invalid usage. /teleport [x] [y] [z] (without [] example: /teleport 123 -456 789)"
}, this);
}
}
}
Console ouput after using Command /teleport [x] [y] [z]:
04/16/2021 02:01:46: Exception in ZRpc::HandlePackage: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Specified method is not supported.
at uMod.Game.Valheim.ValheimPlayer.Teleport (uMod.Common.Position pos) [0x00000] in <d8e28d432e0b4753aa0cd757568403f0>:0
at uMod.Plugins.Teleport.SetCommand (uMod.Common.IPlayer player, System.String command, System.String[] args) [0x0003b] in <a80f9a7d7da34d98bd6bfbc075ca172c>:0
at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,object,object[])
at uMod.Plugins.HookMethod.Invoke (uMod.Common.IContext target, System.Object[] arguments) [0x0005e] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Plugins.HookDispatcher.Dispatch (uMod.Plugins.HookName hookName, System.Object[] args, uMod.Plugins.HookEvent e) [0x001b1] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Plugins.PluginCommands+<>c__DisplayClass9_0.<CreateCallback>b__0 (uMod.Common.IPlayer caller, System.String command, System.String fullCommand, System.Object[] context, uMod.Common.ICommandInfo cmdInfo) [0x000a9] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Plugins.PluginCommands.UniversalCommandCallback (uMod.Common.IPlayer caller, System.String cmd, System.String fullCommand, System.Object[] context, uMod.Common.ICommandInfo cmdInfo) [0x00107] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Game.Valheim.ValheimCommands.CommandCallback (uMod.Common.IPlayer caller, System.String command, System.String fullCommand, System.Object[] context, uMod.Common.ICommandInfo commandInfo) [0x00012] in <d8e28d432e0b4753aa0cd757568403f0>:0
at uMod.Command.CommandHandler.HandleCommand (uMod.Common.IPlayer player, System.String fullCommand, System.Object[] context) [0x000c1] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Command.CommandHandler.HandleChatMessage (uMod.Common.IPlayer player, System.String command, System.Object[] context) [0x0003f] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Game.Valheim.ValheimCommands.HandleChatMessage (uMod.Common.IPlayer player, System.String message) [0x00000] in <d8e28d432e0b4753aa0cd757568403f0>:0
at uMod.Game.Valheim.Valheim.IOnHandleRoutedRPC (ZRoutedRpc+RoutedRPCData rpcData) [0x000e9] in <d8e28d432e0b4753aa0cd757568403f0>:0
at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,object,object[])
at uMod.Plugins.HookMethod.Invoke (uMod.Common.IContext target, System.Object[] arguments) [0x000b4] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Module.CallHook (System.String hookname, System.Object[] args) [0x0002f] in <31fefd269fb145f890ad5296123ff870>:0
at uMod.Interface.CallHook (System.String hook, System.Object obj1) [0x00014] in <31fefd269fb145f890ad5296123ff870>:0
at ZRoutedRpc.HandleRoutedRPC (ZRoutedRpc+RoutedRPCData data) [0x00000] in <327b4a0a15454dd5a266954181e42230>:0
at ZRoutedRpc.RPC_RoutedRPC (ZRpc rpc, ZPackage pkg) [0x00023] in <327b4a0a15454dd5a266954181e42230>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <eae584ce26bc40229c1b1aa476bfa589>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <eae584ce26bc40229c1b1aa476bfa589>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <eae584ce26bc40229c1b1aa476bfa589>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <eae584ce26bc40229c1b1aa476bfa589>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <eae584ce26bc40229c1b1aa476bfa589>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <eae584ce26bc40229c1b1aa476bfa589>:0
at ZRpc+RpcMethod`1[T].Invoke (ZRpc rpc, ZPackage pkg) [0x0001d] in <327b4a0a15454dd5a266954181e42230>:0
at ZRpc.HandlePackage (ZPackage package) [0x00049] in <327b4a0a15454dd5a266954181e42230>:0
at ZRpc.Update (System.Single dt) [0x0003e] in <327b4a0a15454dd5a266954181e42230>:0
Thanks for any helping!