Jump to content

Kill distance and getDistanceBetweenPoints3D


zuzu

Recommended Posts

There are many kill/dead message scripts, but i couldnt find any that will output distance which from player was killed.

Ive seen it on few servers, so i decided to make my own but somehow it doesent work..

Could someone take a look on it, and help me please :cry:

  
addEventHandler ( "onPlayerWasted" , root,  
function ( _, killer ) 
    x,y,z = getElementPosition ( source ) 
    x1,y1,z1 = getElementPosition ( killer ) 
    distance = getDistanceBetweenPoints3D ( x, y, z, x1, y1, z1 ) 
    outputChatBox ( getPlayerName(source).." was killed by "..getPlayerName ( killer ), root, 255, 255, 255 ) 
    outputChatBox ( "Distance: "..distance, root, 255, 255, 255 ) 
end) 
  

Edited by Guest
Link to comment

I heve used this code for meta and my script called kd_s.lua

<meta> 
    <info author="kev" type="script" name="KillDistance" version="1.0"/> 
    <script src="kd_s.lua" type="server" /> 
</meta> 
  

So everything should be fine I think.

Link to comment
  
addEventHandler("onPlayerWasted",root,function(_,killer) 
    if killer and getElementType(killer) == "player" then 
        local VictimX,VictimY,VictimZ = getElementPosition(source); 
        local KillerX,KillerY,KillerZ = getElementPosition(killer); 
        local Distance = getDistanceBetweenPoints3D(VictimX,VictimY,VictimZ,KillerX,KillerY,KillerZ); 
        outputChatBox(getPlayerName(source).." was killed by "..getPlayerName(killer).." from a distance of "..tostring(Distance).."!",root,255,255,255); 
    end; 
end); 
  

Link to comment

@ MrTasty

Not that newbie:p

@ Cheez3D

Thanks for your exmaple! Anyway its still wont work but I found where the problem is.

My server is running DayZ gamemode, and when I terminate it then distance appeared and your script as same as mine works perfect.

So my next problem is how to adapt it for DayZ...

I wonder why all killmessages and other stuff works there, while distance dont.

Link to comment
  
addEventHandler("onPlayerWasted",root,function(_,killer) 
    if killer and getElementType(killer) == "player" then 
        local VictimX,VictimY,VictimZ = getElementPosition(source); 
        local KillerX,KillerY,KillerZ = getElementPosition(killer); 
        local Distance = getDistanceBetweenPoints3D(VictimX,VictimY,VictimZ,KillerX,KillerY,KillerZ); 
        outputChatBox(getPlayerName(source).." was killed by "..getPlayerName(killer).." from a distance of "..tostring(Distance).."!",root,255,255,255); 
    end; 
end); 
  

Ok I manage how make it work, thanks for help everyone.

One more little question, how can I output short distance value like "was killed from 200m" except of "was killed from 200.23472423108m" ?

Link to comment

Distance = string.format ( "%.f" , Distance ) 

----------------------------------

 

distance=pos2-pos1 --use getDistanceBetweenPoints if 2/3D needed 
currentDistance=pos2-yourPos --use getDistanceBetweenPoints if 2/3D needed 
precents=math.min(math.max(math.abs(currentDistance/distance*100),0),100) 

----------------------------------------

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...