SA-MP Forums Archive
Injuried System - 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)
+--- Thread: Injuried System (/showthread.php?tid=606983)



Injuried System - McGuiness - 12.05.2016

Hey guys,

So I have been working on my death system, but I don't get why it won't work properly, as when I have one of my testers kills me to test, but what should happen is when someone kills someone, they should spawn back at their place as an injuried person, but oddly enough what it does is spawns you at the points of 0, 0, 0 (X, Y, Z), and doesn't do anything, its strange for me.

Code:
Код:
public OnPlayerSpawn(playerid)
{
	if(IsDead[playerid] == 1)
	{
		SetPlayerPos(playerid, DeathPos[playerid][dX], DeathPos[playerid][dY], DeathPos[playerid][dZ]);
		SetPlayerHealth(playerid, 50);
		IsDead[playerid] = 2;
		ApplyAnimation(playerid,"PARACHUTE","FALL_skyDive_DIE", 4.0, 0, 0, 0, 1, 0);
		SetTimerEx("AutoDeath", AUTODEATH_SECONDS * 1000, false, "i", playerid);
		SendClientMessage(playerid, COLOUR_TWPINK, "------------------ Health Advice -----------------");
	    SendClientMessage(playerid, COLOUR_TWPINK, "You have been critically injured!");
	    SendClientMessage(playerid, COLOUR_TWPINK, "You can type either '/requestmedic' or '/acceptdeath' to continue.");
	    SendClientMessage(playerid, COLOUR_TWPINK, "--------------------------------------------------------");

		new string[400];
		new holder[400];

		if(sInfo[playerid][Misc] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d bruises on their body.\n", sInfo[playerid][Misc]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Head] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the head.\n", sInfo[playerid][Head]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Chest] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the chest.\n", sInfo[playerid][Chest]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Crotch] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the crotch.\n", sInfo[playerid][Crotch]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][LArm] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the left arm.\n", sInfo[playerid][LArm]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][RArm] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the right arm.\n", sInfo[playerid][RArm]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][LLeg] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the left leg.\n", sInfo[playerid][LLeg]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][RLeg] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the right leg.\n", sInfo[playerid][RLeg]);
			strcat(holder, string, sizeof(holder));
		}
		deathlabel[playerid] = Create3DTextLabel(holder, -1, DeathPos[playerid][dX], DeathPos[playerid][dY], DeathPos[playerid][dZ], 10.0, 0, 0);
	}
	else if(IsDead[playerid] == 2)
	{
	    AutoDeath(playerid);
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	new Float:pX, Float:pY, Float:pZ;
	GetPlayerPos(playerid, pX, pY, pZ);
	
	PlayerInfo[killerid][pKills]++;
	PlayerInfo[playerid][pDeaths]++;
	DeathPos[playerid][dX] = pX;
	DeathPos[playerid][dY] = pY;
	DeathPos[playerid][dZ] = pZ;
	IsDead[playerid] = 1;
	return 1;
}



Re: Injuried System - MBilal - 12.05.2016

