i'm trying to display the player's current horizontal speed in tf2 on the beta vphysics branch currently. I have it working using the following code:
function updateSpeedoAll()
{
local ply = null
while (ply = Entities.FindByClassname(ply, "player")) {
local vel = ply.GetVelocity().Length2D()
local info = floor(vel).tostring() + " u/s"
// print using game_text entity
local output = Entities.FindByName(null, "text_output")
output.__KeyValueFromString("message", info)
EntFireByHandle(output, "Display", "", 0.0, ply, ply)
}
}
... where text_output is a game_text entity in the map. this is called from a logic_timer with refire of 0.015s since tf2 is 66.66... ticks per second outputting OnTimer -> MyScript -> RunScriptCode -> updateSpeedoAll().
this does work, but i'm wondering a few things.
- 1, will this be multiplayer-safe? I do think the game_text is only going to show on a specific player's screen but I'm not sure if updating the "message" keyvalue will be quick enough to always show player's only their speed.
- 2, is there perhaps a better way to do this than looping through all player entities every tick? maybe an event that can be listened to or something? my only coding experience is bodging bash/powershell scripts so i don't really know what i'm doing with regards to vscript and proper technique :^)