Hello There ^^
I wanted to publish this in ETPro forums but no body activating my forum acc o.O Accounting to member list last activated ETPro forum acc is been created in 31 December 2006… i don’t want to wait months for acc… so i publish this here ;p
I coded function that calculates distance between objects positions in vec3 value. Here it is:
function dist(a ,b)
ax,ay,az = a[1],a[2],a[3]
bx,by,bz = b[1],b[2],b[3]
dx = math.abs(bx - ax)
dy = math.abs(by - ay)
dz = math.abs(bz - az)
d = math.sqrt((dx ^ 2) + (dy ^ 2) + (dz ^ 2))
return math.floor(d) / 39.37
end
You just put vec3 values (for example r.currentOrigin from players entity field) to a and b argument and it will return distance between them.
If you know some geometry math you probably notice that is simple algorithm for diagonal of cuboid crated from difference between absolute (negative numbers turn to positive) values of x, y ,z in objects a and b. Simple isn’t ;p
Now how you can use that ;> heres example modified killers hp announcer
:
function et_Obituary(victimnum, killernum, meansofdeath)
local victimteam = tonumber(et.gentity_get(victim, "sess.sessionTeam"))
local killerteam = tonumber(et.gentity_get(killer, "sess.sessionTeam"))
local posk = et.gentity_get(victim,"r.currentOrigin")
local posv = et.gentity_get(killer,"r.currentOrigin")
if victimteam ~= killerteam and killernum < 1022 then
local killername = string.gsub(et.gentity_get(killernum, "pers.netname"), "%^$", "^^ ")
local killerhp = et.gentity_get(killernum, "health")
killdist = dist(posk,posv)
msg = string.format("cp \"" .. killername .. "^1 killed you from ^o" .. killdist .. " ^1m
^7He had ^o" .. killerhp.. "^7 HP\"
")
et.trap_SendServerCommand(victimnum, msg)
end
end
Now not only killer’s HP will be shown but also from what distance he killed you. You just put this and dist function code in one lua file and it should work ^^
You can also create invert code that shows to killer how far his victim was. You can many ideas how to use that you just need position vec3 values of specific object.
Theres 2 problems i know ;p
- killers hp/dist announcer, that i shown has a bug ;p It may return wrong
values when killer uses grenade or mortar and specially the mines or other weapons that killer may move before victim will be killed ;p but you can fix by if’ing it for specified meansofdeath ^^ - Calibration of value unit ;p
return math.floor(d) / 100
See this divider? Without it dist() function will return value in quake3 position units ;p i calibrate it to distance that for my eye looks like 1 meter in game (100 q3units = 1 meter that will be shown). If you don’t like it, you can calibrate it for your own by placing other number then 100 ;p
EDIT: SCDS_reyalP said that game units are truly inches so divider should be 39.37. I apply it to function
So here you have ^^ if you code something interesting with it post it here ;p Enjoy!
P.S. If you got contact with bani or other ETPro forum admin tell him that many people waiting for acc activation there ;p and no body activate them. I got many ideas for lua scripts and i want to share them with server admins community and ETPro Forum is good place for it.
