User:Furion: Difference between revisions
Jump to navigation
Jump to search
m anather correction |
m read the thread carefully... you will see that Phenomenon has wrote this piece of code |
||
| Line 15: | Line 15: | ||
</nowiki></pre> | </nowiki></pre> | ||
===Example=== | ===Example=== | ||
Modified code of [[User: | Modified code of [[User:Phenomenon|Phenomenon's]] HP Announcer that uses dist() function to calculate ditance between killer and victim | ||
<pre><nowiki> | <pre><nowiki> | ||
Revision as of 17:49, 12 February 2007
Hello There ;p
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
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 :>