Skip to content

Commit

Permalink
External voice connection status
Browse files Browse the repository at this point in the history
Random hairs and colors
Player respawn fix
  • Loading branch information
emcifuntik committed Sep 15, 2023
1 parent 54a5532 commit 76d89de
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 14 deletions.
25 changes: 25 additions & 0 deletions freeroam-extended/client/html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,30 @@ function setStreamedEntities(players, vehicles) {
document.querySelector(".streamed-in-vehicles").textContent = vehicles
}

function setVoiceConnectionState(state) {
const el = document.querySelector(".voice-server-connection-status").children[0];
el.classList.remove(".voice-connection-status-connected");
el.classList.remove(".voice-connection-status-disconnected");
el.classList.remove(".voice-connection-status-connecting");

let stateText = "Disconnected"
switch(state) {
case 0:
stateText = "Disconnected"
el.classList.add(".voice-connection-status-disconnected")
break;
case 1:
stateText = "Connecting"
el.classList.add(".voice-connection-status-connecting")
break;
case 2:
stateText = "Connected"
el.classList.add(".voice-connection-status-connected")
break;
}
el.textContent = stateText
}

alt.on("addString", (text) => addString(colorify(text)));
alt.on("addMessage", (name, text) => addString("<b>" + name + ": </b>" + colorify(text)));
alt.on("openChat", openChat);
Expand All @@ -207,3 +231,4 @@ alt.on("setPlayerId", setPlayerId);
alt.on("setWeaponsDisabled", setWeaponsDisabled);
alt.on("focusChatInput", focusChatInput);
alt.on("setStreamedEntities", setStreamedEntities)
alt.on("setVoiceConnectionState", setVoiceConnectionState)
5 changes: 4 additions & 1 deletion freeroam-extended/client/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<body>
<div class="stress-test-label">
Public Stress Test - xx.xx.2022
Public Stress Test - v15
</div>
<div class="info">
<div class="players-online">
Expand All @@ -21,6 +21,9 @@
<div class="weapons-enabled">
Weapons <div class="info-number weapons-enabled-on">ON</div>
</div>
<div class="voice-server-connection-status">
Voice connection <div class="info-number voice-connection-status-connected">Connected</div>
</div>
<div class="streamed-in">
Streamed players <div class="info-number streamed-in-players">0</div>
</div>
Expand Down
24 changes: 23 additions & 1 deletion freeroam-extended/client/html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ body {

.help-keys {
position: absolute;
top: 10em;
top: 12em;
right: 1.5em;
text-align: right;
}
Expand Down Expand Up @@ -282,6 +282,28 @@ body {
box-shadow: 0 0 0.5em var(--bg-color) !important;
}

.voice-server-connection-status > * {
color: rgb(255, 255, 255) !important;
}

.voice-connection-status-connected {
--bg-color: rgb(98, 218, 114);
background: var(--bg-color) !important;
box-shadow: 0 0 0.5em var(--bg-color) !important;
}

.voice-connection-status-disconnected {
--bg-color: rgb(235, 91, 86);
background: var(--bg-color) !important;
box-shadow: 0 0 0.5em var(--bg-color) !important;
}

.voice-connection-status-connecting {
--bg-color: rgb(255, 247, 0);
background: var(--bg-color) !important;
box-shadow: 0 0 0.5em var(--bg-color) !important;
}

.streamed-in > * {

}
5 changes: 5 additions & 0 deletions freeroam-extended/client/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toggleNoclip } from "./noclip"
import { playerData } from "./playerdata"
import { view } from "./view"
import { KeyCode, Permission, PermissionState } from "altv-enums"
import type { VoiceConnectionState } from "alt-client"

