[Lua] Distance'o-Meter


(Furion) #1

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

  1. 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 ^^
  2. 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.


(SCDS_reyalP) #2

In RTCW/ET, 1 unit = 1 inch, or 2.54cm. This is not the same as Q3.

You can contact bani on irc.freenode.net #etpro

I’m pretty sure the killer can be ENTITYNUM_NONE (1023) or ENTITYNUM_WORLD (1022). The safest thing to do is to check if the killernum is a valid client number.


(Furion) #3

If you right the divider should be 39.37 ;p
All hp announcers i meet was only checking that the killers id is not 1022 (how you can be killed by nothing? ;p) but ok i will correct the example.
Thx for solving unit mystery ^^ and for bani coordinates ;p


#4

If I remember correctly the server *u|k.public server 213.228.232.155:27960 , use a similar lua script (perhaps same) where when you die you see the HP of the player who killed you. It is a nice feature.


(TNR360) #5

where do I put the scripts in etpro?


#6

Im not 100% sure. But in my experience with a lua sound script the lua file/module goes into etpro folder on server, and in the server.cfg you load the file with the following command: set lua_modules “filename.lua”

More info here:


(Furion) #7

set lua_modules “filename.lua”

Yep, do it on rcon and restart the match :wink:

If I remember correctly the server *u|k.public server 213.228.232.155:27960 , use a similar lua script (perhaps same) where when you die you see the HP of the player who killed you. It is a nice feature.

Yea it is ^^ ETPro Lua API is very powerful ;p killer’s hp announcement its just little piece of it ;p it is will replace for python scripts like ETAdminMod


(kamikazee) #8

If you right the divider should be 39.37 ;p
All hp announcers i meet was only checking that the killers id is not 1022 (how you can be killed by nothing? ;p) but ok i will correct the example.
Thx for solving unit mystery ^^ and for bani coordinates ;p[/quote]You can be killed easily by 1022. This happens when you land on earth with a smack or get crushed under railgun’s train barrier.


(Furion) #9

I was talking about 1023 that is none ;p