User:Furion: Difference between revisions

From WolfWiki
Jump to navigation Jump to search
Furion (talk | contribs)
Example
Furion (talk | contribs)
m More optimized version
 
(3 intermediate revisions by 2 users not shown)
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 / 39.37)
return math.floor(d / 52.4934)
end
end
</nowiki></pre>
More optimized version:
<pre><nowiki>
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
</nowiki></pre>
</nowiki></pre>
===Example===
===Example===
Modified code of [[User:McSteve|McSteve's]] HP Announcer that uses dist() function to calculate ditance between killer and victim
Modified code of [[User:Phenomenon|Phenomenon's]] HP Announcer that uses dist() function to calculate ditance between killer and victim


<pre><nowiki>
<pre><nowiki>

Latest revision as of 22:15, 17 June 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

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 

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 :>