SA-MP Forums Archive
Problem with the system of life - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with the system of life (/showthread.php?tid=228031)



Problem with the system of life - [BR]Michael - 18.02.2011

Hello all!

I'm having a problem with health in my server, I did a system that uses a variable (pHealth) to store a player's health and calculate his damage, but when I set his health higher, the "Update" function sets it back to the previous value.
OBS: sometimes it works normally.

Код:
#define UPDATE_HEALTH                   4

new pUpdate[MAX_PLAYERS];
new Float:pHealth[MAX_PLAYERS];

stock SetPlayerSysHealth(playerid, Float:health)
{
    pHealth[playerid] = health;
    SetPlayerHealth(playerid, pHealth[playerid]);
    return pUpdate[playerid] |= UPDATE_HEALTH;
}

stock AddPlayerSysHealth(playerid, Float:health)
{
    pHealth[playerid] += health;
    SetPlayerHealth(playerid, pHealth[playerid]);
    return pUpdate[playerid] |= UPDATE_HEALTH;
}

stock GetPlayerSysHealth(playerid, &Float:health)
    health = pHealth[playerid];

public OnGameModeInit()
{
    SetTimer("Update", 50, true);
}

public Update()
{
    for(new n = 0; n < MAX_PLAYERS; n++)
    {
        if(IsPlayerConnected(n) && IsPlayerLogged(n))
        {
            if(pUpdate[n] & UPDATE_HEALTH)
            {
                if(pHealth[n] < 1.0)
                    pHealth[n] = 1.0;
                    
                if(pHealth[n] > 100.0)
                    pHealth[n] = 100.0;
                    
                SetPlayerHealth(n, pHealth[n]);
                pUpdate[n] &= ~UPDATE_HEALTH;
            }
            
            else
            {
            	new Float:H;

	        GetPlayerHealth(n, H);

     	       	if(H < pHealth[n])
        	{
            	    new Float:D;
                
                    D = pHealth[n] - H;
                    SetPlayerSysHealth(n, H);
                    OnPlayerDamage(n, D);
            	}
	    }
        }
    }
}
public OnPlayerDamage(playerid, Float:damage)
{
	if(Limp[playerid] != 0)
	    return 0;
	    
	new Float:health;
	
	GetPlayerHealth(playerid, health);
	
	if(health < 25.0)
	{
	    if(Limp[playerid] != 2)
	    {
	    	HideTextRed(playerid);
	    	Rob[playerid] = 0;
			Limp[playerid] = 2;
	   		ShowTextGray(playerid);
	   		SetPlayerDrunkLevel(playerid, 40000);
	   		SetTimerEx("Limping", 3000, false, "d", playerid);
		}
	}
	
	else
	{
	    ShowTextRed(playerid);

		if(damage < 10.0)
		    SetTimerEx("HideTextRed", 400, false, "d", playerid);

		else
		{
		    Rob[playerid] = 0;
		    
		    if(!IsPlayerInAnyVehicle(playerid))
		    {
		        Limp[playerid] = 1;
				SetTimerEx("StopAnimation", 200, false, "d", playerid);
		    	SetTimerEx("DamageAnimation", 500, false, "df", playerid, damage);
			}
			
			else
			    SetTimerEx("HideTextRed", 3000, false, "d", playerid);
		}
	}
	
	return 1;
}

