User:Furion
From WolfWiki
Hello There ;p
[edit]
dist() Function
For distance between two object with vec3 position values
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 / 52.4934) end
More optimized version:
function dist(a ,b) local dx = math.abs(b[1] - a[1]) local dy = math.abs(b[2] - a[2]) local dz = math.abs(b[3] - a[3]) local d = math.sqrt((dx ^ 2) + (dy ^ 2) + (dz ^ 2)) return math.floor(d / 52.4934) end
[edit]
Example
Modified code of Phenomenon's HP Announcer that uses dist() function to calculate ditance between killer and victim
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\n^7He had ^o" .. killerhp.. "^7 HP\"\n")
et.trap_SendServerCommand(victimnum, msg)
end
end
Put this and dist() function code to one lua file, it should work ^^
More stuff coming soon :>
