Add keybind, label, nametag, scoreboard scripts
This commit is contained in:
6
meta.xml
6
meta.xml
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
<script src="scripts/server/account.js" type="server" language="javascript" />
|
<script src="scripts/server/account.js" type="server" language="javascript" />
|
||||||
<script src="scripts/server/ammunation.js" type="server" language="javascript" />
|
<script src="scripts/server/ammunation.js" type="server" language="javascript" />
|
||||||
|
<script src="scripts/server/anticheat.js" type="server" language="javascript" />
|
||||||
<script src="scripts/server/ban.js" type="server" language="javascript" />
|
<script src="scripts/server/ban.js" type="server" language="javascript" />
|
||||||
<script src="scripts/server/bitflag.js" type="server" language="javascript" />
|
<script src="scripts/server/bitflag.js" type="server" language="javascript" />
|
||||||
<script src="scripts/server/business.js" type="server" language="javascript" />
|
<script src="scripts/server/business.js" type="server" language="javascript" />
|
||||||
@@ -74,8 +75,11 @@
|
|||||||
|
|
||||||
<script src="scripts/client/gui.js" type="client" language="javascript" />
|
<script src="scripts/client/gui.js" type="client" language="javascript" />
|
||||||
<script src="scripts/client/main.js" type="client" language="javascript" />
|
<script src="scripts/client/main.js" type="client" language="javascript" />
|
||||||
<script src="scripts/client/nametags.js" type="client" language="javascript" />
|
<script src="scripts/client/nametag.js" type="client" language="javascript" />
|
||||||
<script src="scripts/client/sync.js" type="client" language="javascript" />
|
<script src="scripts/client/sync.js" type="client" language="javascript" />
|
||||||
|
<script src="scripts/client/scoreboard.js" type="client" language="javascript" />
|
||||||
|
<script src="scripts/client/keybind.js" type="client" language="javascript" />
|
||||||
|
<script src="scripts/client/label.js" type="client" language="javascript" />
|
||||||
|
|
||||||
<file type="client" src="files/images/skins/none.png" />
|
<file type="client" src="files/images/skins/none.png" />
|
||||||
<file type="client" src="files/images/skins/gta3/Skin000.png" />
|
<file type="client" src="files/images/skins/gta3/Skin000.png" />
|
||||||
|
|||||||
45
scripts/client/keybind.js
Normal file
45
scripts/client/keybind.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
// ===========================================================================
|
||||||
|
// Asshat-Gaming Roleplay
|
||||||
|
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||||
|
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// FILE: afk.js
|
||||||
|
// DESC: Provides AFK detection
|
||||||
|
// TYPE: Client (JavaScript)
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
let lastKeyBindUse = 0;
|
||||||
|
let keyBindDelayTime = 2000;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function bindAccountKey(key, keyState) {
|
||||||
|
bindKey(toInteger(key), keyState, function(event) {
|
||||||
|
if(hasKeyBindDelayElapsed()) {
|
||||||
|
triggerNetworkEvent("ag.keybind.trig", key);
|
||||||
|
lastKeyBindUse = sdl.ticks;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
addNetworkHandler("ag.keybinds.add", bindAccountKey);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function unBindAccountKey(key) {
|
||||||
|
unbindKey(key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
addNetworkHandler("ag.keybinds.del", unBindAccountKey);
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function hasKeyBindDelayElapsed() {
|
||||||
|
if(sdl.ticks-lastKeyBindUse >= keyBindDelayTime) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
9
scripts/client/label.js
Normal file
9
scripts/client/label.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// ===========================================================================
|
||||||
|
// Asshat-Gaming Roleplay
|
||||||
|
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||||
|
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// FILE: labels.js
|
||||||
|
// DESC: Provides functionality for world labels (3D labels)
|
||||||
|
// TYPE: Client (JavaScript)
|
||||||
|
// ===========================================================================
|
||||||
@@ -4,12 +4,10 @@
|
|||||||
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// FILE: nametags.js
|
// FILE: nametags.js
|
||||||
// DESC: Provides nametags for VRS
|
// DESC: Provides nametag rendering
|
||||||
// TYPE: Client (JavaScript)
|
// TYPE: Client (JavaScript)
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
let nametagFont = null;
|
let nametagFont = null;
|
||||||
let afkStatusFont = null;
|
let afkStatusFont = null;
|
||||||
@@ -17,6 +15,11 @@ let pingFont = null;
|
|||||||
let nametagDistance = 50.0;
|
let nametagDistance = 50.0;
|
||||||
let nametagWidth = 70;
|
let nametagWidth = 70;
|
||||||
|
|
||||||
|
let playerNames = {};
|
||||||
|
let playerColours = {};
|
||||||
|
let playerPaused = {};
|
||||||
|
let playerPing = {};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
addEventHandler("OnResourceReady", function(event, resource) {
|
addEventHandler("OnResourceReady", function(event, resource) {
|
||||||
@@ -28,6 +31,15 @@ addEventHandler("OnResourceReady", function(event, resource) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
addNetworkHandler("ag.nametag", function(mainName, characterName, colour, paused, ping) {
|
||||||
|
playerNames[mainName] = characterName;
|
||||||
|
playerColours[mainName] = colour;
|
||||||
|
playerPaused[mainName] = paused;
|
||||||
|
playerPing[mainName] = ping;
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
function drawNametag(x, y, health, armour, text, ping, alpha, distance, colour, afk, skin) {
|
function drawNametag(x, y, health, armour, text, ping, alpha, distance, colour, afk, skin) {
|
||||||
if(nametagFont == null) {
|
if(nametagFont == null) {
|
||||||
return false;
|
return false;
|
||||||
@@ -49,6 +61,8 @@ function drawNametag(x, y, health, armour, text, ping, alpha, distance, colour,
|
|||||||
} else {
|
} else {
|
||||||
y -= 5;
|
y -= 5;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
y -= 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(health > 0.0) {
|
if(health > 0.0) {
|
||||||
@@ -121,21 +135,26 @@ function updateNametags(element) {
|
|||||||
if(element.type == ELEMENT_PLAYER) {
|
if(element.type == ELEMENT_PLAYER) {
|
||||||
let name = element.name;
|
let name = element.name;
|
||||||
let colour = COLOUR_WHITE;
|
let colour = COLOUR_WHITE;
|
||||||
let afk = false;
|
let paused = false;
|
||||||
|
let ping = -1;
|
||||||
|
|
||||||
if(getEntityData(client, "ag.name") != null) {
|
if(typeof playerNames[element.name] != "undefined") {
|
||||||
name = getEntityData(client, "ag.name");
|
name = playerNames[element.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getEntityData(client, "ag.afk") != null) {
|
if(typeof playerPaused[element.name] != "undefined") {
|
||||||
afk = true;
|
paused = playerPaused[element.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getEntityData(client, "ag.colour") != null) {
|
if(typeof playerColours[element.name] != "undefined") {
|
||||||
colour = getEntityData(client, "ag.colour");
|
colour = playerColours[element.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(typeof playerPing[element.name] != "undefined") {
|
||||||
|
ping = playerPing[element.name];
|
||||||
|
}
|
||||||
|
|
||||||
drawNametag(screenPos[0], screenPos[1], health, armour, name, 0, 1.0-distance/nametagDistance, distance, colour, afk, element.skin);
|
drawNametag(screenPos[0], screenPos[1], health, armour, name, ping, 1.0-distance/nametagDistance, distance, colour, paused, element.skin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,13 +174,15 @@ function getClientFromPlayer(player) {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
addEventHandler("OnDrawnHUD", function(event) {
|
addEventHandler("OnDrawnHUD", function(event) {
|
||||||
//if(gta.game >= GAME_GTA_IV) {
|
if(gta.game >= GAME_GTA_IV) {
|
||||||
// return false;
|
return false;
|
||||||
//}
|
}
|
||||||
|
|
||||||
//getElementsByType(ELEMENT_PLAYER).forEach(function(player) {
|
getElementsByType(ELEMENT_PLAYER).forEach(function(player) {
|
||||||
// updateNametags(player)
|
if(player != localPlayer) {
|
||||||
//})
|
updateNametags(player);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
79
scripts/client/scoreboard.js
Normal file
79
scripts/client/scoreboard.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// ===========================================================================
|
||||||
|
// Asshat-Gaming Roleplay
|
||||||
|
// https://github.com/VortrexFTW/gtac_asshat_rp
|
||||||
|
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// FILE: scoreboard.js
|
||||||
|
// DESC: Provides scoreboard feature and rendering
|
||||||
|
// TYPE: Client (JavaScript)
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
let titleFont = null;
|
||||||
|
let listFont = null;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bindEventHandler("OnResourceReady", thisResource, function(event, resource) {
|
||||||
|
titleFont = lucasFont.createDefaultFont(22.0, "Roboto", "Medium");
|
||||||
|
listFont = lucasFont.createDefaultFont(12.0, "Roboto", "Light");
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
addEventHandler("OnDrawnHUD", function (event) {
|
||||||
|
if(isKeyDown(SDLK_TAB)) {
|
||||||
|
if(listFont != null && titleFont != null) {
|
||||||
|
let scoreboardStart = (game.height/2)-(Math.floor(getClients().length/2)*20);
|
||||||
|
let titleSize = titleFont.measure("PLAYERS", game.width, 0.0, 1.0, 10, false, false);
|
||||||
|
titleFont.render("PLAYERS", [game.width/2, scoreboardStart-50], 0, 0.5, 0.0, titleFont.size, COLOUR_WHITE, false, false, false, true);
|
||||||
|
|
||||||
|
titleSize = titleFont.measure("____________________________", game.width, 0.0, 1.0, 10, false, false);
|
||||||
|
titleFont.render("____________________________", [game.width/2, scoreboardStart-35], 0, 0.5, 0.0, titleFont.size, COLOUR_WHITE, false, false, false, true);
|
||||||
|
|
||||||
|
let clients = getClients();
|
||||||
|
for(let i in clients) {
|
||||||
|
let name = element.name;
|
||||||
|
let colour = COLOUR_WHITE;
|
||||||
|
let paused = false;
|
||||||
|
let ping = "-1";
|
||||||
|
|
||||||
|
if(typeof playerNames[clients[i].name] != "undefined") {
|
||||||
|
name = playerNames[clients[i].name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof playerPaused[clients[i].name] != "undefined") {
|
||||||
|
paused = playerPaused[clients[i].name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof playerColours[clients[i].name] != "undefined") {
|
||||||
|
colour = playerColours[clients[i].name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof playerPing[element.name] != "undefined") {
|
||||||
|
ping = toString(playerPing[element.name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Player ID
|
||||||
|
let text = String(clients[i].index);
|
||||||
|
let size = listFont.measure(text, 75, 0.0, 1.0, 10, false, false);
|
||||||
|
listFont.render(text, [game.width/2-100, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, COLOUR_WHITE, false, false, false, true);
|
||||||
|
|
||||||
|
// Player Name
|
||||||
|
text = name;
|
||||||
|
size = listFont.measure(text, 100, 0.0, 1.0, 10, false, false);
|
||||||
|
listFont.render(text, [game.width/2, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, colour, false, false, false, true);
|
||||||
|
|
||||||
|
// Ping
|
||||||
|
|
||||||
|
size = listFont.measure(ping, 75, 0.0, 1.0, 10, false, false);
|
||||||
|
listFont.render(ping, [game.width/2+100, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, COLOUR_WHITE, false, false, false, true);
|
||||||
|
|
||||||
|
// PAUSED Status (depends on resource "afk")
|
||||||
|
if(paused == true) {
|
||||||
|
size = listFont.measure("PAUSED", 100, 0.0, 1.0, 10, false, false);
|
||||||
|
listFont.render("PAUSED", [game.width/2+200, scoreboardStart + (i*20)], 0, 0.5, 0.0, listFont.size, COLOUR_RED, false, false, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user