Jump to content

C# How do you set the ped of my player?


Recommended Posts

Posted (edited)

Actually it does not explain anything, if you are asking how to access your local player, its RAGE.Elements.Player.LocalPlayer

Edited by Kopra
Posted (edited)

I sorted it but I have another problem. I've written a noclip clientside script but it doesnt work. All it does is create a camera that won't move:

 

using RAGE;
using System;
using System.Collections.Generic;
using System.Text;

namespace SOCRPClient
{
    internal class NoClip : Events.Script
    {
        int noClipCamera;

        bool isEnabled;
        RAGE.Elements.Player localPlayer = RAGE.Elements.Player.LocalPlayer;

        int W = 32, S = 33, A = 34, D = 35, Space = 321, LCtrl = 326;

        float flyingSpeedMultiplier = 2.0f;

        public NoClip()
        {
            Events.Add("StartNoClip", StartNoClip);
            Events.Tick += Tick
        }

        public void StartNoClip(object[] args)
        {
            isEnabled = (bool)args[0];


            var camPos = new Vector3(
                localPlayer.Position.X,
                localPlayer.Position.Y,
                localPlayer.Position.Z
            );
            var camRot = RAGE.Game.Cam.GetGameplayCamRot(2);
            int noClipCamera = 0;

            noClipCamera = RAGE.Game.Cam.CreateCameraWithParams(
                RAGE.Game.Misc.GetHashKey("gameplay"),
                camPos.X, camPos.Y, camPos.Z,
                camRot.X, camRot.Y, camRot.Z,
                70.0f,
                true, 2
            );


            if (isEnabled)
            {
                RAGE.Game.Cam.SetCamActive(noClipCamera, true);
                RAGE.Game.Cam.RenderScriptCams(true, false, 0, true, false, 0);
                localPlayer.FreezePosition(true);
                localPlayer.SetInvincible(true);
                localPlayer.SetVisible(true, false);
                localPlayer.SetCollision(false, false);
            }
            else
            {
                RAGE.Game.Cam.DestroyCam(noClipCamera, true);
                RAGE.Game.Cam.RenderScriptCams(false, false, 0, true, false, 0);
                localPlayer.FreezePosition(false);
                localPlayer.SetInvincible(false);
                localPlayer.SetVisible(true, false);
                localPlayer.SetCollision(true, false);
            }

        }

        public void Tick(List<Events.TickNametagData> nametags)
        {
            bool isUpdated = false;
            if (!RAGE.Game.Cam.DoesCamExist(noClipCamera)) return;

            var position = RAGE.Elements.Player.LocalPlayer.Position;
            var direction = RAGE.Game.Cam.GetCamRot(noClipCamera, 2);

            if (RAGE.Input.IsDown(W))
            {
                position.X += direction.X * flyingSpeedMultiplier;
                position.Y += direction.Y * flyingSpeedMultiplier;
                position.Z += direction.Z * flyingSpeedMultiplier;
                isUpdated = true;
            }
            else if(RAGE.Input.IsDown(S))
            {
                position.X -= direction.X * flyingSpeedMultiplier;
                position.Y -= direction.Y * flyingSpeedMultiplier;
                position.Z -= direction.Z * flyingSpeedMultiplier;
                isUpdated = true;
            }

            if (RAGE.Input.IsDown(D))
            {
                position.X += (-direction.Y) * flyingSpeedMultiplier;
                position.Y += direction.X * flyingSpeedMultiplier;
                isUpdated = true;
            }
            else if (RAGE.Input.IsDown(32))
            {
                position.X -= (-direction.Y) * flyingSpeedMultiplier;
                position.Y -= direction.X * flyingSpeedMultiplier;
                isUpdated = true;
            }

            if(RAGE.Input.IsDown(Space))
            {
                position.Z += flyingSpeedMultiplier;
                isUpdated = true;
            }
            else if(RAGE.Input.IsDown(LCtrl))
            {
                position.Z -= flyingSpeedMultiplier;
                isUpdated = true;
            }

            if (isUpdated)
            {
                RAGE.Game.Cam.SetCamCoord(noClipCamera, position.X, position.Y, position.Z);
            }

        }
    }
}

 

The camera won't move or turn.

 

Edited by inesiati
Posted

You will have to debug it and see which part of code is problematic.
Check if this returns correct value.

if (!RAGE.Game.Cam.DoesCamExist(noClipCamera)) return;

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...