Skip to content

Commit

Permalink
Add config.json
Browse files Browse the repository at this point in the history
The update rate for coordinate blips can now be adjusted in real-time.
  • Loading branch information
DefinitelyNotNoah committed Nov 12, 2023
1 parent f0f138e commit 6958326
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Server/Server.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CitizenFX.Core;
using CitizenFX.Server;
using CitizenFX.Server.Native;
using Newtonsoft.Json;

namespace Server;

Expand All @@ -13,7 +15,7 @@ public class ServerScript : BaseScript
private void SendPlayerData()
{
IDictionary<string, object> playerData = new Dictionary<string, object>();

// Loop through all the players known to the server, where their ped entity exists.
foreach (Player player in new PlayerList().ToList().Where(player => player.Character != null))
{
Expand All @@ -28,35 +30,39 @@ private void SendPlayerData()
Natives.GetEntityModel(vehicle),
Natives.GetEntityRoutingBucket(player.Character.Handle)
};

// Update player state bags to make routing buckets known client-side.
player.State["bucket"] = Natives.GetEntityRoutingBucket(player.Character.Handle);
}

Events.TriggerAllClientsEvent("PlayerBlips-Client:ReceivePlayerData", playerData);
}

[EventHandler("playerEnteredScope")]
public void PlayerEnteredScopeServerEvent(IDictionary<string, object> data)
{
Events.TriggerAllClientsEvent("PlayerBlips-Client:PlayerEnteredScope", data["for"], data["player"]);
}

[EventHandler("playerLeftScope")]
public void PlayerLeftScopeServerEvent(IDictionary<string, object> data)
{
Events.TriggerAllClientsEvent("PlayerBlips-Client:PlayerLeftScope", data["for"], data["player"]);
}

[EventHandler("playerDropped")]
public void PlayerDroppedServerEvent([Source] Player source, string reason)
{
Events.TriggerAllClientsEvent("PlayerBlips-Client:PlayerDropped", source.Handle);
}

[Tick]
public async Coroutine OnTick()
{
SendPlayerData();
await Wait(500);
string config = File.ReadAllText(Natives.GetResourcePath("playerblips") + "/config.json");
dynamic json = JsonConvert.DeserializeObject<dynamic>(config);

await Wait((uint)json["Delay"]);
}
}
2 changes: 2 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ game 'gta5'

mono_rt2 'Prerelease expiring 2023-06-30. See https://aka.cfx.re/mono-rt2-preview for info.'

file 'bin/Newtonsoft.Json.dll'

client_script 'bin/Client.net.dll'
server_script 'bin/Server.net.dll'

0 comments on commit 6958326

Please sign in to comment.