Author Topic: Throwing knife message  (Read 1713 times)

0 Members and 1 Guest are viewing this topic.

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Throwing knife message
« on: February 06, 2012, 12:57:03 pm »
Hi, I want to have a throwing knife message appear in the, if the killer does an over (lets just say) 30 m throw, which will sound like  "Herp just did a 436 m knife throw!".

This is my code:
 
Code: [Select]
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;

The problem is, the distance of the kill and the distance this script is receiving are almost never the same... How do I get a precision measure of the distance between the 2 players, transformed into game meters?
« Last Edit: February 06, 2012, 04:06:56 pm by Mexer »
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Re: Throwing knife message
« Reply #1 on: February 06, 2012, 04:25:21 pm »
Can someone explain to me how this Distance function works?

Because I just did some kills and, with the help of
Code: [Select]
Dist := Distance(GetPlayerStat(Killer,'x'),GetPlayerStat(Killer,'y'),GetPlayerStat(Victim,'x'),GetPlayerStat(Victim,'y'));
SayToPlayer(1,inttostr(round(Dist)));
I recorded the following knife kills:

4.92 m  - 82 (this is the value the Dist function was generating)
4.93 m  - 85 
4.94 m  - 86
4.95 m  - 92

Why is the step from one kill to another so random? There should've been a fixed step from each meter to another for the values , like 2 or 3 , not that randomness.
I need a much more precise system for measuring distance so I can transform it correctly to meters... can you help me?
« Last Edit: February 06, 2012, 04:27:08 pm by Mexer »
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Throwing knife message
« Reply #2 on: February 06, 2012, 04:54:43 pm »
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.

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Throwing knife message
« Reply #3 on: February 06, 2012, 05:04:05 pm »
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.
« Last Edit: February 06, 2012, 05:08:58 pm by tk »

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Re: Throwing knife message
« Reply #4 on: February 06, 2012, 05:23:51 pm »
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.

You're not rounding it so the values are showing as 6.32000000000 or similar. I also recall having almost the same results with the old script.

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.

Uh, so the game calculates the exact trajectory's distance of the knife, while the Distance function shows the exact distance between the two players?
« Last Edit: February 06, 2012, 05:25:26 pm by Mexer »
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Throwing knife message
« Reply #5 on: February 06, 2012, 05:48:11 pm »
You have a logical flaw in here. OnPlayerKill is called, as name suggests, when player gets killed. But that, especially on long distances, happens much later than knife throw. So in result, shooter's position is retrieved just in the moment when knife hits the victim, which is too late as he most likely moved from the throw position long time ago.
And also yes, the airdistance calculated by soldat client is a length of ballistic curve, not a flat line.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Re: Throwing knife message
« Reply #6 on: February 06, 2012, 05:51:02 pm »
A little offtopic: what soldat measures and gives back as distance is counted from where i threw the knife or where i am standing when knife kills? answered while posting

@up: that's exactly what i'm worried about here. However, you could save the position and id of thrown knife, but that would make the script pretty heavy (not comparable to the effect). At least the way i see it in my head
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Throwing knife message
« Reply #7 on: February 06, 2012, 06:14:33 pm »
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.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Re: Throwing knife message
« Reply #8 on: February 07, 2012, 04:33:26 am »
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.

Why isn't soldat just giving that distance value you see at the bottom of your screen. WHY?
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!