26.10.2010, 05:21
(
Последний раз редактировалось Calgon; 26.10.2010 в 05:41.
Причина: Hungarian notation
)
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).
Grab foreach and include it for this, or replace the foreach line with:
Enjoy.
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;
}
pawn Код:
for(new _i = 0; _i < MAX_PLAYERS; _i++)