alt.on("connectionComplete", () => {
setTimeout(() => {
Expand Down Expand Up @@ -116,3 +117,7 @@ alt.onServer("esp", (state: boolean) => {
// }
// })
})

alt.on("voiceConnection", (state: alt.VoiceConnectionState) => {
view.emit("setVoiceConnectionState", state)
})
2 changes: 1 addition & 1 deletion freeroam-extended/client/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export function raycast(

const [, hit, pos,, entity] = native.getShapeTestResult(ray)
return hit
? { pos: pos, entity }
? { pos, entity }
: null
}

Expand Down
3 changes: 2 additions & 1 deletion freeroam-extended/client/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type EventNames =
"setPlayerId" |
"setWeaponsDisabled" |
"focusChatInput" |
"setStreamedEntities"
"setStreamedEntities" |
"setVoiceConnectionState"

class View extends alt.WebView {
public override emit(eventName: EventNames, ...args: unknown[]) {
Expand Down
2 changes: 1 addition & 1 deletion freeroam-extended/server/freeroam-extended/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public void OnPlayerDisconnect(IAltPlayer player, string reason)
[AsyncScriptEvent(ScriptEventType.PlayerDead)]
public async Task OnPlayerDead(IAltPlayer player, IEntity killer, uint weapon)
{
if (killer is not IAltPlayer killerPlayer) return;
var spawnPointPool = player.DmMode ? Misc.AirportSpawnPositions : Misc.SpawnPositions;

var randomSpawnPoint = spawnPointPool.ElementAt(_random.Next(0, spawnPointPool.Length));
Expand All @@ -146,6 +145,7 @@ public async Task OnPlayerDead(IAltPlayer player, IEntity killer, uint weapon)
StatsHandler.StatsData.PlayerDeaths++;
}

if (killer is not IAltPlayer killerPlayer) return;
if (!Misc.BlacklistedWeapons.Contains(weapon)) return;
Alt.Core.LogColored(
$"~r~ Banned Player: {killerPlayer.Name} ({killerPlayer.Id}) for using illegal weapon!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ public void RefreshFace()
this.SetHeadOverlayColor(5, 2, 11, 0);
this.SetHeadOverlayColor(8, 2, 6, 0);

this.SetClothes(2, 3, 0, 0);
this.HairColor = 61;
this.HairHighlightColor = 61;
int hairs = Misc.RandomInt(1, 23);
int hairsColor = Misc.RandomInt(1, 63);
int hairsColor2 = Misc.RandomInt(1, 63);

this.SetClothes(2, (ushort)hairs, 0, 0);
this.HairColor = (byte)hairsColor;
this.HairHighlightColor = (byte)hairsColor2;
this.SetEyeColor(2);

float[] featureParams = { -0.78f, 0, 0, -0.07f, 0.03f, 0, 0.07f, -0.44f, 0.07f, 0.02f, -0.95f, -0.74f, -1, -0.09f, -0.57f, 0.02f, -0.1f, -0.19f, -1, -1 };
Expand Down Expand Up @@ -102,9 +106,13 @@ public void RefreshFace()
this.SetHeadOverlayColor(5, 2, 32, 0);
this.SetHeadOverlayColor(8, 2, 11, 0);

this.SetClothes(2, 21, 0, 0);
this.HairColor = 35;
this.HairHighlightColor = 35;
int hairs = Misc.RandomInt(1, 22);
int hairsColor = Misc.RandomInt(1, 63);
int hairsColor2 = Misc.RandomInt(1, 63);

this.SetClothes(2, (ushort)hairs, 0, 0);
this.HairColor = (byte)hairsColor;
this.HairHighlightColor = (byte)hairsColor2;
this.SetEyeColor(3);

float[] featureParams = { 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 };
Expand All @@ -128,9 +136,8 @@ public async Task RefreshClothes()

ulong[] outfits = await ClothesFitService.GetOutfitsBySex(Sex);

Random rand = new Random();
int randomIndex = rand.Next(outfits.Length);
ulong randomElement = outfits[randomIndex];
int index = Misc.RandomInt(0, outfits.Length - 1);
ulong randomElement = outfits[index];

await ClothesFitService.Equip(this, (uint)randomElement);
}
Expand Down
7 changes: 7 additions & 0 deletions freeroam-extended/server/freeroam-extended/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Freeroam_Extended
{
public static class Misc
{
public static Random random = new Random();
public static HashSet<uint> BlacklistedWeapons = new()
{
125959754, // Compact Grenade Launcher
Expand Down Expand Up @@ -325,5 +326,11 @@ public static bool IsResourceLoaded(string resourceName)
var allResources = Alt.GetAllResources();
return allResources.Count(x => x.Name == resourceName) > 0;
}

public static int RandomInt(int min, int max)
{
int randomNumber = random.Next(min, max + 1);
return randomNumber;
}
}
}

0 comments on commit 76d89de

Please sign in to comment.