コード例 #1
0
        // Handles cutting | saw storage and grab | saw pickup and drop
        private async Task OnTick()
        {
            await Task.FromResult(0);

            if (ScriptReady)
            {
                if (CurrentSaw == null)
                {
                    Vehicle truck = GetVehicleInArea();

                    // Grabbing saw from vehicle
                    if (truck != null)
                    {
                        var CheckedVehicle = CheckCastedVehicle(truck);
                        if (CheckedVehicle != null)
                        {
                            World.DrawMarker(MarkerType.HorizontalCircleSkinny, truck.GetOffsetPosition(CheckedVehicle.MarkerPos), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), System.Drawing.Color.FromArgb(255, 0, 0), false, false, true, null, null, false);
                            if (World.GetDistance(LocalPlayer.Character.Position, truck.GetOffsetPosition(CheckedVehicle.MarkerPos)) <= 1.2f)
                            {
                                Screen.DisplayHelpTextThisFrame($"~INPUT_PICKUP~ Retrieve Saw");
                                if (Game.IsControlJustPressed(1, Control.Pickup))
                                {
                                    await RetrieveSaw();
                                }
                            }
                        }
                    }

                    // Pickup Saw From Ground
                    var LocalPedPos        = LocalPlayer.Character.Position;
                    var closestSaw         = API.GetClosestObjectOfType(LocalPedPos.X, LocalPedPos.Y, LocalPedPos.Z, 5f, (uint)API.GetHashKey(SawModel), false, true, true);
                    var closestSawPos      = API.GetEntityCoords(closestSaw, false);
                    var closestSawDistance = World.GetDistance(LocalPedPos, API.GetEntityCoords(closestSaw, false));

                    if (closestSaw != 0 && !LocalPlayer.Character.IsInVehicle() && API.GetEntityAttachedTo(closestSaw) == 0)
                    {
                        World.DrawMarker(MarkerType.HorizontalCircleSkinny, closestSawPos, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), System.Drawing.Color.FromArgb(255, 0, 0), false, false, true, null, null, false);
                        if (closestSawDistance <= 1.2f)
                        {
                            Screen.DisplayHelpTextThisFrame($"~INPUT_PICKUP~ Pickup Saw");
                            if (Game.IsControlJustPressed(1, Control.Pickup))
                            {
                                await PickupSaw(closestSaw);
                            }
                        }
                    }
                }
                else
                {
                    Game.DisableControlThisFrame(1, Control.Attack);
                    Game.DisableControlThisFrame(1, Control.Attack2);
                    Game.DisableControlThisFrame(1, Control.Jump);
                    Game.DisableControlThisFrame(1, Control.Aim);
                    Game.DisableControlThisFrame(1, Control.Enter);
                    if (LocalPlayer.Character.Weapons.Current.Hash != WeaponHash.Unarmed)
                    {
                        API.SetCurrentPedWeapon(LocalPlayer.Character.Handle, (uint)WeaponHash.Unarmed, true);
                    }

                    Vehicle truck   = GetVehicleInArea();
                    Vehicle vehicle = GetVehicleFromCast();

                    // Storing saw to vehicle
                    if (truck != null)
                    {
                        var CheckedVehicle = CheckCastedVehicle(truck);
                        if (CheckedVehicle != null)
                        {
                            World.DrawMarker(MarkerType.HorizontalCircleSkinny, truck.GetOffsetPosition(CheckedVehicle.MarkerPos), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(1f, 1f, 1f), System.Drawing.Color.FromArgb(255, 0, 0), false, false, true, null, null, false);
                            if (World.GetDistance(LocalPlayer.Character.Position, truck.GetOffsetPosition(CheckedVehicle.MarkerPos)) <= 1.2f)
                            {
                                Screen.DisplayHelpTextThisFrame($"~INPUT_PICKUP~ Store Saw");
                                if (Game.IsControlJustPressed(1, Control.Pickup))
                                {
                                    StoreSaw();
                                }
                            }
                        }
                    }
                    else
                    {
                        // Dropping Saw
                        if (Game.IsControlJustPressed(1, Control.Detonate))
                        {
                            await DropSaw();
                        }
                    }

                    // Cutting Logic
                    if (KeyHolding && GetClosestDoorBone(vehicleBeingCut) != (VehicleDoorIndex)(-1) && !vehicleBeingCut.Doors[GetClosestDoorBone(vehicleBeingCut)].IsBroken)
                    {
                        if (Game.IsDisabledControlPressed(1, Control.Attack))
                        {
                            if (Game.GameTime > KeyHoldStartTime)
                            {
                                KeyHolding       = false;
                                KeyHoldStartTime = 0;
                                TriggerServerEvent("ExtractionSaw:StopSawCutSync", CurrentSawNetHandle);
                                VehicleDoorIndex doorIndex = GetClosestDoorBone(vehicle);
                                CutDoor(vehicleBeingCut, doorIndex);
                            }
                            BarTimerBar bar = new BarTimerBar("Cutting Door");
                            bar.Percentage = 1f - (float)(((KeyHoldStartTime - Game.GameTime) / 1000) * 0.1m) - 0.1f;
                            bar.Draw(0);
                        }
                        else
                        {
                            KeyHoldStartTime = 0;
                            KeyHolding       = false;
                            TriggerServerEvent("ExtractionSaw:StopSawCutSync", CurrentSawNetHandle);
                        }
                    }
                    else
                    {
                        if (Game.IsDisabledControlPressed(1, Control.Attack) && GetClosestDoorBone(vehicle) != (VehicleDoorIndex)(-1))
                        {
                            KeyHoldStartTime = Game.GameTime + (CutTimer * 1000);
                            vehicleBeingCut  = vehicle;
                            KeyHolding       = true;
                        }
                    }

                    // Saw Particle Syncing
                    if (KeyHolding)
                    {
                        LoopParticles();
                    }
                }
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: BobbySwaggTV/WeRP-Server
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task OnTick()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            // Watermark
            API.SetTextFont(1);
            API.SetTextProportional(true);
            API.SetTextScale(0.0F, 0.6F);
            API.SetTextColour(192, 192, 192, 255);
            API.SetTextDropshadow(0, 0, 0, 0, 255);
            API.SetTextEdge(1, 0, 1, 0, 255);
            API.SetTextDropShadow();
            API.SetTextOutline();
            API.SetTextEntry("STRING");
            API.AddTextComponentString("~b~We~w~RP");
            API.DrawText(0.005F, 0.005F);

            API.SetTextFont(4);
            API.SetTextProportional(true);
            API.SetTextScale(0.0F, 0.5F);
            API.SetTextColour(192, 192, 192, 255);
            API.SetTextDropshadow(0, 0, 0, 0, 255);
            API.SetTextEdge(1, 0, 1, 0, 255);
            API.SetTextDropShadow();
            API.SetTextOutline();
            API.SetTextEntry("STRING");
            API.AddTextComponentString("v" + Assembly.GetExecutingAssembly().GetName().Version);
            API.DrawText(0.044F, 0.0058F);

            // Player Location Display
            // Coordinates
            int     playerPed      = API.GetPlayerPed(-1);
            Vector3 playerPosition = API.GetEntityCoords(playerPed, true);
            String  posX           = String.Format("{0:0.00}", playerPosition.X);
            String  posY           = String.Format("{0:0.00}", playerPosition.Y);
            String  posZ           = String.Format("{0:0.00}", playerPosition.Z);

            API.SetTextFont(4);
            API.SetTextScale(0.0F, 0.5F);
            API.SetTextColour(255, 255, 255, 255);
            API.SetTextDropshadow(0, 0, 0, 0, 255);
            API.SetTextEdge(1, 0, 1, 0, 255);
            API.SetTextDropShadow();
            API.SetTextOutline();
            API.SetTextEntry("STRING");
            API.AddTextComponentString("~r~X~w~: " + posX + "\n~r~Y~w~: " + posY + "\n~r~Z~w~: " + posZ);
            API.DrawText(0.005F, 0.042F);

            // Location
            String direction    = this.GetPlayerDirection(playerPed);
            float  safezoneSize = API.GetSafeZoneSize();
            float  screenWidth  = Screen.Width;
            float  screenHeight = Screen.Height;
            PointF offset       = new PointF((int)Math.Round((screenWidth - (screenWidth * safezoneSize)) / 2 + 1), (int)Math.Round((screenHeight - (screenHeight * safezoneSize)) / 2 - 2));

            Vector3 position  = API.GetEntityCoords(playerPed, true);
            float   xPosition = (0.145F + ((1.0F - safezoneSize) / 2));
            float   yPosition = (0.825F - ((1.0F - safezoneSize) / 2));

            uint streetNameHash   = 0;
            uint crossingRoadHash = 0;

            API.GetStreetNameAtCoord(position.X, position.Y, position.Z, ref streetNameHash, ref crossingRoadHash);

            String streetName       = API.GetStreetNameFromHashKey(streetNameHash);
            String streetNameOutput = streetName;
            String crossingRoad     = API.GetStreetNameFromHashKey(crossingRoadHash);

            if (crossingRoad != "")
            {
                streetNameOutput += " / " + crossingRoad;
            }

            String zoneName = Helper.GetZoneFullname(API.GetNameOfZone(position.X, position.Y, position.Z));

            API.SetTextFont(2);
            API.SetTextScale(0.0F, 0.9F);
            API.SetTextColour(255, 255, 255, 255);
            API.SetTextDropshadow(0, 0, 0, 0, 255);
            API.SetTextEdge(1, 0, 1, 0, 255);
            API.SetTextDropShadow();
            API.SetTextOutline();
            API.SetTextEntry("STRING");
            API.AddTextComponentString(direction);
            API.DrawText(xPosition, yPosition);

            API.SetTextFont(4);
            API.SetTextScale(0.0F, 0.6F);
            API.SetTextColour(198, 198, 198, 255);
            API.SetTextDropshadow(0, 0, 0, 0, 255);
            API.SetTextEdge(1, 0, 1, 0, 255);
            API.SetTextDropShadow();
            API.SetTextOutline();
            API.SetTextEntry("STRING");
            API.AddTextComponentString(streetNameOutput);
            API.DrawText(xPosition, yPosition + 0.047F);

            API.SetTextFont(2);
            API.SetTextScale(0.0F, 0.4F);
            API.SetTextColour(240, 200, 80, 255);
            API.SetTextDropshadow(0, 0, 0, 0, 255);
            API.SetTextEdge(1, 0, 1, 0, 255);
            API.SetTextDropShadow();
            API.SetTextOutline();
            API.SetTextEntry("STRING");
            API.AddTextComponentString(zoneName);
            API.DrawText(xPosition, yPosition + 0.085F);
        }