[LiveMap] Server to Website

Started by KrOoB_, Jan 13, 2021, 12:29 PM

Previous topic - Next topic

KrOoB_

Vice City LiveMap

Website
Install XAMPP
You need a website so you have to install XAMPP

[After Installation]
Download this and extract to X:\xampp\htdocs\ (delete everything in htdocs before)

VC:MP
Download this plugin(json) and move it to plugins folder then add the plugin's name to server.cfg
After that place this code to your main.nut (you can add more features)
function onScriptLoad()
{
  NewTimer("LiveMap", 1000, 0);
}

function LiveMap()
{
   local i = 0, ii = 0, plrveh = null, plrspec = null;
    local players = [];
    if (GetPlayers() > 0) {
        while ((i < GetMaxPlayers()) && (ii < GetPlayers())) {
            local plr = FindPlayer(i++);
            if (!plr) continue;

            if (plr.Vehicle) plrveh = {
                model = plr.Vehicle.Model,
                color = [plr.Vehicle.Colour1, plr.Vehicle.Colour2],
                health = plr.Vehicle.Health
            }
            else plrveh = null;

            players.push({
                id = plr.ID,
                name = plr.Name,
                skin = plr.Skin,
                team = plr.Team,
                hp = plr.Health,
                ap = plr.Armour,
                score = plr.Score,
                cash = plr.Cash,
                ping = plr.Ping,
                weapon = plr.Weapon,
                vehicle = plrveh,
                pos = {
                    x = plr.Pos.x,
                    y = plr.Pos.y
                },
                spawned = plr.IsSpawned,
                spectating = plrspec
            });
            ii++;
        }
    }
    local export = {
        hostname = GetServerName(),
        weather = GetWeather(),
        hour = GetHour(),
        minute = GetMinute(),
        numplayers = GetPlayers(),
        maxplayers = GetMaxPlayers(),
        players = players
    }

    try {
        toJSONFile("C:/xampp/htdocs/data.json", export, JSON_C_TO_STRING_PRETTY);
    }
    catch (e) {
        print("Export failed: " + e);
    }

}

Start the server and open your website
CREDITS
huncrys (Kristóf Bach)
Gudio
Their github link