zuzu Posted August 2, 2014 Posted August 2, 2014 (edited) 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 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 August 3, 2014 by Guest
Bonsai Posted August 3, 2014 Posted August 3, 2014 C'mon, this can't be so hard. Did you even include the script in the meta? Did you try some output of the coordinates?
zuzu Posted August 3, 2014 Author Posted August 3, 2014 So this should work, right? Yes I'm total newb, but I know that onPlayerWasted is server side, and ofc how I should create meta's
zuzu Posted August 3, 2014 Author Posted August 3, 2014 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.
Addlibs Posted August 3, 2014 Posted August 3, 2014 Are you sure you have started the resource? (Admin Panel >Resources or /start command)
cheez3d Posted August 3, 2014 Posted August 3, 2014 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);
zuzu Posted August 3, 2014 Author Posted August 3, 2014 @ 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.
zuzu Posted August 3, 2014 Author Posted August 3, 2014 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" ?
Et-win Posted August 3, 2014 Posted August 3, 2014 http://www.lua.org/manual/5.1/manual.ht ... math.floor Or: http://www.lua.org/manual/5.1/manual.html#pdf-math.ceil
Max+ Posted August 3, 2014 Posted August 3, 2014 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) ----------------------------------------
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now