OnPlayerTakeDamage? -
N0FeaR - 03.09.2012
Now i wounder something, when i have this and someone stand close to you and you hit with the gun they lose 50 hp, anyway how i can fix that?
Then i mean not shoot, i mean hitting someone with the gun
pawn Код:
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
new Float:HP;
GetPlayerHealth(playerid, HP);
if(weaponid == 24) SetPlayerHealth(playerid, HP-50); //DesertEagle
return 1;
}
Re: OnPlayerTakeDamage? -
Cjgogo - 03.09.2012
I see what you mean there,well,that's not really possible,because HE'S HOLDING IN HIS hands the specific weapon :P,however you can check in OnPlayerKeyStateChange if he's pressed the RMB and LMB at the same time meaning he's punching WITH the specfific gun,or any gun and cancel the action.
Re: OnPlayerTakeDamage? -
Psymetrix - 03.09.2012
You lose less health from a punch than being shot. By checking how much health has been lost you will be able to tell whether it was a punch or not.
Re: OnPlayerTakeDamage? -
Cjgogo - 03.09.2012
Quote:
Originally Posted by Psymetrix
You lose less health from a punch than being shot. By checking how much health has been lost you will be able to tell whether it was a punch or not.
|
He means that the player is punched,but the puncher is HOLDING the weapon in his hands(you know that you can punch with a weapon,right?),and as his codes depicts a health lost when the player is damaged by the weapon,the damage taker actually looses health,even if the damager shoots him OR punches him(while he's holding the respective weapon).
Re : OnPlayerTakeDamage? -
ricardo178 - 03.09.2012
Basicaly, OnPlayerTakeDamage, check if the attacker has any weapon in hands.
Re: OnPlayerTakeDamage? -
N0FeaR - 03.09.2012
Is there anyway so is only take 50hp when i shoot?
Re: OnPlayerTakeDamage? -
Psymetrix - 03.09.2012
I mean something like;
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
new Float:HP;
GetPlayerHealth(playerid, HP);
// Only continue if the health lost is enough to be a weapon and not a punch
if (amount > 5.0) // 5.0 - Roughly the amount of a punch. May not be correct
{
if(weaponid == 24) // Desert Eagle
{
SetPlayerHealth(playerid, HP-50);
}
}
return 1;
}
Re: OnPlayerTakeDamage? -
leonardo1434 - 03.09.2012
This may work.
pawn Код:
new bool:works[MAX_PLAYERS],_i = 0,_e,Float:_D[3];
public OnPlayerUpdate(playerid)
{
if(GetPlayerWeapon(playerid) == 24) // checking if has a deagle
{
_e = GetMaxPlayers();
GetPlayerPos(playerid,_D[0],_D[1],_D[2]);//player pos.
for(; _i < _e; ++_i) // loop.
{
if(IsPlayerInRangeOfPoint(_i,1.0,_D[0],_D[1],_D[2])) // checking if there's players near to him.
{
works[playerid] = true; // setting the bool.
}
}
}
works[playerid] = false; // not near.
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
new Float:HP;
GetPlayerHealth(playerid, HP);
if(works[playerid]) // if true, it means, he has the wep in his hand's, so it doesn't matter if he punch's or not.
{
SetPlayerHealth(playerid, HP-50); // setting his health -50 while is being punched or not.
}
return 1;
}
Re: OnPlayerTakeDamage? -
Psymetrix - 03.09.2012
Quote:
Originally Posted by leonardo1434
|
All that code will give the same result as the original code..
Edit: I think I misread the OP but why not do the checks under OnPlayerTakeDamage?
Re: OnPlayerTakeDamage? -
leonardo1434 - 03.09.2012
the code i've made is based at what he said... he says that wanted to do one thing and posted a piece of code that wasn't working "properly", most probably he already his own stuff. Then i supposed his code won't work as he wanted.
i don't sleep for over 2 days, Anyways, i thought in a short version and better.
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
new Float:HP;
GetPlayerHealth(playerid, HP);
if(GetPlayerWeapon(issuerid) == 24) SetPlayerHealth(playerid, HP-50);
return 1;
}