progress bar help
#1

Hello, I've been working on a vehicle damage progress bar and I don't seem to be getting it working, I could use a little bit of help. thanks, code:
pawn Код:
#include <a_samp>
#include <progress>

new Bar:Vhealthbar[MAX_PLAYERS];
forward OnVehicleUpdate();

public OnFilterScriptInit()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        Vhealthbar[playerid] = CreateProgressBar(500.00, 122.00, 106.50, 5.50, 16777215, 100.0);
    }
    return 1;
}

public OnFilterScriptExit()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        DestroyProgressBar(Vhealthbar[playerid]);
    }
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    ShowProgressBarForPlayer(playerid, Vhealthbar[playerid]);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    HideProgressBarForPlayer(playerid, Vhealthbar[playerid]);
    return 1;
}

public OnVehicleUpdate()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        new Float:health, veh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(veh, health);
        SetProgressBarValue(Vhealthbar[playerid], GetVehicleHealth(veh, health));
        UpdateProgressBar(Vhealthbar[playerid], playerid);
        return 1;
    }
    return 1;
}
It is showing the bar, but it doesn't progress nor does it show the progression, it's just a blank bar, thanks if you're able to help me out here!
Reply
#2

You have got function OnVehicleUpdate, but you never call it. You have to set timer

Код:
public OnFilterScriptInit()
{
	return SetTimer("OnVehicleUpdate", 1000, 1);
}

forward OnVehicleUpdate();
public OnVehicleUpdate()
{
	new Float:health;

	for(new playerid; playerid != MAX_PLAYERS; playerid++)
	{
		if(!IsPlayerConnected(playerid) || !IsPlayerInAnyVehicle(playerid)) continue;

		GetVehicleHealth(GetPlayerVehicleID(playerid), health);
		SetProgressBarValue(Vhealthbar[playerid], health);
		UpdateProgressBar(Vhealthbar[playerid], playerid);
	}
}
Not tested, should work. Also i recommend show progress bar in callback OnPlayerStateChange, not in OnPlayerEnterVehicle - this callback is called when a player begins to enter a vehicle.
Reply
#3

Okay I will test it when I have time, thanks for the help and thanks for the little tip.
Reply
#4

Hello again, I've just tested it and change what you said I still have the problem where the bar does nothing, but OnPlayerStateChange seems to be buggy with it as well, like when you fall off it doesn't hide it...

pawn Код:
#include <a_samp>
#include <progress>

new Bar:Vhealthbar[MAX_PLAYERS];
forward OnVehicleUpdate();

public OnFilterScriptInit()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        Vhealthbar[playerid] = CreateProgressBar(500.00, 122.00, 106.50, 5.50, 16777215, 100.0);
    }
    return 1;
}

public OnFilterScriptExit()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        DestroyProgressBar(Vhealthbar[playerid]);
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    SetTimer("OnVehicleUpdate", 1000, 1);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnVehicleUpdate()
{
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
        new Float:health, veh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(veh, health);
        SetProgressBarValue(Vhealthbar[playerid], GetVehicleHealth(veh, health));
        UpdateProgressBar(Vhealthbar[playerid], playerid);
        return 1;
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
    ShowProgressBarForPlayer(playerid, Vhealthbar[playerid]);
    }
    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
    HideProgressBarForPlayer(playerid, Vhealthbar[playerid]);
    }
    return 1;
}
Reply
#5

You didn't change this code. In my code function SetTimer is in OnFilterScriptInit, in your code is in OnPlayerEnterVehicle, why? Also code inside OnVehicleUpdate isn't changed. I gave you repaired function, you don't use it. I can't understand why.

Here is example script for updating vehicle health in progress bar -> https://sampforum.blast.hk/showthread.php?tid=113443
Reply
#6

Okay, now the bar shows, but it doesn't decrease when I lose damage... and this thread you shown me is the one I was learning from, but that's when it didn't work...
Reply
#7

pawn Код:
SetProgressBarValue(Vhealthbar[playerid], health));
Edit: Also add a GetPlayerState-check in the loop on your update-function to check if the player is actually driving a vehicle. if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
Reply
#8

Show actually code of OnVehicleUpdate - my code should work, but i didn't test it.
Reply
#9

pawn Код:
forward OnVehicleUpdate();
public OnVehicleUpdate()
{
    new Float:health;

    for(new playerid; playerid != MAX_PLAYERS; playerid++)
    {
        if(!IsPlayerConnected(playerid) || !IsPlayerInAnyVehicle(playerid)) continue;

        GetVehicleHealth(GetPlayerVehicleID(playerid), health);
        SetProgressBarValue(Vhealthbar[playerid], health);
        UpdateProgressBar(Vhealthbar[playerid], playerid);
    }
}
Thanks again for trying to help me out here!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)