public void WeaponImageonWetFire(coScriptObject thisobj, coPlayer obj, int slot) { if (!thisobj["projectile"].isObject()) { console.error("WeaponImage::onFire() - Invalid projectile datablock"); return; } // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. if (!thisobj["infiniteAmmo"].AsBool()) ShapeBaseShapeBaseDecInventory(obj, thisobj["ammo"], 1); // Get the player's velocity, we'll then add it to that of the projectile int numProjectiles = thisobj["projectileNum"].AsInt(); if (numProjectiles == 0) numProjectiles = 1; TransformF muzzleVector = new TransformF(); for (int i = 0; i < numProjectiles; i++) { if (thisobj["wetProjectileSpread"].AsBool()) { // We'll need to "skew" this projectile a little bit. We start by // getting the straight ahead aiming point of the gun Point3F vec = obj.getMuzzleVector(slot); // Then we'll create a spread matrix by randomly generating x, y, and z // points in a circle Random r = new Random(); TransformF matrix = new TransformF(); matrix.MPosition.x = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat()); matrix.MPosition.y = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat()); matrix.MPosition.z = (float)((r.NextDouble() - .5) * 2 * Math.PI * thisobj["wetProjectileSpread"].AsFloat()); TransformF mat = math.MatrixCreateFromEuler(matrix); muzzleVector = math.MatrixMulVector(mat, vec); } else { muzzleVector = new TransformF(obj.getMuzzleVector(slot)); } Point3F objectVelocity = obj.getVelocity(); muzzleVector = muzzleVector.vectorScale(thisobj["wetProjectile.muzzleVelocity"].AsFloat()); objectVelocity = objectVelocity.vectorScale(thisobj["wetProjectile.velInheritFactor"].AsFloat()); Point3F muzzleVelocity = muzzleVector.MPosition + objectVelocity; Torque_Class_Helper tch = new Torque_Class_Helper(thisobj["projectileType"]); tch.Props.Add("dataBlock", thisobj["wetProjectile"]); tch.Props.Add("initialVelocity", '"' + muzzleVelocity.AsString() + '"'); tch.Props.Add("initialPosition", '"' + obj.getMuzzlePoint(slot).AsString() + '"'); tch.Props.Add("sourceObject", obj); tch.Props.Add("sourceSlot", slot.AsString()); tch.Props.Add("client", obj["client"]); tch.Props.Add("sourceClass", obj.getClassName()); coItem projectile = tch.Create(); ((coSimSet)"MissionCleanup").pushToBack(projectile); } }
public void AmmoOnInventory(coItemData thisobj, coPlayer player, int amount) { coGameConnection client = player["client"]; for (int i = 0; i < 8; i++) { coItemData image = player.getMountedImage(i); if (image <= 0) continue; if (!image["ammo"].isObject()) continue; if (console.Call(image["ammo"], "getID") != console.Call(thisobj, "getID")) continue; player.setImageAmmo(i, amount != 0); int currentammo = ShapeBaseShapeBaseGetInventory(player, thisobj); if (player.getClassName() != "Player") continue; int amountInClips; if (thisobj["clip"].isObject()) { amountInClips = ShapeBaseShapeBaseGetInventory(player, thisobj["clip"]); amountInClips *= thisobj["maxInventory"].AsInt(); amountInClips += player["remaining" + thisobj.getName()].AsInt(); } else { amountInClips = currentammo; currentammo = 1; } if (player["client"] != "" && !player["isAiControlled"].AsBool()) { GameConnectionSetAmmoAmountHud(client, currentammo, amountInClips); } } }
public void ArmorOnMount(coPlayerData datablock, coPlayer player, coVehicle vehicle, int node) { coVehicleData vehicleDataBlock = vehicle.getDataBlock(); if (node == 0) { player.setTransform(new TransformF("0 0 0 0 0 1 0")); string mountPose = vehicleDataBlock["mountPose[" + node + "]"]; player.setActionThread(mountPose, true, true); player["lastWeapon"] = player.getMountedImage(WeaponSlot).AsString(); coGameConnection client = player["client"]; if (client.isObject()) player["lastperson"] = client.isFirstPerson().AsString(); player.unmountImage(WeaponSlot); player.setControlObject(vehicle); if (player.getClassName() == "Player") { console.commandToClient(player["client"], console.addTaggedString("toggleVehicleMap"), new[] { "true" }); } } else { string pose = vehicleDataBlock["mountPose[" + node + "]"]; player.setActionThread(pose != "" ? pose : "root", false, true); } }