public static void ProcessClient(byte[] data) { if (MyAPIGateway.Utilities.IsDedicated /*|| (!MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Multiplayer.IsServer)*/) { return; } //This converts your data back to the original type you had before you sent //Depending on what you sent, you may need to parse it back into something usable var receivedData = MyAPIGateway.Utilities.SerializeFromBinary <RailgunTracerData>(data); RailgunCore.DrawProjectileClient(receivedData); }
public static void SendToClients(RailgunTracerData data) { //Below, save your data to string or some other serializable type var sendData = MyAPIGateway.Utilities.SerializeToBinary(data); //Send the message to the ID you registered in Setup, and specify the user via SteamId bool sendStatus = MyAPIGateway.Multiplayer.SendMessageToOthers(NetID, sendData); if (!MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Multiplayer.IsServer) { RailgunCore.DrawProjectileClient(data); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { base.Init(objectBuilder); try { _objectBuilder = objectBuilder; NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME; // this.m_missileAmmoDefinition = weaponProperties.GetCurrentAmmoDefinitionAs<MyMissileAmmoDefinition>(); SetPowerSink(); cube = (IMyCubeBlock)Entity; block = (IMyFunctionalBlock)Entity; GetAmmoProperties(); //get shoot time for initial check _lastShootTime = GetLastShootTime(); GetTurretMaxRange(); soundEmitter = new MyEntity3DSoundEmitter((MyEntity)Entity, true); projectileData = new RailgunProjectileData() { DesiredSpeed = _desiredSpeed, MaxTrajectory = _maxTrajectory, ExplosionDamage = 0f, ExplosionRadius = 0f, PenetrationDamage = _projectileDamage, PenetrationRange = 50f, ProjectileTrailColor = _trailColor, ProjectileTrailScale = _trailScale, DrawTracer = true, Explode = true, Penetrate = true }; RailgunCore.RegisterRailgun(Entity.EntityId, projectileData); } catch (Exception e) { MyAPIGateway.Utilities.ShowNotification("Exception in init", 10000, MyFontEnum.Red); MyLog.Default.WriteLine(e); } }
public static void ProcessClient(byte[] data) { if (MyAPIGateway.Utilities.IsDedicated || (!MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Multiplayer.IsServer)) { return; } //This converts your data back to the original type you had before you sent //Depending on what you sent, you may need to parse it back into something usable var receivedData = MyAPIGateway.Utilities.SerializeFromBinary <RailgunFireData>(data); IMyEntity ent; var entityExists = MyAPIGateway.Entities.TryGetEntityById(receivedData.ShooterID, out ent); if (entityExists) { RailgunCore.ShootProjectileClient(receivedData); } }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); try { if (cube?.CubeGrid?.Physics == null) //ignore ghost grids { return; } if (MyAPIGateway.Multiplayer.IsServer) { Vector3D direction; Vector3D origin; _currentShootTime = GetLastShootTime(); //fire weapon if (_currentShootTime != _lastShootTime && !_firstUpdate) { if (Entity is IMyLargeTurretBase) { Vector3D.CreateFromAzimuthAndElevation(turret.Azimuth, turret.Elevation, out direction); direction = Vector3D.TransformNormal(direction, turret.WorldMatrix); origin = turret.WorldMatrix.Translation + turret.WorldMatrix.Up * 1.75 + direction * 0.5; } else { direction = block.WorldMatrix.Forward; origin = block.WorldMatrix.Translation + direction * -2.5; //for cushion } var velocity = block.CubeGrid.Physics.LinearVelocity; //var projectile = new ArmorPiercingProjectileSimulation(origin, direction, velocity, this._desiredSpeed, this._maxTrajectory, 0f, 0f, _projectileDamage, 50f, Entity.EntityId, _trailColor, _trailScale, true, true, true); var fireData = new RailgunFireData() { ShooterVelocity = velocity, Origin = origin, Direction = direction, ShooterID = Entity.EntityId }; RailgunCore.ShootProjectileServer(fireData); //RailgunCore.AddProjectile(projectile); _isReloading = true; _currentReloadTicks = 0; //Apply recoil force var centerOfMass = block.CubeGrid.Physics.CenterOfMassWorld; var forceVector = -direction * _backkickForce; block.CubeGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, forceVector, block.GetPosition(), null); //MyAPIGateway.Utilities.ShowNotification("Shot", 3000); } _lastShootTime = _currentShootTime; sink.Update(); _firstUpdate = false; } ShowReloadMessage(); //MyAPIGateway.Utilities.ShowNotification($"Power draw: {GetPowerInput(false):n0} MW | reloading?: {_isReloading} | max: {sink.MaxRequiredInputByType(resourceId)} | current ticks {_currentReloadTicks}", 16, MyFontEnum.Blue); } catch (Exception e) { MyAPIGateway.Utilities.ShowNotification("Exception in update", 16, MyFontEnum.Red); MyLog.Default.WriteLine(e); } }
public override void Close() { base.Close(); //remove from dict RailgunCore.UnregisterRailgun(Entity.EntityId); }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); try { if (cube?.CubeGrid?.Physics == null) //ignore ghost grids { return; } _currentShootTime = GetLastShootTime(); if (_currentShootTime != _lastShootTime && !_firstUpdate) { _isReloading = true; //fire weapon if (MyAPIGateway.Multiplayer.IsServer) { Vector3D direction; Vector3D origin; if (Entity is IMyLargeTurretBase) { Vector3D.CreateFromAzimuthAndElevation(turret.Azimuth, turret.Elevation, out direction); direction = Vector3D.TransformNormal(direction, turret.WorldMatrix); origin = turret.WorldMatrix.Translation + turret.WorldMatrix.Up * 1.75 + direction * 0.5; } else { direction = block.WorldMatrix.Forward; origin = block.WorldMatrix.Translation + direction * -2.5; //for cushion } var velocity = block.CubeGrid.Physics.LinearVelocity; var fireData = new RailgunFireData() { ShooterVelocity = velocity, Origin = origin, Direction = direction, ShooterID = Entity.EntityId, }; RailgunCore.ShootProjectileServer(fireData); _currentReloadTicks = 0; //Apply recoil force var centerOfMass = block.CubeGrid.Physics.CenterOfMassWorld; var forceVector = -direction * _backkickForce; block.CubeGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, forceVector, block.GetPosition(), null); } } _lastShootTime = _currentShootTime; _firstUpdate = false; ShowReloadMessage(); } catch (Exception e) { MyAPIGateway.Utilities.ShowNotification("Exception in update", 16, MyFontEnum.Red); MyLog.Default.WriteLine(e); } }