Fix server-side API errors: use toColour, Vec3, spawnPlayer, giveWeapon

- Replace color arrays with toColour() integer format for message/messageClient
- Replace position arrays with Vec3 objects for player/vehicle positions
- Use pos.x, pos.y, pos.z instead of pos[0], pos[1], pos[2]
- Fix client.spawn() to client.spawnPlayer(Vec3, heading, skin)
- Fix client.giveWeapon() to client.player.giveWeapon()

Fixed files: freeroam, admin, chat, world, teleport, vehicles, modmenu
This commit is contained in:
Claude
2026-01-12 15:16:21 +00:00
parent fee097c7db
commit 686f80d49c
7 changed files with 381 additions and 324 deletions

View File

@@ -3,6 +3,16 @@
// Handles player spawning, basic commands, and player management
// ============================================================================
// Define colors using toColour
const COLOUR_WHITE = toColour(255, 255, 255, 255);
const COLOUR_RED = toColour(255, 100, 100, 255);
const COLOUR_GREEN = toColour(100, 255, 100, 255);
const COLOUR_BLUE = toColour(100, 200, 255, 255);
const COLOUR_YELLOW = toColour(255, 255, 100, 255);
const COLOUR_ORANGE = toColour(255, 200, 100, 255);
const COLOUR_GREY = toColour(200, 200, 200, 255);
const COLOUR_PINK = toColour(255, 150, 200, 255);
// Spawn points around Liberty City (GTA IV)
const spawnPoints = [
{ x: -252.0, y: 947.0, z: 15.0, name: "Star Junction" },
@@ -59,11 +69,11 @@ addEventHandler("OnPlayerJoined", function(event, client) {
};
// Welcome message
messageClient("[SERVER] Welcome to Liberty City Freeroam, " + client.name + "!", client, [255, 200, 100, 255]);
messageClient("[SERVER] Type /help for available commands", client, [200, 200, 200, 255]);
messageClient("[SERVER] Welcome to Liberty City Freeroam, " + client.name + "!", client, COLOUR_ORANGE);
messageClient("[SERVER] Type /help for available commands", client, COLOUR_GREY);
// Spawn the player
spawnPlayer(client);
spawnPlayerAtRandom(client);
});
// When a player quits
@@ -71,7 +81,7 @@ addEventHandler("OnPlayerQuit", function(event, client, reason) {
console.log("[Freeroam] Player quit: " + client.name + " - Reason: " + reason);
// Broadcast quit message
message("[SERVER] " + client.name + " has left the server", [255, 150, 100, 255]);
message("[SERVER] " + client.name + " has left the server", COLOUR_PINK);
// Clean up player data
delete playerData[client.index];
@@ -91,14 +101,14 @@ addEventHandler("OnPedWasted", function(event, ped, killer, weapon) {
let killerClient = getClientFromPed(killer);
if (killerClient && playerData[killerClient.index]) {
playerData[killerClient.index].kills++;
message("[KILL] " + killerClient.name + " killed " + client.name, [255, 100, 100, 255]);
message("[KILL] " + killerClient.name + " killed " + client.name, COLOUR_RED);
}
}
// Respawn after delay
setTimeout(function() {
if (client && client.player) {
spawnPlayer(client);
if (client) {
spawnPlayerAtRandom(client);
}
}, 3000);
}
@@ -115,15 +125,15 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
case "spawn":
case "respawn":
spawnPlayer(client);
messageClient("[SERVER] You have been respawned!", client, [100, 255, 100, 255]);
spawnPlayerAtRandom(client);
messageClient("[SERVER] You have been respawned!", client, COLOUR_GREEN);
break;
case "kill":
case "suicide":
if (client.player) {
client.player.health = 0;
messageClient("[SERVER] You killed yourself!", client, [255, 100, 100, 255]);
messageClient("[SERVER] You killed yourself!", client, COLOUR_RED);
}
break;
@@ -131,7 +141,7 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
case "position":
if (client.player) {
let pos = client.player.position;
messageClient("[POS] X: " + pos[0].toFixed(2) + " Y: " + pos[1].toFixed(2) + " Z: " + pos[2].toFixed(2), client, [200, 200, 255, 255]);
messageClient("[POS] X: " + pos.x.toFixed(2) + " Y: " + pos.y.toFixed(2) + " Z: " + pos.z.toFixed(2), client, COLOUR_BLUE);
}
break;
@@ -147,7 +157,7 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
case "heal":
if (client.player) {
client.player.health = 100;
messageClient("[SERVER] You have been healed!", client, [100, 255, 100, 255]);
messageClient("[SERVER] You have been healed!", client, COLOUR_GREEN);
}
break;
@@ -155,7 +165,7 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
case "armor":
if (client.player) {
client.player.armour = 100;
messageClient("[SERVER] You have been given armour!", client, [100, 200, 255, 255]);
messageClient("[SERVER] You have been given armour!", client, COLOUR_BLUE);
}
break;
@@ -165,28 +175,28 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
if (!isNaN(skinId)) {
if (client.player) {
client.player.modelIndex = skinId;
messageClient("[SERVER] Skin changed to: " + skinId, client, [200, 200, 255, 255]);
messageClient("[SERVER] Skin changed to: " + skinId, client, COLOUR_BLUE);
}
}
} else {
messageClient("[USAGE] /skin <skin_id>", client, [255, 200, 100, 255]);
messageClient("[USAGE] /skin <skin_id>", client, COLOUR_ORANGE);
}
break;
case "weapons":
case "giveweapons":
giveWeapons(client);
messageClient("[SERVER] You have been given weapons!", client, [255, 200, 100, 255]);
messageClient("[SERVER] You have been given weapons!", client, COLOUR_ORANGE);
break;
case "flip":
if (client.player && client.player.vehicle) {
let veh = client.player.vehicle;
let rot = veh.rotation;
veh.rotation = [0, 0, rot[2]];
messageClient("[SERVER] Vehicle flipped!", client, [100, 255, 100, 255]);
veh.rotation = new Vec3(0, 0, rot.z);
messageClient("[SERVER] Vehicle flipped!", client, COLOUR_GREEN);
} else {
messageClient("[SERVER] You need to be in a vehicle!", client, [255, 100, 100, 255]);
messageClient("[SERVER] You need to be in a vehicle!", client, COLOUR_RED);
}
break;
@@ -194,16 +204,16 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
case "repair":
if (client.player && client.player.vehicle) {
client.player.vehicle.health = 1000;
messageClient("[SERVER] Vehicle repaired!", client, [100, 255, 100, 255]);
messageClient("[SERVER] Vehicle repaired!", client, COLOUR_GREEN);
} else {
messageClient("[SERVER] You need to be in a vehicle!", client, [255, 100, 100, 255]);
messageClient("[SERVER] You need to be in a vehicle!", client, COLOUR_RED);
}
break;
case "eject":
if (client.player && client.player.vehicle) {
client.player.removeFromVehicle();
messageClient("[SERVER] Ejected from vehicle!", client, [200, 200, 255, 255]);
messageClient("[SERVER] Ejected from vehicle!", client, COLOUR_BLUE);
}
break;
@@ -217,15 +227,19 @@ addEventHandler("OnPlayerCommand", function(event, client, command, params) {
// FUNCTIONS
// ============================================================================
function spawnPlayer(client) {
function spawnPlayerAtRandom(client) {
// Select random spawn point
let spawn = spawnPoints[Math.floor(Math.random() * spawnPoints.length)];
// Select random skin
let skin = playerSkins[Math.floor(Math.random() * playerSkins.length)];
// Spawn the player
client.spawn([spawn.x, spawn.y, spawn.z], 0, skin);
// Create spawn position vector
let spawnPos = new Vec3(spawn.x, spawn.y, spawn.z);
// Spawn the player using the correct function
client.despawnPlayer();
client.spawnPlayer(spawnPos, 0.0, skin);
// Give basic weapons after short delay
setTimeout(function() {
@@ -245,76 +259,74 @@ function giveStarterWeapons(client) {
if (!client || !client.player) return;
// Give basic starter weapons (GTA IV weapon IDs)
// Pistol
client.giveWeapon(5, 100); // Pistol with 100 ammo
// SMG
client.giveWeapon(11, 200); // Micro SMG with 200 ammo
client.player.giveWeapon(5, 100); // Pistol with 100 ammo
client.player.giveWeapon(11, 200); // Micro SMG with 200 ammo
}
function giveWeapons(client) {
if (!client || !client.player) return;
// GTA IV Weapon IDs
client.giveWeapon(1, 1); // Baseball Bat
client.giveWeapon(2, 1); // Knife
client.giveWeapon(5, 500); // Pistol
client.giveWeapon(6, 500); // Desert Eagle
client.giveWeapon(9, 200); // Shotgun
client.giveWeapon(10, 200); // Combat Shotgun
client.giveWeapon(11, 500); // Micro SMG
client.giveWeapon(12, 500); // SMG
client.giveWeapon(14, 500); // Assault Rifle
client.giveWeapon(15, 500); // Carbine Rifle
client.giveWeapon(16, 100); // Sniper Rifle
client.giveWeapon(18, 20); // RPG
client.giveWeapon(19, 20); // Grenades
client.giveWeapon(20, 20); // Molotov
client.player.giveWeapon(1, 1); // Baseball Bat
client.player.giveWeapon(2, 1); // Knife
client.player.giveWeapon(5, 500); // Pistol
client.player.giveWeapon(6, 500); // Desert Eagle
client.player.giveWeapon(9, 200); // Shotgun
client.player.giveWeapon(10, 200); // Combat Shotgun
client.player.giveWeapon(11, 500); // Micro SMG
client.player.giveWeapon(12, 500); // SMG
client.player.giveWeapon(14, 500); // Assault Rifle
client.player.giveWeapon(15, 500); // Carbine Rifle
client.player.giveWeapon(16, 100); // Sniper Rifle
client.player.giveWeapon(18, 20); // RPG
client.player.giveWeapon(19, 20); // Grenades
client.player.giveWeapon(20, 20); // Molotov
}
function showHelp(client) {
messageClient("=== AVAILABLE COMMANDS ===", client, [255, 200, 100, 255]);
messageClient("/spawn - Respawn at a random location", client, [200, 200, 200, 255]);
messageClient("/kill - Kill yourself", client, [200, 200, 200, 255]);
messageClient("/pos - Show your current position", client, [200, 200, 200, 255]);
messageClient("/stats - Show your statistics", client, [200, 200, 200, 255]);
messageClient("/players - Show online players", client, [200, 200, 200, 255]);
messageClient("/heal - Restore your health", client, [200, 200, 200, 255]);
messageClient("/armour - Give yourself armour", client, [200, 200, 200, 255]);
messageClient("/weapons - Get all weapons", client, [200, 200, 200, 255]);
messageClient("/skin <id> - Change your skin", client, [200, 200, 200, 255]);
messageClient("/flip - Flip your vehicle", client, [200, 200, 200, 255]);
messageClient("/fix - Repair your vehicle", client, [200, 200, 200, 255]);
messageClient("/eject - Exit vehicle", client, [200, 200, 200, 255]);
messageClient("=== VEHICLE COMMANDS ===", client, [255, 200, 100, 255]);
messageClient("/v <name> - Spawn a vehicle", client, [200, 200, 200, 255]);
messageClient("/dv - Delete your vehicle", client, [200, 200, 200, 255]);
messageClient("=== TELEPORT COMMANDS ===", client, [255, 200, 100, 255]);
messageClient("/tp <location> - Teleport to location", client, [200, 200, 200, 255]);
messageClient("/tplist - List teleport locations", client, [200, 200, 200, 255]);
messageClient("=== WORLD COMMANDS ===", client, [255, 200, 100, 255]);
messageClient("/weather <id> - Change weather", client, [200, 200, 200, 255]);
messageClient("/time <hour> - Change time", client, [200, 200, 200, 255]);
messageClient("=== AVAILABLE COMMANDS ===", client, COLOUR_ORANGE);
messageClient("/spawn - Respawn at a random location", client, COLOUR_GREY);
messageClient("/kill - Kill yourself", client, COLOUR_GREY);
messageClient("/pos - Show your current position", client, COLOUR_GREY);
messageClient("/stats - Show your statistics", client, COLOUR_GREY);
messageClient("/players - Show online players", client, COLOUR_GREY);
messageClient("/heal - Restore your health", client, COLOUR_GREY);
messageClient("/armour - Give yourself armour", client, COLOUR_GREY);
messageClient("/weapons - Get all weapons", client, COLOUR_GREY);
messageClient("/skin <id> - Change your skin", client, COLOUR_GREY);
messageClient("/flip - Flip your vehicle", client, COLOUR_GREY);
messageClient("/fix - Repair your vehicle", client, COLOUR_GREY);
messageClient("/eject - Exit vehicle", client, COLOUR_GREY);
messageClient("=== VEHICLE COMMANDS ===", client, COLOUR_ORANGE);
messageClient("/v <name> - Spawn a vehicle", client, COLOUR_GREY);
messageClient("/dv - Delete your vehicle", client, COLOUR_GREY);
messageClient("=== TELEPORT COMMANDS ===", client, COLOUR_ORANGE);
messageClient("/tp <location> - Teleport to location", client, COLOUR_GREY);
messageClient("/tplist - List teleport locations", client, COLOUR_GREY);
messageClient("=== WORLD COMMANDS ===", client, COLOUR_ORANGE);
messageClient("/weather <id> - Change weather", client, COLOUR_GREY);
messageClient("/time <hour> - Change time", client, COLOUR_GREY);
}
function showStats(client) {
let data = playerData[client.index];
if (data) {
messageClient("=== YOUR STATISTICS ===", client, [255, 200, 100, 255]);
messageClient("Kills: " + data.kills, client, [100, 255, 100, 255]);
messageClient("Deaths: " + data.deaths, client, [255, 100, 100, 255]);
messageClient("=== YOUR STATISTICS ===", client, COLOUR_ORANGE);
messageClient("Kills: " + data.kills, client, COLOUR_GREEN);
messageClient("Deaths: " + data.deaths, client, COLOUR_RED);
let kd = data.deaths > 0 ? (data.kills / data.deaths).toFixed(2) : data.kills.toFixed(2);
messageClient("K/D Ratio: " + kd, client, [200, 200, 255, 255]);
messageClient("K/D Ratio: " + kd, client, COLOUR_BLUE);
}
}
function showOnlinePlayers(client) {
let clients = getClients();
messageClient("=== ONLINE PLAYERS (" + clients.length + ") ===", client, [255, 200, 100, 255]);
messageClient("=== ONLINE PLAYERS (" + clients.length + ") ===", client, COLOUR_ORANGE);
for (let i = 0; i < clients.length; i++) {
let c = clients[i];
let data = playerData[c.index] || { kills: 0, deaths: 0 };
messageClient(c.name + " - K: " + data.kills + " D: " + data.deaths, client, [200, 200, 200, 255]);
messageClient(c.name + " - K: " + data.kills + " D: " + data.deaths, client, COLOUR_GREY);
}
}