User:Furion: Difference between revisions
Jump to navigation
Jump to search
m fix again |
Example |
||
| Line 11: | Line 11: | ||
dz = math.abs(bz - az) | dz = math.abs(bz - az) | ||
d = math.sqrt((dx ^ 2) + (dy ^ 2) + (dz ^ 2)) | d = math.sqrt((dx ^ 2) + (dy ^ 2) + (dz ^ 2)) | ||
return math.floor(d | return math.floor(d / 39.37) | ||
end | end | ||
</nowiki></pre> | </nowiki></pre> | ||
===Example=== | |||
Modified code of [[User:McSteve|McSteve's]] HP Announcer that uses dist() function to calculate ditance between killer and victim | |||
<pre><nowiki> | |||
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 | |||
</nowiki></pre> | |||
Put this and dist() function code to one lua file, it should work ^^ | |||
More stuff coming soon :> | More stuff coming soon :> | ||
[[Category:ETPro:Mods]] | [[Category:ETPro:Mods]] | ||
Revision as of 12:35, 10 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 / 39.37) end
Example
Modified code of McSteve'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 :>