0 Members and 5 Guests are viewing this topic.
var Dist: Single;i : double;x : double; procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);begin if Weapon = 'Combat Knife' then begin Dist := Distance(GetPlayerStat(Killer,'x'),GetPlayerStat(Killer,'y'),GetPlayerStat(Victim,'x'),GetPlayerStat(Victim,'y')); i:=Dist; x:=(i/17.62); if x>30 then begin SayToPlayer(1,GetPlayerStat(1,'name')+' has just achieved a '+inttostr(round(x))+' m knife kill!'); end; end; end;
Dist := Distance(GetPlayerStat(Killer,'x'),GetPlayerStat(Killer,'y'),GetPlayerStat(Victim,'x'),GetPlayerStat(Victim,'y'));SayToPlayer(1,inttostr(round(Dist)));
sqrt((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1))
procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);var dist: single;begin if Weapon = 'Combat Knife' then begin dist := Distance(GetPlayerStat(Killer, 'X'), GetPlayerStat(Killer, 'Y'), GetPlayerStat(Victim, 'X'), GetPlayerStat(Victim, 'Y')) / 14; if dist > 30 then WriteConsole(0, IDToName(Killer) + ' has just achieved a ' + floattostr(RoundTo(dist, 2)) + 'm knife kill!', $FFFFFF); end;end;
To calculate the distance beetween two points you use the following formulate (that's actually what Distance() does):Code: [Select]sqrt((X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1))One meter in soldat is 14 (it's a little bit more actually from what i've heard)So you would probably have to use this code:Code: [Select]procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);var dist: single;begin if Weapon = 'Combat Knife' then begin dist := Distance(GetPlayerStat(Killer, 'X'), GetPlayerStat(Killer, 'Y'), GetPlayerStat(Victim, 'X'), GetPlayerStat(Victim, 'Y')) / 14; if dist > 30 then WriteConsole(0, IDToName(Killer) + ' has just achieved a ' + floattostr(RoundTo(dist, 2)) + 'm knife kill!', $FFFFFF); end;end;Not testet, but should work.
1. Use GetPlayeXY instead of GetPlayerStat('x'/'y'...2. In most cases I've seen, soldat meter was assumed 15px. Nothing is random when it comes to calculations, maybe the difference comes from how the flight distance is calculated? Maybe it measures length of curve, not just dist point1 point2? Can't tell, never tested. In case it's the first option, you will have to use something based on ballistic functions.
It just can't be done "perfectly". There's no way for you to get velocity of the thrown knife, which means that you can't calculate it's path/distance it traveled. Also packetloss is your enemy in here. OnWeaponChange likes not to be triggered.