FirstScript and FirstGameMode updated

This commit is contained in:
EntenKoeniq 2021-11-27 01:23:19 +01:00
parent b3391f3da0
commit 9736bc9635
2 changed files with 39 additions and 19 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.ComponentModel;
using System.Timers;
using System.Linq;
@ -7,14 +6,6 @@ using CoopServer;
namespace FirstGameMode
{
[Serializable]
public class SetPlayerTime
{
public int Hours { get; set; }
public int Minutes { get; set; }
public int Seconds { get; set; }
}
public class Main : ServerScript
{
private static readonly Timer RunningSinceTimer = new() { Interval = 1000 };
@ -64,17 +55,17 @@ namespace FirstGameMode
args.Cancel = true;
// Get data from bytes
SetPlayerTime setPlayerTime = bytes.CDeserialize<SetPlayerTime>();
// Find the client by 'from' and send the time back as a nativecall
//API.GetAllClients().Find(x => x.ID == from).SendNativeCall(0x47C3B5848C3E45D8, setPlayerTime.Hours, setPlayerTime.Minutes, setPlayerTime.Seconds);
// Find the client by 'target' and send the time back as a nativecall
Client targetClient = API.GetAllClients().FirstOrDefault(x => x.ID == target);
Client fromClient = API.GetAllClients().FirstOrDefault(x => x.ID == target);
Client targetClient = API.GetAllClients().Find(x => x.ID == target);
targetClient.SendChatMessage($"New modpacket nativecall from \"{API.GetAllClients().FirstOrDefault(x => x.ID == from)?.Player.Username}\"");
targetClient.SendNativeCall(0x47C3B5848C3E45D8, setPlayerTime.Hours, setPlayerTime.Minutes, setPlayerTime.Seconds);
fromClient.SendChatMessage($"New modpacket nativecall from \"{targetClient?.Player.Username}\"");
// Send packet to target
targetClient.SendModPacket("FirstScript", 1, bytes);
}
public void RunningCommand(CommandContext ctx)

View File

@ -1,6 +1,7 @@
using System;
using GTA;
using GTA.Native;
namespace FirstScript
{
@ -30,11 +31,11 @@ namespace FirstScript
CoopClient.Interface.OnConnection += OnConnection;
}
private void OnConnection(bool connected, string reason = null)
private void OnConnection(bool connected, long id, string reason = null)
{
if (connected)
{
CoopClient.Interface.SendChatMessage("Mod", "Welcome!");
CoopClient.Interface.LocalChatMessage("Mod", "Welcome!");
}
else
{
@ -60,12 +61,40 @@ namespace FirstScript
return;
}
CoopClient.Entities.EntitiesPlayer fromClient;
switch (customID)
{
case 0:
TestPacketClass testPacketClass = CoopClient.CoopSerializer.CDeserialize<TestPacketClass>(bytes);
GTA.UI.Notification.Show($"ModPacket(0)({from}): A[{testPacketClass.A}] B[{testPacketClass.B}]");
fromClient = CoopClient.Interface.GetPlayer(from);
if (fromClient == null)
{
if (from != CoopClient.Interface.GetLocalID())
{
GTA.UI.Notification.Show($"ClientID [{from}] not found!");
}
else
{
GTA.UI.Notification.Show($"ModPacket(0): A[{testPacketClass.A}] B[{testPacketClass.B}]");
}
}
else
{
GTA.UI.Notification.Show($"ModPacket(0)({fromClient.Username}): A[{testPacketClass.A}] B[{testPacketClass.B}]");
}
break;
case 1:
SetPlayerTimePacket setPlayerTimePacket = CoopClient.CoopSerializer.CDeserialize<SetPlayerTimePacket>(bytes);
fromClient = CoopClient.Interface.GetPlayer(from);
if (fromClient != null)
{
GTA.UI.Notification.Show($"Player {fromClient.Username} changed the time to: {setPlayerTimePacket.Hours}, {setPlayerTimePacket.Minutes}, {setPlayerTimePacket.Seconds}");
}
Function.Call(Hash.SET_CLOCK_TIME, setPlayerTimePacket.Hours, setPlayerTimePacket.Minutes, setPlayerTimePacket.Seconds);
break;
default:
GTA.UI.Notification.Show($"ModPacket({from}): ~r~Unknown customID!");