No message. 83 files changed.

This commit is contained in:
Vortrex
2021-01-11 10:31:49 -06:00
parent ce8579364c
commit 7f2ee0c8d5
83 changed files with 1544 additions and 746 deletions

75
scripts/client/chatbox.js Normal file
View File

@@ -0,0 +1,75 @@
// ===========================================================================
// Asshat-Gaming Roleplay
// https://github.com/VortrexFTW/gtac_asshat_rp
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
// ---------------------------------------------------------------------------
// FILE: chatbox.js
// DESC: Provides extra chatbox features
// TYPE: Client (JavaScript)
// ===========================================================================
// ---------------------------------------------------------------------------
let chatBoxHistory = [];
let bottomMessageIndex = 0;
let scrollAmount = 1;
let maxChatBoxLines = 6;
bindKey(SDLK_PAGEUP, KEYSTATE_DOWN, chatBoxScrollUp);
bindKey(SDLK_PAGEDOWN, KEYSTATE_DOWN, chatBoxScrollDown);
// ---------------------------------------------------------------------------
addNetworkHandler("ag.m", function(messageString, colour) {
message(messageString, colour);
addToChatBoxHistory(messageString, colour);
bottomMessageIndex = chatBoxHistory.length-1;
});
// ---------------------------------------------------------------------------
function addToChatBoxHistory(messageString, colour) {
chatBoxHistory.push([messageString, colour]);
}
// ---------------------------------------------------------------------------
function chatBoxScrollUp() {
if(bottomMessageIndex > maxChatBoxLines) {
bottomMessageIndex = bottomMessageIndex-scrollAmount;
updateChatBox();
}
}
// ---------------------------------------------------------------------------
function chatBoxScrollDown() {
if(bottomMessageIndex < chatBoxHistory.length-1) {
bottomMessageIndex = bottomMessageIndex+scrollAmount;
updateChatBox();
}
}
// ---------------------------------------------------------------------------
function clearChatBox() {
for(let i = 0 ; i <= maxChatBoxLines ; i++) {
message("", COLOUR_WHITE);
}
}
// ---------------------------------------------------------------------------
function updateChatBox() {
clearChatBox();
for(let i = bottomMessageIndex-maxChatBoxLines ; i <= bottomMessageIndex ; i++) {
if(typeof chatBoxHistory[i] != "undefined") {
message(chatBoxHistory[i][0], chatBoxHistory[i][1]);
} else {
message("", COLOUR_WHITE);
}
}
}
// ---------------------------------------------------------------------------

View File

