Quote:
Originally Posted by Calgon
You would have to create some code which detects whether a player is actually using their knife at the time (best bet would be to check if they have a knife under OnPlayerKeyStateChange, for KEY_FIRE), then check how close they are to a player, if they're close enough, then you could get that players ID and subtract 50 from their HP.
I've created some code for you, but I haven't tested it. (FYI I started scripting this after I posted, added about 5-10 minutes later).
pawn Код:
// PRESSED(keys) - From the SA-MP wiki #define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(PRESSED(KEY_FIRE)) { // Check if they pressed KEY_FIRE if(GetPlayerWeapon(playerid) == 4) { // Check if they have a knife new Float: _curHealth, // Variable for storing the looping players health to subtract from. Float: _knifeDamagePos[3]; // Create our variable to store our current players position.
GetPlayerPos(playerid, _knifeDamagePos[0], _knifeDamagePos[1], _knifeDamagePos[2]); foreach(Player, _i) { // Perform a loop to see who is in range if(IsPlayerInRangeOfPoint(_i, 1, _knifeDamagePos[0], _knifeDamagePos[1], _knifeDamagePos[2])) { // This code isn't exactly 100% accurate, others close may be damaged by the knife, I've added a return though so it only gets 1 player. GetPlayerHealth(_i, _curHealth); // Get the players current health. SetPlayerHealth(_i, _curHealth-50); // Subtract 50. return 1; } } } } return 1; }
Grab foreach and include it for this, or replace the foreach line with:
pawn Код:
for(new _i = 0; _i < MAX_PLAYERS; _i++)
Enjoy.
|
Not bad; however, with the GetPlayerAnimationIndex function, this could be done in a better way.
That code could make players that got knifed get away with only losing 1 hp, and players that didn't lose 50 hp.
My suggestion to a proper solution would be to check nearby players, when a knifing slash animation is played out, for these animations (from my
animation_names.inc):
pawn Код:
KNIFE_KNIFE_HIT_1, // 755
KNIFE_KNIFE_HIT_2, // 756
KNIFE_KNIFE_HIT_3, // 757
I can write a FS for this when I get home.