Progressbar za Vehicle Health

Započeo onett, Novembar 20, 2021, 23:53:58 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 2 gostiju pregledaju ovu temu.

Moze li neko da mi pomogne kako bi mogao da napravim ovakav progressbar s vehicle health-om, kako ga napraviti da radi

https://imgur.com/a/LswOTsR

Najprostiji progress bar koji možeš uzet iz example-a (sto se koda tice), a za poziciju imaš filterskriptu, kada uzmeš poziciju jednostavno vrijednost staviš procentualno od healtha vozila, ali budući da je max health vozila 1000,a progress bara 100, vrijednost možeš staviti kroz prostu formulu hpvozila/10,s tim da vrijednost nikad ne ide preko 100 ili ispod 0 jer neko prakticira stavljati ručno hp na vozila preko 1000 imitirajući blindirano vozilo ili sta vec

Citat: daniop poslato Novembar 21, 2021, 00:10:14 PRE PODNE
Najprostiji progress bar koji možeš uzet iz example-a (sto se koda tice), a za poziciju imaš filterskriptu, kada uzmeš poziciju jednostavno vrijednost staviš procentualno od healtha vozila, ali budući da je max health vozila 1000,a progress bara 100, vrijednost možeš staviti kroz prostu formulu hpvozila/10,s tim da vrijednost nikad ne ide preko 100 ili ispod 0 jer neko prakticira stavljati ručno hp na vozila preko 1000 imitirajući blindirano vozilo ili sta vec
Da ali kako napraviti da to update-a i ostalo


Evo sklepao sam ti nesto, testiraj, trebalo bi da radi :>

[pawn]
#include <progress2>

/**
  * Variables
*/
new
    vehicleBarTimer[MAX_PLAYERS],
    PlayerBar: vehicleBar[MAX_PLAYERS] = {PlayerBar: INVALID_PLAYER_BAR_ID,...};

/**
  * Function
*/
stock Bar_CreateVehicleBar(const playerid, bool: status = true)
{
    if (!status)
    {
        DestroyPlayerProgressBar(playerid, PlayerBar: vehicleBar[playerid]);
        vehicleBar[playerid] = PlayerBar: INVALID_PLAYER_BAR_ID;

        KillTimer(vehicleBarTimer[playerid]);
        return 1;
    }

    vehicleBar[playerid] = CreatePlayerProgressBar(playerid, 469.00, 392.00, 146.00, 1.70, -263908865, 100.00, 0);

    SetPlayerProgressBarValue(playerid, PlayerBar: vehicleBar[playerid], Float: 100.00);
    ShowPlayerProgressBar(playerid, PlayerBar: vehicleBar[playerid]);

    return 1;
}

/**
  * Callbacks
*/
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER)
    {
        /**
         * Customize interval
         */
        vehicleBarTimer[playerid] = SetTimerEx("OnVehicleDamaged", 1500, 1, "d", playerid);
    }

    else
    {
        Bar_CreateVehicleBar(playerid, false);
    }

    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    /**
     * Test
     */
    if (newkeys & KEY_YES)
    {
        new Float: x, Float: y, Float: z;
        GetPlayerPos(playerid, x, y, z);
        CreateVehicle(411, x, y, z, 0.0, 0, 0, 0);
    }

    if (newkeys & KEY_NO)
    {
        Bar_CreateVehicleBar(playerid);
    }

    return 1;
}

forward OnVehicleDamaged(const playerid);
public OnVehicleDamaged(const playerid)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
        new
            Float: floatbar = GetPlayerProgressBarValue(playerid, PlayerBar: vehicleBar[playerid]),
            Float: floatveh;

        GetVehicleHealth(GetPlayerVehicleID(playerid), floatveh);
        SetPlayerProgressBarValue(playerid, PlayerBar: vehicleBar[playerid], (floatveh / 10));
    }

    return 1;
}[/pawn]

Citat: Emmett White poslato Novembar 21, 2021, 08:26:36 PRE PODNE
Evo sklepao sam ti nesto, testiraj, trebalo bi da radi :>

[pawn]
#include <progress2>

/**
  * Variables
*/
new
    vehicleBarTimer[MAX_PLAYERS],
    PlayerBar: vehicleBar[MAX_PLAYERS] = {PlayerBar: INVALID_PLAYER_BAR_ID,...};

/**
  * Function
*/
stock Bar_CreateVehicleBar(const playerid, bool: status = true)
{
    if (!status)
    {
        DestroyPlayerProgressBar(playerid, PlayerBar: vehicleBar[playerid]);
        vehicleBar[playerid] = PlayerBar: INVALID_PLAYER_BAR_ID;

        KillTimer(vehicleBarTimer[playerid]);
        return 1;
    }

    vehicleBar[playerid] = CreatePlayerProgressBar(playerid, 469.00, 392.00, 146.00, 1.70, -263908865, 100.00, 0);

    SetPlayerProgressBarValue(playerid, PlayerBar: vehicleBar[playerid], Float: 100.00);
    ShowPlayerProgressBar(playerid, PlayerBar: vehicleBar[playerid]);

    return 1;
}

/**
  * Callbacks
*/
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (newstate == PLAYER_STATE_DRIVER)
    {
        /**
         * Customize interval
         */
        vehicleBarTimer[playerid] = SetTimerEx("OnVehicleDamaged", 1500, 1, "d", playerid);
    }

    else
    {
        Bar_CreateVehicleBar(playerid, false);
    }

    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    /**
     * Test
     */
    if (newkeys & KEY_YES)
    {
        new Float: x, Float: y, Float: z;
        GetPlayerPos(playerid, x, y, z);
        CreateVehicle(411, x, y, z, 0.0, 0, 0, 0);
    }

    if (newkeys & KEY_NO)
    {
        Bar_CreateVehicleBar(playerid);
    }

    return 1;
}

forward OnVehicleDamaged(const playerid);
public OnVehicleDamaged(const playerid)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
        new
            Float: floatbar = GetPlayerProgressBarValue(playerid, PlayerBar: vehicleBar[playerid]),
            Float: floatveh;

        GetVehicleHealth(GetPlayerVehicleID(playerid), floatveh);
        SetPlayerProgressBarValue(playerid, PlayerBar: vehicleBar[playerid], (floatveh / 10));
    }

    return 1;
}[/pawn]
iq 198

[Filterscript] Simple Treasure Hunt
[Filterscript] Sistem pecanja
[Filterscript] Meditacija
[Filterscript] Molitva
[Include] Alarm
[Include] Posao Taxi