@@ -2178,7 +2178,11 @@ addNetworkHandler("ag.guiColour", function(red, green, blue) {
logToConsole(LOG_DEBUG, `[Asshat.GUI] Received new GUI colours from server`);
primaryColour = [red, green, blue];
focusedColour = [red+focusedColourOffset, green+focusedColourOffset, blue+focusedColourOffset];
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.guiInit", function() {
logToConsole(LOG_DEBUG, `[Asshat.GUI] Initializing MexUI app`);
app.init();
triggerNetworkEvent("ag.guiReady", true);

View File

@@ -3,26 +3,26 @@
// https://github.com/VortrexFTW/gtac_asshat_rp
// Copyright (c) 2020 Asshat-Gaming (https://asshatgaming.com)
// ---------------------------------------------------------------------------
// FILE: afk.js
// DESC: Provides AFK detection
// FILE: keybind.js
// DESC: Provides keybind features
// TYPE: Client (JavaScript)
// ===========================================================================
let lastKeyBindUse = 0;
let keyBindDelayTime = 2000;
let keyBindDelayTime = 2500;
// -------------------------------------------------------------------------
function bindAccountKey(key, keyState) {
bindKey(toInteger(key), keyState, function(event) {
if(hasKeyBindDelayElapsed()) {
triggerNetworkEvent("ag.keybind.trig", key);
lastKeyBindUse = sdl.ticks;
triggerNetworkEvent("ag.useKeyBind", key);
}
});
return false;
}
addNetworkHandler("ag.keybinds.add", bindAccountKey);
addNetworkHandler("ag.addKeyBind", bindAccountKey);
// -------------------------------------------------------------------------
@@ -30,7 +30,7 @@ function unBindAccountKey(key) {
unbindKey(key);
return true;
}
addNetworkHandler("ag.keybinds.del", unBindAccountKey);
addNetworkHandler("ag.delKeyBind", unBindAccountKey);
// -------------------------------------------------------------------------

View File

@@ -48,10 +48,6 @@ function renderPropertyEntranceLabel(name, position, locked, isBusiness, price)
if(propertyLabelLockedFont == null) {
return false;
}
if(localPlayer.position.distance(position) > 7.5) {
return false;
}
let tempPosition = position;
@@ -97,10 +93,6 @@ function renderPropertyExitLabel(position) {
return false;
}
if(localPlayer.position.distance(position) > 7.5) {
return false;
}
let tempPosition = position;
tempPosition.z = tempPosition.z + propertyLabelHeight;
let screenPosition = getScreenFromWorldPosition(tempPosition);
@@ -125,10 +117,6 @@ function renderJobLabel(name, position, jobType) {
return false;
}
if(localPlayer.position.distance(position) > 7.5) {
return false;
}
let tempPosition = position;
tempPosition.z = tempPosition.z + propertyLabelHeight;
let screenPosition = getScreenFromWorldPosition(tempPosition);
@@ -160,52 +148,38 @@ function renderJobLabel(name, position, jobType) {
// -------------------------------------------------------------------------
addEventHandler("OnDrawnHUD", function (event) {
if(!renderHUD) {
return false;
}
if(!renderLabels) {
return false;
}
function processLabelRendering() {
if(localPlayer != null) {
let pickups = getElementsByType(ELEMENT_PICKUP);
for(let i in pickups) {
if(pickups[i].getData("ag.label.type") != null) {
//if(pickups[i].isOnScreen) {
if(getDistance(localPlayer.position, pickups[i].position)) {
//if(pickups[i].interior == localPlayer.interior) {
//if(pickups[i].dimension == localPlayer.dimension) {
let price = 0;
if(pickups[i].getData("ag.label.price") != null) {
price = pickups[i].getData("ag.label.price");
}
switch(pickups[i].getData("ag.label.type")) {
case AG_LABEL_BUSINESS:
renderPropertyEntranceLabel(pickups[i].getData("ag.label.name"), pickups[i].position, pickups[i].getData("ag.label.locked"), true, price);
break;
case AG_LABEL_HOUSE:
renderPropertyEntranceLabel(pickups[i].getData("ag.label.name"), pickups[i].position, pickups[i].getData("ag.label.locked"), false, price);
break;
case AG_LABEL_JOB:
renderJobLabel(pickups[i].getData("ag.label.name"), pickups[i].position, pickups[i].getData("ag.label.jobType"));
break;
case AG_LABEL_EXIT:
renderPropertyExitLabel(pickups[i].position);
break;
}
//}
//}
if(getDistance(localPlayer.position, pickups[i].position) <= 7.5) {
let price = 0;
if(pickups[i].getData("ag.label.price") != null) {
price = pickups[i].getData("ag.label.price");
}
//}
switch(pickups[i].getData("ag.label.type")) {
case AG_LABEL_BUSINESS:
renderPropertyEntranceLabel(pickups[i].getData("ag.label.name"), pickups[i].position, pickups[i].getData("ag.label.locked"), true, price);
break;
case AG_LABEL_HOUSE:
renderPropertyEntranceLabel(pickups[i].getData("ag.label.name"), pickups[i].position, pickups[i].getData("ag.label.locked"), false, price);
break;
case AG_LABEL_JOB:
renderJobLabel(pickups[i].getData("ag.label.name"), pickups[i].position, pickups[i].getData("ag.label.jobType"));
break;
case AG_LABEL_EXIT:
renderPropertyExitLabel(pickups[i].position);
break;
}
}
}
}
}
});
}
// -------------------------------------------------------------------------

View File

@@ -40,24 +40,34 @@ let garbageCollectorInterval = null;
let parkedVehiclePosition = false;
let parkedVehicleHeading = false;
let renderHUD = false;
let renderLabels = false;
let renderLogo = false;
let renderSmallGameMessage = false;
let renderScoreboard = false;
let renderHotBar = false;
let renderHUD = true;
let renderLabels = true;
let renderLogo = true;
let renderSmallGameMessage = true;
let renderScoreboard = true;
let renderHotBar = true;
let renderItemActionDelay = true;
let logLevel = LOG_DEBUG;
let logLevel = LOG_ALL;
let weaponDamageEnabled = {};
let weaponDamageEvent = AG_WEAPON_DAMAGE_EVENT_NONE;
let weaponDamageEvent = {};
let forceWeapon = 0;
let itemActionDelayDuration = 0;
let itemActionDelayStart = 0;
let itemActionDelayEnabled = false;
let itemActionDelayPosition = toVector2(gta.width/2, gta.height-100);
let itemActionDelaySize = toVector2(100, 10);
// ---------------------------------------------------------------------------
addEvent("OnLocalPlayerEnterSphere", 1);
addEvent("OnLocalPlayerExitSphere", 1);
addEvent("OnLocalPlayerEnterVehicle", 1);
addEvent("OnLocalPlayerExitVehicle", 1);
addEvent("OnLocalPlayerEnteredVehicle", 1);
addEvent("OnLocalPlayerExitedVehicle", 1);
addEvent("OnLocalPlayerSwitchWeapon", 2);
// ---------------------------------------------------------------------------
@@ -171,6 +181,7 @@ function getClosestVehicle(pos) {
addNetworkHandler("ag.clearWeapons", function() {
logToConsole(LOG_DEBUG, `[Asshat.Main] Clearing weapons`);
localPlayer.clearWeapons();
forceWeapon = 0;
});
// ---------------------------------------------------------------------------
@@ -178,11 +189,12 @@ addNetworkHandler("ag.clearWeapons", function() {
addNetworkHandler("ag.giveWeapon", function(weaponId, ammo, active) {
logToConsole(LOG_DEBUG, `[Asshat.Main] Giving weapon ${weaponId} with ${ammo} ammo`);
localPlayer.giveWeapon(weaponId, ammo, active);
forceWeapon = weaponId;
});
// ---------------------------------------------------------------------------
addEventHandler("onElementStreamIn", function(event, element) {
addEventHandler("OnElementStreamIn", function(event, element) {
switch(element.type) {
case ELEMENT_VEHICLE:
syncVehicleProperties(element);
@@ -196,6 +208,10 @@ addEventHandler("onElementStreamIn", function(event, element) {
syncPlayerProperties(element);
break;
case ELEMENT_OBJECT:
syncObjectProperties(element);
break;
default:
break;
}
@@ -305,6 +321,8 @@ function initLocalPlayer(player) {
// ---------------------------------------------------------------------------
function processEvent(event, deltaTime) {
gta.clearMessages();
if(localPlayer != null) {
localPlayer.wantedLevel = 0;
@@ -361,29 +379,27 @@ function processEvent(event, deltaTime) {
if(localPlayer.vehicle) {
if(!inVehicle) {
triggerNetworkEvent("ag.onPlayerEnterVehicle");
inVehicle = localPlayer.vehicle;
inVehicleSeat = getLocalPlayerVehicleSeat();
if(inVehicleSeat == 0) {
inVehicle.engine = false;
if(!inVehicle.engine) {
parkedVehiclePosition = inVehicle.position;
parkedVehicleHeading = inVehicle.heading;
}
}
triggerEvent("OnLocalPlayerEnteredVehicle", inVehicle, inVehicleSeat);
}
} else {
if(inVehicle) {
triggerNetworkEvent("ag.onPlayerExitVehicle");
if(inVehicleSeat) {
parkedVehiclePosition = false;
parkedVehicleHeading = false;
}
triggerEvent("OnLocalPlayerExitedVehicle", inVehicle, inVehicleSeat);
inVehicle = false;
inVehicleSeat = false;
}
}
if(forceWeapon != 0) {
if(localPlayer.weapon != forceWeapon) {
localPlayer.weapon = forceWeapon;
}
} else {
if(localPlayer.weapon > 0) {
localPlayer.clearWeapons();
}
}
}
}
@@ -403,7 +419,6 @@ addEventHandler("OnDrawnHUD", function (event) {
if(smallGameMessageFont != "") {
smallGameMessageFont.render(smallGameMessageText, [0, gta.height-50], gta.width, 0.5, 0.0, smallGameMessageFont.size, smallGameMessageColour, true, true, false, true);
}
return false;
}
}
@@ -414,8 +429,31 @@ addEventHandler("OnDrawnHUD", function (event) {
}
if(renderScoreboard) {
if(localPlayer != nul && isKeyDown()) {
renderScoreboard();
if(isKeyDown(SDLK_TAB)) {
processScoreboardRendering();
}
}
if(renderLabels) {
processLabelRendering();
}
if(renderItemActionDelay) {
//logToConsole(LOG_DEBUG, `Item action delay render enabled`);
if(itemActionDelayEnabled) {
//logToConsole(LOG_DEBUG, `Item action delay enabled`);
let finishTime = itemActionDelayStart+itemActionDelayDuration;
if(sdl.ticks >= finishTime) {
logToConsole(LOG_DEBUG, `Item action delay finish time reached`);
itemActionDelayEnabled = false;
itemActionDelayDuration = 0;
itemActionDelayStart = 0;
triggerNetworkEvent("ag.itemActionDelayComplete");
} else {
let progressWidth = itemActionDelaySize.x-Math.ceil((finishTime-sdl.ticks)/100);
logToConsole(LOG_DEBUG, `Item action delay in progress - ${Math.ceil((finishTime-sdl.ticks)/100)} - ${progressWidth}/${itemActionDelaySize.x}`);
drawing.drawRectangle(null, [itemActionDelayPosition.x-(itemActionDelaySize.x/2), itemActionDelayPosition.y-(itemActionDelaySize.y/2)], [progressWidth, itemActionDelaySize.y], COLOUR_LIME, COLOUR_LIME, COLOUR_LIME, COLOUR_LIME);
}
}
}
});
@@ -631,7 +669,7 @@ function clearSelfOwnedPeds() {
// ---------------------------------------------------------------------------
addNetworkHandler("ag.set2DRendering", function(hudState, labelState, smallGameMessageState, scoreboardState, hotBarState) {
addNetworkHandler("ag.set2DRendering", function(hudState, labelState, smallGameMessageState, scoreboardState, hotBarState, itemActionDelayState) {
renderHUD = hudState;
setHUDEnabled(hudState);
@@ -639,6 +677,7 @@ addNetworkHandler("ag.set2DRendering", function(hudState, labelState, smallGameM
renderSmallGameMessage = smallGameMessageState;
renderScoreboard = scoreboardState;
renderHotBar = hotBarState;
renderItemActionDelay = itemActionDelayState;
});
// ---------------------------------------------------------------------------
@@ -659,4 +698,37 @@ addEventHandler("OnPedInflictDamage", function(event, damagedPed, damagerEntity,
//
// }
// if(damagerEntity.isType(ELEMENT_PLAYER))
});
// ---------------------------------------------------------------------------
addEventHandler("OnLocalPlayerExitedVehicle", function(event, vehicle, seat) {
triggerNetworkEvent("ag.onPlayerExitVehicle");
if(inVehicleSeat) {
parkedVehiclePosition = false;
parkedVehicleHeading = false;
}
});
// ---------------------------------------------------------------------------
addEventHandler("OnLocalPlayerEnteredVehicle", function(event, vehicle, seat) {
triggerNetworkEvent("ag.onPlayerEnterVehicle");
if(inVehicleSeat == 0) {
inVehicle.engine = false;
if(!inVehicle.engine) {
parkedVehiclePosition = inVehicle.position;
parkedVehicleHeading = inVehicle.heading;
}
}
});
// ---------------------------------------------------------------------------
addNetworkHandler("ag.showItemActionDelay", function(duration) {
itemActionDelayDuration = duration;
itemActionDelayStart = sdl.ticks;
itemActionDelayEnabled = true;
logToConsole(LOG_DEBUG, `Item action delay event called. Duration: ${itemActionDelayDuration}, Start: ${itemActionDelayStart}, Render: ${renderItemActionDelay}`);
});

View File

@@ -74,9 +74,9 @@ function drawNametag(x, y, health, armour, text, ping, alpha, distance, colour,
if(health > 0.0) {
let hx = x-width/2;
let hy = y-10/2;
let colourB = createColour(0, 0, 0, Math.floor(255.0*alpha)); // Background colour (black)
let colourB = toColour(0, 0, 0, Math.floor(255.0*alpha)); // Background colour (black)
drawing.drawRectangle(null, [hx, hy], [width, 8], colourB, colourB, colourB, colourB);
let colour = createColour(Math.floor(255.0*alpha), Math.floor(255.0-(health*255.0)), Math.floor(health*255.0), 0); // Health bar colour (varies, depending on health)
let colour = toColour(Math.floor(255.0*alpha), Math.floor(255.0-(health*255.0)), Math.floor(health*255.0), 0); // Health bar colour (varies, depending on health)
drawing.drawRectangle(null, [hx+2, hy+2], [(width-4)*health, 10-6], colour, colour, colour, colour);
}

View File

@@ -24,7 +24,7 @@ bindEventHandler("OnResourceReady", thisResource, function(event, resource) {
// -------------------------------------------------------------------------
function renderScoreboard() {
function processScoreboardRendering() {
if(scoreBoardListFont != null && scoreBoardTitleFont != null) {
let scoreboardStart = (game.height/2)-(Math.floor(getClients().length/2)*20);
let titleSize = scoreBoardTitleFont.measure("PLAYERS", game.width, 0.0, 1.0, 10, false, false);

View File

@@ -87,7 +87,9 @@ function syncVehicleProperties(vehicle) {
vehicle.setSuspensionHeight(suspensionHeight);
}
}
addNetworkHandler("ag.veh.sync", syncVehicleProperties);
addNetworkHandler("ag.veh.sync", function(event, vehicle) {
syncVehicleProperties(vehicle);
});
// ---------------------------------------------------------------------------
@@ -102,7 +104,9 @@ function syncCivilianProperties(civilian) {
civilian.position = tempPosition;
}
}
addNetworkHandler("ag.civ.sync", syncCivilianProperties);
addNetworkHandler("ag.civ.sync", function(event, civilian) {
syncCivilianProperties(civilian);
});
// ---------------------------------------------------------------------------
@@ -117,6 +121,25 @@ function syncPlayerProperties(player) {
player.position = tempPosition;
}
}
addNetworkHandler("ag.player.sync", syncPlayerProperties);
addNetworkHandler("ag.player.sync", function(event, player) {
syncPlayerProperties(player);
});
// ---------------------------------------------------------------------------
function syncObjectProperties(object) {
if(doesEntityDataExist(object, "ag.scale")) {
let scaleFactor = getEntityData(object, "ag.scale");
let tempMatrix = object.matrix;
tempMatrix.setScale(toVector3(scaleFactor.x, scaleFactor.y, scaleFactor.z));
let tempPosition = object.position;
object.matrix = tempMatrix;
tempPosition.z += scaleFactor.z;
object.position = tempPosition;
}
}
addNetworkHandler("ag.obj.sync", function(event, object) {
syncObjectProperties(object);
});
// ---------------------------------------------------------------------------