RAGECOOP-V/Client/PlayerList.cs

69 lines
2.2 KiB
C#
Raw Normal View History

2021-07-07 13:36:25 +02:00
using System;
using System.Collections.Generic;
using CoopClient.Entities;
using GTA;
using GTA.Native;
namespace CoopClient
{
2021-08-13 15:20:26 +02:00
public class PlayerList : Script
2021-07-07 13:36:25 +02:00
{
private readonly Scaleform MainScaleform = new Scaleform("mp_mm_card_freemode");
2021-08-13 15:20:26 +02:00
private int LastUpdate = Environment.TickCount;
public static int Pressed { get; set; }
2021-07-07 13:36:25 +02:00
2021-08-13 15:20:26 +02:00
public PlayerList()
{
Init();
Tick += OnTick;
}
private void OnTick(object sender, EventArgs e)
{
if ((Environment.TickCount - LastUpdate) >= 1000)
{
Update(Main.Players, Main.MainSettings.Username);
}
if (!Main.MainNetworking.IsOnServer())
{
return;
}
if ((Environment.TickCount - Pressed) < 5000 && !Main.MainChat.Focused && !Main.MainMenu.MenuPool.AreAnyVisible)
{
Function.Call(Hash.DRAW_SCALEFORM_MOVIE, MainScaleform.Handle, 0.122f, 0.3f, 0.28f, 0.6f, 255, 255, 255, 255, 0);
}
}
private void Init()
2021-07-07 13:36:25 +02:00
{
MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
2021-08-13 15:20:26 +02:00
MainScaleform.CallFunction("SET_DATA_SLOT", 0, "", "Me", 116, 0, 0, "", "", 2, "", "", ' ');
2021-07-07 13:36:25 +02:00
MainScaleform.CallFunction("SET_TITLE", "Player list", "1 players");
MainScaleform.CallFunction("DISPLAY_VIEW");
}
2021-08-13 15:20:26 +02:00
private void Update(Dictionary<string, EntitiesPlayer> players, string localUsername)
2021-07-07 13:36:25 +02:00
{
2021-08-13 15:20:26 +02:00
LastUpdate = Environment.TickCount;
2021-07-07 13:36:25 +02:00
MainScaleform.CallFunction("SET_DATA_SLOT_EMPTY", 0);
2021-08-13 15:20:26 +02:00
MainScaleform.CallFunction("SET_DATA_SLOT", 0, "", localUsername, 116, 0, 0, "", "", 2, "", "", ' ');
2021-07-07 13:36:25 +02:00
int i = 1;
2021-08-13 15:20:26 +02:00
2021-07-07 13:36:25 +02:00
foreach (KeyValuePair<string, EntitiesPlayer> player in players)
{
2021-08-13 15:20:26 +02:00
MainScaleform.CallFunction("SET_DATA_SLOT", i++, player.Value.Latency + "ms", player.Value.Username, 116, 0, i - 1, "", "", 2, "", "", ' ');
2021-07-07 13:36:25 +02:00
}
MainScaleform.CallFunction("SET_TITLE", "Player list", (players.Count + 1) + " players");
MainScaleform.CallFunction("DISPLAY_VIEW");
}
}
}