If you already know which effect the envelope is attached to, you can get the parameter index from the envelope state chunk.
Code:
local track = reaper.GetTrack(0, 0)
local env = reaper.GetTrackEnvelope(track, 0)
local _, chunk = reaper.GetEnvelopeStateChunk(env, "", false)
reaper.ShowConsoleMsg(chunk)
--[[
spits out:
<PARMENV 4 0.000000 1.000000 0.500000
ACT 1 -1
VIS 1 1 1
LANEHEIGHT 0 0
ARM 0
DEFSHAPE 0 -1 -1
PT 0 0.5 0
PT 1 0.5 0
PT 2 0.3 0 0 1
>
]]--
The parameter index is the very first number there, so it's an easy string match:
Code:
local paramIndex = chunk:match("PARMENV (%d+)")
(Don't forget to convert it to a number afterward)