Got a problem here.
#1

Well I basically got this code, damage one. Anyway, when I set myself to gTeam 2(vampire), I don't get any increased damage, I recently changed

if(IsPlayerInRangeOfPoint(playerid, 1.7, pos[0], pos[1], pos[2]))

To what you can see below in the code, before all got damage when I set a random player including myself to the race Vampire, increasing even humans damage and when setting the player back to human everyone got normal damage. I then changed to the one below. And that one doesn't even affect it at all, not even doing anything at all basically, so it basically just don't work even though it compiles fine. Any help would be awesome, seriously, if you got any idea of what could be the problem, please tell me! Thanks.


Код:
public OnPlayerUpdate(playerid)
{
	pOldHP[playerid] = pCurrentHP[playerid];
	GetPlayerHealth(playerid, pCurrentHP[playerid]);
	new Float:HPDifference = pOldHP[playerid] - pCurrentHP[playerid];
	new anim = GetPlayerAnimationIndex(playerid);
	new animname[16];
	GetAnimationName(anim, animname, 16, animname, 16);
	
	if(strfind(animname, "FIGHT", true) != -1)
	{
		Fighter[playerid] = true;
		Victim[playerid] = false;
	}
	else if(strfind(animname, "HIT", true) != -1)
	{
		Victim[playerid] = true;
		Fighter[playerid] = false;
		for(new i; i != MAX_PLAYERS; i++)
		{
			new fighter = -1;
			new Float:pos[3];
			GetPlayerPos(i, pos[0], pos[1], pos[2]);
			if(IsPlayerInRangeOfPoint(playerid, 1.7, pos[0], pos[1], pos[2]) && Fighter[fighter] == true)
			{
				fighter = i;
				if(HPDifference > 0.0)
				{
					if(gTeam[fighter] == 2) ///VAMPIRE SHIT! GOES HERE!
					{
						//increase damage on 20%
						HPDifference = floatmul(HPDifference, VAMPIRE_DAMAGE_RATIO); //floatmul - multiply a number with a floating point (0.00)
						//to reduce x on y% : x * (1 - (y / 100))
						SetPlayerHealth(playerid, pOldHP[playerid] - HPDifference);
					}
					Victim[playerid] = false;
					Fighter[playerid] = false;
					Victim[fighter] = false;
					Fighter[fighter] = false;
				}
			}
		}
	}
	return 1;
Reply
#2

Quote:
Originally Posted by Andregood
Посмотреть сообщение
Код:
public OnPlayerUpdate(playerid)
{
		for(new i; i != MAX_PLAYERS; i++)
		{
Don't do this if you don't want to lag like shit. OnPlayerUpdate is called about 32 times per second, per player. So even with 10 players connected, you will execute the code in the loop 32 x 10 x 500 = 160000 times per second.

Also: debug, debug, debug! I can't stretch this enough. Add prints and see if certain pieces are being called (or not).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)