Try this.
Код:
new Float:DeathPos[MAX_PLAYERS][3]; 
public OnPlayerSpawn(playerid)
{
	if(IsDead[playerid] == 1)
	{
		SetPlayerPos(playerid, DeathPos[playerid][0], DeathPos[playerid][1], DeathPos[playerid][2]);
		SetPlayerHealth(playerid, 50);
		IsDead[playerid] = 2;
		ApplyAnimation(playerid,"PARACHUTE","FALL_skyDive_DIE", 4.0, 0, 0, 0, 1, 0);
		SetTimerEx("AutoDeath", AUTODEATH_SECONDS * 1000, false, "i", playerid);
		SendClientMessage(playerid, COLOUR_TWPINK, "------------------ Health Advice -----------------");
	    SendClientMessage(playerid, COLOUR_TWPINK, "You have been critically injured!");
	    SendClientMessage(playerid, COLOUR_TWPINK, "You can type either '/requestmedic' or '/acceptdeath' to continue.");
	    SendClientMessage(playerid, COLOUR_TWPINK, "--------------------------------------------------------");

		new string[400];
		new holder[400];

		if(sInfo[playerid][Misc] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d bruises on their body.\n", sInfo[playerid][Misc]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Head] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the head.\n", sInfo[playerid][Head]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Chest] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the chest.\n", sInfo[playerid][Chest]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Crotch] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the crotch.\n", sInfo[playerid][Crotch]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][LArm] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the left arm.\n", sInfo[playerid][LArm]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][RArm] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the right arm.\n", sInfo[playerid][RArm]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][LLeg] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the left leg.\n", sInfo[playerid][LLeg]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][RLeg] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the right leg.\n", sInfo[playerid][RLeg]);
			strcat(holder, string, sizeof(holder));
		}
		deathlabel[playerid] = Create3DTextLabel(holder, -1, DeathPos[playerid][dX], DeathPos[playerid][dY], DeathPos[playerid][dZ], 10.0, 0, 0);
	}
	else if(IsDead[playerid] == 2)
	{
	    AutoDeath(playerid);
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{ 
	GetPlayerPos(playerid,DeathPos[playerid][0], DeathPos[playerid][1], DeathPos[playerid][2]); 
	PlayerInfo[killerid][pKills]++;
	PlayerInfo[playerid][pDeaths]++; 
	IsDead[playerid] = 1;
	return 1;
}



Re: Injuried System - McGuiness - 13.05.2016

Tried it but it doesn't work.. Really don't know what is going on here


Re: Injuried System - Dayrion - 13.05.2016

Quote:
Originally Posted by McGuiness
Посмотреть сообщение
Tried it but it doesn't work.. Really don't know what is going on here
It don't teleport the player to last position?

Put a print
PHP код:
printf("x : %f - y : %f - z: %f"DeathPos[playerid][0], DeathPos[playerid][1],DeathPos[playerid][2]); 
under
PHP код:
SetPlayerPos(playeridDeathPos[playerid][0], DeathPos[playerid][1], DeathPos[playerid][2]); 
and here (OnPlayerDeath) :
PHP код:
GetPlayerPos(playeridDeathPos[playerid][0], DeathPos[playerid][1], DeathPos[playerid][2]); 
And let's see what happens!


Re: Injuried System - McGuiness - 13.05.2016

Works now! Seems one code in the onplayer death was giving an error 4 when being used so once removed it works perfectly now, as it seems the info was saving it into the variables.

Thank you all for the help!


Re: Injuried System - MBilal - 13.05.2016

The code is perfect but this is not right way to use them better way to use them is to use it on OnPlayerTakeDamage

check if Player Health < 10

Код:
if(Health < 10)
{
// here your code after 
SetPlayerHealth(playerid, 50);
		IsDead[playerid] = 2;
		ApplyAnimation(playerid,"PARACHUTE","FALL_skyDive_DIE", 4.0, 0, 0, 0, 1, 0);
		SetTimerEx("AutoDeath", AUTODEATH_SECONDS * 1000, false, "i", playerid);
		SendClientMessage(playerid, COLOUR_TWPINK, "------------------ Health Advice -----------------");
	    SendClientMessage(playerid, COLOUR_TWPINK, "You have been critically injured!");
	    SendClientMessage(playerid, COLOUR_TWPINK, "You can type either '/requestmedic' or '/acceptdeath' to continue.");
	    SendClientMessage(playerid, COLOUR_TWPINK, "--------------------------------------------------------");

		new string[400];
		new holder[400];

		if(sInfo[playerid][Misc] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d bruises on their body.\n", sInfo[playerid][Misc]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Head] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the head.\n", sInfo[playerid][Head]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Chest] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the chest.\n", sInfo[playerid][Chest]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][Crotch] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the crotch.\n", sInfo[playerid][Crotch]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][LArm] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the left arm.\n", sInfo[playerid][LArm]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][RArm] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the right arm.\n", sInfo[playerid][RArm]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][LLeg] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the left leg.\n", sInfo[playerid][LLeg]);
			strcat(holder, string, sizeof(holder));
		}
		if(sInfo[playerid][RLeg] > 0)
		{
			format(string, sizeof(string), ""COL_RED"%d gun shot wound(s) in the right leg.\n", sInfo[playerid][RLeg]);
			strcat(holder, string, sizeof(holder));
		}
		deathlabel[playerid] = Create3DTextLabel(holder, -1, DeathPos[playerid][dX], DeathPos[playerid][dY], DeathPos[playerid][dZ], 10.0, 0, 0);
	}
	else if(IsDead[playerid] == 2)
	{
	    AutoDeath(playerid);
	}
}
I think using it Under OnPlayerTakeDamage is better way because player will not die and you can apply anim or things which you want to apply on it.


Re: Injuried System - IzadorO - 13.05.2016

Better way's to check if a player's health's below the weaponid's damage.