public DamageAnimation(playerid, Float:damage)
{
	new anim;

	if(damage >= 22.0)
	{
	    new getupid;
	    
	    anim = random(4);
	    
		if(anim == 0)
		{
		    getupid = 1;
			ApplyAnimation(playerid, "PED", "KO_shot_face", 4.1, 0, 1, 1, 1, -1, 1);
		}
		
		else if(anim == 1)
		{
		    getupid = 0;
		    ApplyAnimation(playerid, "PED", "KO_shot_stom", 4.1, 0, 1, 1, 1, -1, 1);
		}
		
		else if(anim == 2)
		{
		    getupid = 0;
		    ApplyAnimation(playerid, "KNIFE", "KILL_Knife_Ped_Die", 4.1, 0, 1, 1, 1, -1, 1);
		}
		
		else
		{
		    getupid = 1;
		    ApplyAnimation(playerid, "KNIFE", "knife_hit_3", 4.1, 0, 1, 1, 1, -1, 1);
		}
		
		SetTimerEx("DamageAnimationGetUp", 7000, false, "dd", playerid, getupid);
	}
	
	else
	{
	    anim = random(3);
	    
	    if(anim == 0)
			ApplyAnimation(playerid, "MD_END", "END_SC1_PLY", 4.1, 0, 1, 1, 1, -1, 1);
			
		else if(anim == 1)
			ApplyAnimation(playerid, "MD_END", "END_SC1_RYD", 4.1, 0, 1, 1, 1, -1, 1);
			
		else
			ApplyAnimation(playerid, "MD_END", "END_SC1_SWE", 4.1, 0, 1, 1, 1, -1, 1);
        	
        SetTimerEx("DamageEnd", 5000, false, "d", playerid);
	}
	
	SetPlayerDrunkLevel(playerid, 50000);
}

public DamageAnimationGetUp(playerid, getupid)
{
	if(getupid == 0)
		ApplyAnimation(playerid, "PED", "getup_front", 4.1, 0, 1, 1, 1, -1, 1);

	else
	    ApplyAnimation(playerid, "PED", "getup", 4.1, 0, 1, 1, 1, -1, 1);
	    
	SetTimerEx("DamageEnd", 1500, false, "d", playerid);
}

public DamageEnd(playerid)
{
    Limp[playerid] = 0;
    SetPlayerDrunkLevel(playerid, pDrunk[playerid]);
    HideTextRed(playerid);
    ClearAnimations(playerid);
}

public Limping(playerid)
{
	if(Limp[playerid] == 2)
	{
		new Float:health;
		
		GetPlayerHealth(playerid, health);
	
		if(health < 25.0)
		{
		    if(!IsPlayerInAnyVehicle(playerid))
		    	ApplyAnimation(playerid, "RYDER", "RYD_Die_PT1", 4.1, 1, 1, 1, 1, 1, 1);
		    	
		    SetTimerEx("Limping", 5000, false, "d", playerid);
		    return;
		}
	}
	    
	SetPlayerDrunkLevel(playerid, pDrunk[playerid]);
	Limp[playerid] = 0;
	HideTextGray(playerid);
}



Re: Problem with the system of life - [BR]Michael - 18.02.2011

Help :/


Re: Problem with the system of life - [BR]Michael - 19.02.2011

help :S


Re: Problem with the system of life - Hal - 19.02.2011

I think you are going to have to set the variable to the health that you setting the player. Because if you aren't its just working as an AC of some sort


Re: Problem with the system of life - [BR]Michael - 19.02.2011

I give up, I think nobody knows about repairing ... As would be if I used the native functions of the SA: MP?


Re: Problem with the system of life - maramizo - 19.02.2011

Put the full script please? As in where you defined health?


Re: Problem with the system of life - [BR]Michael - 19.02.2011

#define UPDATE_HEALTH 4


Re: Problem with the system of life - maramizo - 19.02.2011

What is Limp?
And why would you want to set it higher?
You can just do some sort of command that does NEGATIVE damage, to reverse the action.


AW: Problem with the system of life - Nero_3D - 19.02.2011

If you ask me I cant see where the problem is
But i question me what this part is about ?

pawn Код:
if(pUpdate[n] & UPDATE_HEALTH)
            {
                if(pHealth[n] < 1.0)
                    pHealth[n] = 1.0;
                   
                if(pHealth[n] > 100.0)
                    pHealth[n] = 100.0;
                   
                SetPlayerHealth(n, pHealth[n]);
                pUpdate[n] &= ~UPDATE_HEALTH;
            }
This would have the same effect if it would be in SetPlayerSysHealth