protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 2) { throw new CommandWrongUsageException(Context); } string playerSearchTerm = Context.Parameters[0]; if (!PlayerTool.tryGetSteamPlayer(playerSearchTerm, out SteamPlayer recipient)) { throw new UserFriendlyException(m_StringLocalizer["vehicle:invalid_player", new { Player = playerSearchTerm }]); } string vehicleSearchTerm = Context.Parameters[1]; if (!UnturnedAssetHelper.GetVehicle(vehicleSearchTerm, out VehicleAsset vehicle)) { throw new UserFriendlyException(m_StringLocalizer["vehicle:invalid", new { Vehicle = vehicleSearchTerm }]); } await UniTask.SwitchToMainThread(); if (VehicleTool.giveVehicle(recipient.player, vehicle.id)) { await Context.Actor.PrintMessageAsync(m_StringLocalizer["vehicle:success_given", new { Vehicle = vehicle.vehicleName, Player = recipient.playerID.characterName }]); } else { throw new UserFriendlyException(m_StringLocalizer["vehicle:failure"]); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 1) { throw new CommandWrongUsageException(Context); } string vehicleSearchTerm = Context.Parameters[0]; if (!UnturnedAssetHelper.GetVehicle(vehicleSearchTerm, out VehicleAsset vehicle)) { throw new UserFriendlyException(m_StringLocalizer["vehicle:invalid", new { Vehicle = vehicleSearchTerm }]); } await UniTask.SwitchToMainThread(); if (VehicleTool.giveVehicle(((UnturnedUser)Context.Actor).Player.Player, vehicle.id)) { await Context.Actor.PrintMessageAsync(m_StringLocalizer["vehicle:success", new { Vehicle = vehicle.vehicleName }]); } else { throw new UserFriendlyException(m_StringLocalizer["vehicle:failure"]); } }