public void FMSpawn() { if (GameMode.IsActive) { GameMode.ActiveMode.Leave(this); } KillCharacter(); SetTeamID(TeamIdent.FFAPlayer); NPCDef def = NPCDef.Get(charInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer"); NPCInst npc = new NPCInst(def) { UseCustoms = true, CustomBodyTex = charInfo.BodyTex, CustomHeadMesh = charInfo.HeadMesh, CustomHeadTex = charInfo.HeadTex, CustomVoice = charInfo.Voice, CustomFatness = charInfo.Fatness, CustomScale = new Vec3f(charInfo.BodyWidth, 1.0f, charInfo.BodyWidth), CustomName = charInfo.Name, DropUnconsciousOnDeath = true, UnconsciousDuration = 15 * TimeSpan.TicksPerSecond, }; ItemDef.ForEach(itemDef => { var item = new ItemInst(itemDef); npc.Inventory.AddItem(item); if (string.Equals(itemDef.CodeName, "ItMw_1h_Bau_Mace", StringComparison.OrdinalIgnoreCase) || string.Equals(itemDef.CodeName, "ITAR_Prisoner", StringComparison.OrdinalIgnoreCase)) { npc.EffectHandler.TryEquipItem(item); } else if (itemDef.ItemType == ItemTypes.AmmoBow || itemDef.ItemType == ItemTypes.AmmoXBow) { item.SetAmount(100); } }); if (npc.ModelDef.TryGetOverlay("1HST1", out ScriptOverlay ov)) { npc.ModelInst.ApplyOverlay(ov); } if (npc.ModelDef.TryGetOverlay("2HST1", out ov)) { npc.ModelInst.ApplyOverlay(ov); } var pair = spawnPositions.GetRandom(); npc.Spawn(WorldInst.List[0], pair.Item1, pair.Item2); this.SetControl(npc); npc.AllowHitAttacker.Add(DuelMode.CheckHitDetection); }
static void SpawnItem(WorldInst world, PosAng posAng) { var item = BRScenario.Items.GetRandom(); ItemDef def = ItemDef.Get(item.Definition); if (def == null) { return; } ItemInst inst = new ItemInst(def); inst.SetAmount(item.Amount); inst.Spawn(world, posAng.Position, posAng.Angles); }
public void TryShoot(Vec3f start, Vec3f end) { if (Host.IsDead || !Host.IsAiming()) { return; } if (start.GetDistance(end) > 500000) // just in case { end = start + 500000 * (end - start).Normalise(); } var drawnWeapon = Host.GetDrawnWeapon(); if (drawnWeapon == null || !drawnWeapon.IsWepRanged) { return; } ItemInst ammo = drawnWeapon.ItemType == ItemTypes.WepBow ? Host.GetRightHand() : Host.GetLeftHand(); if (ammo == null || !ammo.IsAmmo) { return; } ProjInst inst = new ProjInst(ProjDef.Get <ProjDef>("arrow")) { Item = new ItemInst(ammo.Definition), Damage = drawnWeapon.Damage, Velocity = 0.0004f, Model = ammo.ModelDef }; end = end - (end - start).Normalise() * (ammo.ItemType == ItemTypes.AmmoBow ? 40 : 10); // so arrows' bodies aren't 90% inside walls Host.DoShoot(start, end, inst); int ammoCount = ammo.Amount - 1; if (ammoCount <= 0) { Host.UnequipItem(ammo); } ammo.SetAmount(ammo.Amount - 1); }
protected NPCInst CreateNPC(NPCClass def, int teamID, CharCreationInfo cInfo = null) { if (def == null) { return(null); } NPCInst npc; if (def.Definition == null) { if (cInfo == null) { npc = new NPCInst(NPCDef.Get("maleplayer")); npc.RandomizeCustomVisuals(def.Name, true); } else { npc = new NPCInst(NPCDef.Get(cInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer")) { UseCustoms = true, CustomBodyTex = cInfo.BodyTex, CustomHeadMesh = cInfo.HeadMesh, CustomHeadTex = cInfo.HeadTex, CustomVoice = cInfo.Voice, CustomFatness = cInfo.Fatness, CustomScale = new Vec3f(cInfo.BodyWidth, 1.0f, cInfo.BodyWidth), CustomName = cInfo.Name }; } } else { npc = new NPCInst(NPCDef.Get(def.Definition)); } // add inventory items if (def.ItemDefs != null) { foreach (var invItem in def.ItemDefs) { var item = new ItemInst(ItemDef.Get(invItem.DefName)); item.SetAmount(invItem.Amount); npc.Inventory.AddItem(item); npc.EffectHandler.TryEquipItem(item); } } // add overlays if (def.Overlays != null) { foreach (var overlay in def.Overlays) { if (npc.ModelDef.TryGetOverlay(overlay, out ScriptOverlay ov)) { npc.ModelInst.ApplyOverlay(ov); } } } npc.TeamID = teamID; npc.Protection = def.Protection; npc.Damage = def.Damage; npc.SetHealth(def.HP, def.HP); npc.Guild = def.Guild; return(npc); }