SA-MP Forums Archive
Bulletproof shield. - 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: Bulletproof shield. (/showthread.php?tid=567697)



Bulletproof shield. - kepa333 - 15.03.2015

Hello there, i am trying to make bulletproof shield, and im stuck at it.. ( So far its done for 1 player only, i will ad loops later )

Код:
	if(strcmp(cmd, "/dshild", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			if (IsPlayerInRangeOfPoint(playerid, 6, 257.1108,78.0250,1003.6406))
			{
			    if(!IsANg(playerid))
			    {
                    SendClientMessage(playerid,COLOR_GREY," Only army deltaforce can use this equipment.");
					return 1;
				}
				shild = SetPlayerAttachedObject(playerid, 8, 18637, 4, 0.3, 0, 0, 0, 170, 270, 1, 1, 1);

	    		return 1;
			}
		}
	}
Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
	if(hittype == 4)
	{
		if(hitid == shild)
		{
			return 0;
		}
	}
	return 1;
}
Code dosent work as it should... i'v been trying with AttachObjectToPlayer aswell, no result after 2 hours.


Re: Bulletproof shield. - Evocator - 15.03.2015

That doesnt work as such...
SetPlayerAttachedObject returns 0 on success and 1 on fail, you need to assign a boolean;

Код:
new 
	bool:Shielded[MAX_PLAYERS]
;



public OnPlayerConnect(playerid)
{
	Shielded[playerid] = false;
	return 1;
}


if(strcmp(cmd, "/dshild", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
		if (IsPlayerInRangeOfPoint(playerid, 6, 257.1108,78.0250,1003.6406))
		{
		    if(!IsANg(playerid))
		    {
                SendClientMessage(playerid,COLOR_GREY," Only army deltaforce can use this equipment.");
				return 1;
			}
			SetPlayerAttachedObject(playerid, 8, 18637, 4, 0.3, 0, 0, 0, 170, 270, 1, 1, 1);
			Shielded[playerid] = true;
    		return 1;
		}
	}
}

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
	if(hittype == BULLET_HIT_TYPE_PLAYER)
	{
		if(Shielded[hitid]) return 0; //desync the bullet if the player has a shield.
	}
	return 1;
}



Re: Bulletproof shield. - kepa333 - 15.03.2015

It is not like i wanted it to be... you gave me script which will make you god if you are shielded... i only need dmg to not be done when player hit shield. if he get shot anywhere else it would take his HP down.


Re: Bulletproof shield. - Smileys - 15.03.2015

Quote:
Originally Posted by kepa333
Посмотреть сообщение
It is not like i wanted it to be... you gave me script which will make you god if you are shielded... i only need dmg to not be done when player hit shield. if he get shot anywhere else it would take his HP down.
On what bodypart is the shield attached to?


Re: Bulletproof shield. - Sew_Sumi - 15.03.2015

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == BULLET_HIT_TYPE_PLAYER)
{
if(Shielded[hitid]) return 0; //desync the bullet if the player has a shield.
}
return 1;
}[/code]
^^ That needs revising. It's not doing what you think it does at all.

This doesn't even check if that the bullet hit the shield.

Quote:
Originally Posted by Smileys
Посмотреть сообщение
On what bodypart is the shield attached to?
Doesn't matter which bodypart it's connected to, it's about the bullets hitting the shield.


Re: Bulletproof shield. - Crayder - 15.03.2015

It's not detectible, but it can be scripted (but not perfect). You should check to see if the shot came from someone in front of the player, if so and the shot was on the torso (with shield attached) do not damage.


Re: Bulletproof shield. - Smileys - 15.03.2015

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
^^ That needs revising. It's not doing what you think it does at all.

This doesn't even check if that the bullet hit the shield.



Doesn't matter which bodypart it's connected to, it's about the bullets hitting the shield.
You can't really detect if someone hit the shield, you CAN detect which bodypart they hit, if the shield is attached to the body and someone hit him on the body, it does no damage, otherwise it does.

This is about the closest you can get lol.


Re: Bulletproof shield. - Abagail - 15.03.2015

You actually can by using the provided X, Y, Z offsets and comparing them to the object.

Example:
pawn Код:
// in command...
ShieldObject[playerid] = CreateObject(18637, 0, 0, 0, 0, 0, 0);
AttachObjectToPlayer(objectid, .....
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float: fX, Float: fY, Float: fZ)
{
     if(hittype == BULLET_HIT_TYPE_PLAYER && Shield[hitid] == true)
     {
          new Float: pos[4];
          GetObjectOffset(ShieldObject[playerid], playerid, EXTRA_TYPE_PLAYER, pos[0], pos[1], pos[2], pos[3]);
          if(GetDistance(x, y, z, pos[0], pos[1], pos[2], pos[3] < 5.0)
          {
               return 0;
          }
     }
     return 1;
}

stock GetDistance( Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2 )
{
    return floatround( floatsqroot( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) + ( ( z1 - z2 ) * ( z1 - z2 ) ) ) ) );
}
However unless you hook(or use an extensive function) to store the object's offsets using Attached Player Objects you have to use global objects.


Re: Bulletproof shield. - kepa333 - 16.03.2015

Well seems like i can't get your include working (GetObjectOffset)... I was tryharding for an hour... inculding stuff, editing it but could not get it work.