Jump to content
RAGE Multiplayer Community

Timer on C# client-side not working


BenX
 Share

Recommended Posts

I'm using C# task to handle event after player spawn, but just look like only the message function work perfectly with the task and others don't.
Here my code:

private void OnPlayerSpawn(Events.CancelEventArgs cancel)
{
  player.FreezePosition(true);
  player.FreezeCameraRotation();
  player.SetInvincible(true);

  RAGE.Game.Graphics.StopScreenEffect("DeathFailMPIn");
  MainCam = RAGE.Game.Cam.CreateCameraWithParams(RAGE.Game.Misc.GetHashKey("DEFAULT_SCRIPTED_CAMERA"), 350.9601f, -638.4666f, 36.8042f, 0, 0, 0, 90.0f, true, 2);
  RAGE.Game.Cam.SetCamActive(Global.Camera.Main, true);
  RAGE.Game.Cam.PointCamAtCoord(Main, 0.02908f, 0.99953f, 0.00921f);
  RAGE.Game.Cam.RenderScriptCams(true, false, 0, true, false, 0);

  Run(() =>
      {
        RAGE.Game.Cam.DestroyCam(MainCam, true);
        RAGE.Game.Cam.RenderScriptCams(false, false, 0, true, false, 0);
        RAGE.Chat.Output("test2");
      }, 2000);
}

public static void Run(Action task, long delayTime = 0)
{
  Task.Factory.StartNew(async () =>
                        {
                          await Task.Delay((int)delayTime);
                          task();
                        });
}

k3xnwlp.jpg

Edited by BenX
Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...
  • 1 month later...

@sui228 is right! It works but;

I'm using compiler to validate my code, so adding this class  into `rage-sharp` nuget package will really help, for now I'm adding in my project to provide intellisense:

 

using System;

namespace RAGE
{
    public class Task
    {
        public static void Run(Action action, int delay)
        {
            // to provide intellisense
            throw new NotImplementedException();
        }

        public static void RunBackground(Action action)
        {
            // to provide intellisense
            throw new NotImplementedException();
        }
    }
}

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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