public void WeaponOnUser(coScriptObject data, coPlayer obj)
            {
            if (obj.getMountedImage(WeaponSlot) == data["image"].AsInt())
                return;

            AudioServerPlay3D("WeaponUseSound", obj.getTransform());


            obj.mountImage(data["image"], WeaponSlot, true, "");

            if (obj["client"].AsBool())
                {
                if (data["description"] != "")

                    MessageClient(obj["client"], "MsgWeaponUsed", "\\c3%1 \\c5 selected.", data["description"]);
                else
                    MessageClient(obj["client"], "MsgWeaponUsed", console.addTaggedString(@"\c0Weapon selected"));
                }

            if (obj.isInNamespaceHierarchy("Player"))
                return;

            obj.allowAllPoses();
            coSimObject image = data["image"];

            if (image["jumpingDisallowed"].AsBool())
                obj.allowJumping(false);

            if (image["jetJumpingDisallowed"].AsBool())
                obj.allowJetJumping(false);

            if (image["sprintDisallowed"].AsBool())
                obj.allowSprinting(false);

            if (image["crouchDisallowed"].AsBool())
                obj.allowCrouching(false);

            if (image["proneDisallowed"].AsBool())
                obj.allowProne(false);

            if (image["swimmingDisallowed"].AsBool())
                obj.allowSwimming(false);
            }
        public void HealthPatchOnCollision(coItemData healthkit_datablock, coSceneObject healthkit_instance, coPlayer player)
            {
            if (player.getDamageLevel() <= 0.00 || player.getState() == "Dead")
                return;

            player.applyRepair(healthkit_datablock["repairAmount"].AsFloat());

            healthkit_instance.call("schedulePop");


            //coGameConnection client = player["client"];
            //if (!client.isObject())
            //    return;
            //using (BackgroundWorker bwr = new BackgroundWorker())
            //    {
            //    bwr.DoWork += bwr_UpdateHealth;
            //    bwr.RunWorkerAsync(new HealthKitHelper(player, healthkit_instance));
            //    }

            AudioServerPlay3D("HealthUseSound", player.getTransform());
            }
        public void AmmoClipOnPickup(coItem thisobj, string obj, coPlayer shape, string amount, int nameSpaceDepth)
            {
            int nsd = nameSpaceDepth + 1;

            if (!console.ParentExecute(thisobj, "onPickup", nsd, new string[] { thisobj, obj, shape, amount }).AsBool())
                return;

            AudioServerPlay3D("WeaponPickupSound", shape.getTransform());

            coItemData image = shape.getMountedImage(WeaponSlot);

            if (image == 0)
                return;

            if (!console.isField(image, "clip") || console.Call(string.Format("{0}.clip", image), "getID") != console.Call(thisobj, "getID"))
                return;

            bool outOfAmmo = !shape.getImageAmmo(WeaponSlot);

            int amountInClips = 0;

            int currentAmmo = ShapeBaseShapeBaseGetInventory(shape, image["ammo"]);

            if (console.isObject(image["clip"]))
                amountInClips = ShapeBaseShapeBaseGetInventory(shape, image["clip"]);

            int t = console.GetVarInt(string.Format("{0}.ammo.maxInventory", image));

            amountInClips *= t;

            int amountloadedingun = console.GetVarInt(string.Format("{0}.remaining{1}", obj, console.GetVarString(string.Format("{0}.ammo", this))));

            amountInClips += amountloadedingun;



            GameConnectionSetAmmoAmountHud(shape["client"], currentAmmo, amountInClips);

            if (outOfAmmo)
                console.Call(image, "onClipEmpty", new string[] { shape, WeaponSlot.AsString() });
            }
 public void DetonadeOnDestroyed(coSimDataBlock thisobj, coPlayer obj, string laststate)
     {
     RadiusDamage(obj, obj.getTransform().MPosition, 10, 25, "DetonadeDamage", 2000);
     }
        public void ServerCmdcarUnmountObj(coGameConnection client, coPlayer obj)
            {
            obj.unmount();
            obj.setControlObject(obj);

            TransformF ejectpos = obj.getTransform();
            ejectpos += new TransformF(0, 0, 5);
            obj.setTransform(ejectpos);

            coVehicle mvehicle = obj["mVehicle"];

            Point3F ejectvel = mvehicle.getVelocity();
            ejectvel += new Point3F(0, 0, 10);

            ejectvel = ejectvel.vectorScale(((coSimDataBlock) (obj.getDataBlock()))["mass"].AsFloat());

            obj.applyImpulse(ejectpos.MPosition, ejectvel);
            }
 public void TeleporterTriggerTeleportPlayer(coSimDataBlock thisobj, coPlayer player, coSceneObject exit)
     {
     TransformF targetPosition;
     if (exit["reorientPlayer"].AsBool())
         {
         targetPosition = exit.getTransform();
         }
     else
         {
         targetPosition = exit.getTransform();
         TransformF playerrot = player.getTransform();
         targetPosition.MOrientation.x = playerrot.MOrientation.x;
         targetPosition.MOrientation.y = playerrot.MOrientation.y;
         targetPosition.MOrientation.z = playerrot.MOrientation.z;
         targetPosition.MAngle = playerrot.MAngle;
         }
     player.setTransform(targetPosition);
     Point3F playervelocity = player.getVelocity();
     playervelocity = playervelocity.vectorScale(exit["exitVelocityScale"].AsFloat());
     player.setVelocity(playervelocity);
     // Prevent the object from doing an immediate second teleport
     // In the case of a bidirectional teleporter
     player["isTeleporting"] = true.AsString();
     }
        public void PlayerSetDamageDirection(coPlayer player, coPlayer sourceObject, TransformF damagePos)
            {
            if (sourceObject.isObject())
                damagePos = console.isField(sourceObject, "initialPosition") ? new TransformF(sourceObject["initialPosition"]) : sourceObject.getTransform();


            TransformF dp = damagePos;
            Point3F wbc = player.getWorldBoxCenter();

            TransformF damagevec = dp - new TransformF(wbc);
            damagevec = damagevec.normalizeSafe();

            coGameConnection client = player["client"];
            if (!client.isObject())
                return;


            coCamera cameraobject = client.getCameraObject();

            TransformF inverseTransform = cameraobject.getInverseTransform();
            damagevec = math.MatrixMulVector(inverseTransform, damagevec.MPosition);

            float[] components = new float[6];
            string[] directions = new string[6];
            directions[0] = "Left";
            directions[1] = "Right";
            directions[2] = "Bottom";
            directions[3] = "Front";
            directions[4] = "Bottom";
            directions[5] = "Top";

            components[0] = -damagevec.MPosition.x;
            components[1] = damagevec.MPosition.x;
            components[2] = -damagevec.MPosition.y;
            components[3] = damagevec.MPosition.y;
            components[4] = -damagevec.MPosition.z;
            components[5] = damagevec.MPosition.z;
            string damagedirection = string.Empty;
            float max = 0;
            for (int i = 0; i < 6; i++)
                {
                if (components[i] <= max)
                    continue;
                damagedirection = directions[i];
                max = components[i];
                }

            if (console.isObject(client))
                console.commandToClient(client, console.addTaggedString("setDamageDirection"), new[] { damagedirection });
            }
 public void PlayerKill(coPlayer player, string damageType)
     {
     ShapeBaseDamage(player, "0", player.getTransform().MPosition, 10000, damageType);
     }
        public void ArmorOnImpact(coPlayerData datablock, coPlayer player, coShapeBase collidedObject, TransformF vec, float vecLen)
            {
            TransformF p = player.getTransform();
            p = p + vec;
            float speedDamageScale = vecLen + datablock["speedDamageScale"].AsFloat();

            ShapeBaseDamage(player, "0", p.MPosition, speedDamageScale, "Impact");
            }
        public void ArmorDoDismount(coPlayerData datablock, coPlayer player, bool forced)
            {
            coVehicle vehicle = player["mVehicle"];
            if (!vehicle.isObject())
                return;
            if (!player.isMounted())
                return;


            Point3F vvel = vehicle.getVelocity();
            coVehicleData vdb = vehicle.getDataBlock();
            int maxDismountSpeed = vdb["maxDismountSpeed"].AsInt();
            if ((vvel.len() <= maxDismountSpeed) || (forced))
                {
                TransformF pos = player.getTransform();
                TransformF rot = pos;
                TransformF oldpos = pos.copy();

                List<Point3F> vecs = new List<Point3F> { new Point3F(-1, 0, 0), new Point3F(0, 0, 1), new Point3F(0, 0, -1), new Point3F(1, 0, 0), new Point3F(0, -1, 0), new Point3F(0, 0, 0) };

                Point3F impulsevec = new Point3F(0, 0, 0);


                TransformF r = math.MatrixMulVector(player.getTransform(), vecs[0]);

                vecs[0] = r.MPosition;
                pos.MPosition.x = 0;
                pos.MPosition.y = 0;
                pos.MPosition.z = 0;

                const int numofAttempts = 5;
                int success = -1;

                for (int i = 0; i < numofAttempts; i++)
                    {
                    Point3F vectorscale = vecs[i].vectorScale(3);

                    pos = oldpos + new TransformF(vectorscale);
                    if (!player.checkDismountPoint(oldpos.MPosition, pos.MPosition))
                        continue;
                    success = i;
                    impulsevec = vecs[i].copy();
                    break;
                    }
                if ((forced) && (success == -1))
                    pos = oldpos.copy();

                player["mountVehicle"] = false.AsString();
                player.schedule("4000", "mountVehicles", "true");
                player.unmount();
                player.setTransform(new TransformF(pos.MPosition.x, pos.MPosition.y, pos.MPosition.z, rot.MOrientation.x, rot.MOrientation.y, rot.MOrientation.z, rot.MAngle));


                Point3F velo = impulsevec.vectorScale(player["mass"].AsFloat());
                velo.z = 1;

                player.applyImpulse(pos.MPosition, velo);


                Point3F vel = player.getVelocity();
                float vec = Point3F.vectorDot(vel, vel.normalizeSafe());
                if (vec > 50)
                    {
                    float scale = 50 / vec;
                    player.setVelocity(vel.vectorScale(scale));
                    }
                }
            else
                {
                MessageClient(player["client"], "msgUnmount", @"\c2Cannot exit %1 while moving.", console.GetVarString(vdb + ".nameTag"));
                }
            }