Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds
Watch MODSonair

Members Online

»
0 Active | 239 Guests
Online:

LATEST FORUM THREADS

»
New BF2 Mod
BF2 General

Tutorials

»
OFP2
ratings:
Awful Rating
Poor Rating
Average Rating
Good Rating
Excellent Rating
Determining farthest kill
Versions: You must be logged in to view history.

Triangulates the distance between killer & victim at time of death

I wrote this because I was creating a sniper
style game and I wanted to reward a player by
recording the longest range as well as praising
them for distant kills. My personal best is 1218.5m with the Barrett

--[[
=================================================
***Display the Range of Your Kills***
Ron "Ronbocop" Carroll
=================================================
I wrote this because I was creating a sniper
style game and I wanted to reward a player by
recording the longest range as well as praising
them for distant kills.

IMPORTANT: If you wound a target that bleeds out,
when it dies it only then triangulates the
relative positions of the killer and the victim.
So if the killer moves away or closer, the kill
distance will then increase or decrease.

Wish List - Appreciate any thoughts
-----------------------------------
I found it difficult to actually find the player
name, ie, "Ronbocop" which I would then use to
record both the furthest kills as well as the
individual's best. I ended up resorting to 
extracting the killer's category, so may get
confusing if you have two snipers for example.
The other problem is the naming convention of
the units which is not consistent. Frustrating.
I ended up stripping the first 6 letters off
the categories names to have something more
readable. Text = string.sub(Text,#Chars)

Apologies for not explaining in more detail the
remarks for the codes. Feel free to query me on
it if you don't quite understand why I have done
something a particular way. Hopefully I will
remember, good luck :D

PS
I appreciate the fact that we have Codemasters to
thank for having a game like this to play and
mod for our friends, but sometimes it is a real
mind .... bender to code something and then be
stymied by the inevitable "if only I could..."
Anyway hope they implement as many of everybody's
wishlists in the next mod.
=================================================
]]

function onMissionStart()
--Global Variables
FarthestKill = 0
end

--Get Range of Kills
function onDeath(victim, killer)
-- OFP:displaySystemMessage(victim .. " is victim, " .. killer .. " is killer")
VictimCat = OFP:getUnitCategory(victim)
KillerCat = OFP:getUnitCategory(killer)
-- OFP:displaySystemMessage(VictimCat .. " is victim category, " .. KillerCat .. " is killer category")

--Actual Distance between Protagonists
local VictimX, VictimY, VictimZ = OFP:getPosition(victim)
local KillerX, KillerY, KillerZ = OFP:getPosition(killer)
XDist = KillerX - VictimX
YDist = KillerY - VictimY
ZDist = KillerZ - VictimZ
HypDistXY = math.sqrt((XDist*XDist)+(YDist*YDist))
HypDist = math.sqrt((HypDistXY*HypDistXY)+(ZDist*ZDist))
--Strip Unit_ prefix off Category
VictimCat = string.sub(VictimCat,6)
KillerCat = string.sub(KillerCat,6)

--Round Distance to decimetres
HypDist = (math.floor(HypDist*10))/10

--Display Kills if over 150m
if HypDist >= 150 then
if HypDist >= 600 then
OFP:displaySystemMessage("Phenomenal Shot!!!")
elseif HypDist >= 400 then
OFP:displaySystemMessage("Great Shot!!")
else
OFP:displaySystemMessage("Shot!")
end
OFP:displaySystemMessage(VictimCat .. " was killed by " .. KillerCat .. " at range " .. HypDist .. "m")
if HypDist > FarthestKill then
OFP:displaySystemMessage("Well done, achieved longest distance kill")
FarthestKill = HypDist
end
end
end

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»