Find actor id last position in party

Is there any script command to get the actor id at the last place in the party?
Try this (e.g. in Control Variables -> Script):
JavaScript:
var m = $gameParty.members(); m[m.length - 1].actorId()
This assumes there is at least one actor in the party.

If you only want to check the active/battle party (ignoring reserve members) then use battleMembers instead, e.g.
JavaScript:
var m = $gameParty.battleMembers(); m[m.length - 1].actorId()
it can also be done without scripts by event commands alone, but then it is a bit more complex.

you can use control variable to get the actor ID on any party position, and when that returns zero you know there is no longer a party member and you'll have to use the previous index for the last member
Must admit that I would be tempted to get the party size by using the event command "control variable" > "Game Data" > "Others" > "Party Members". For example, let's say that you set variable number 10 to store "Party Members".

The index of party members starts at 0, so, for example, for a party of 4, the index of the last party member would be 3. You need subtract 1 from the variable that you put the party size into, so another "control variable" command for variable number 10, this time just subtract 1.

Next, use one line of script in a "control variable" to return the actor id that you want:

$gameParty.members()[$gameVariables.value(10)].actorId();

Total of 3 "control variable" editor commands, with just a fragment of script in the third.

Edit: This assumes that you are just doing an event. I prefer the above because I would find it easy to understand and revise in a few months time. If you are writing a plugin then of course caethyril's script would be what you want.
Total of 3 "control variable" editor commands, with just a fragment of script in the third.
It seems to me that if you're going to have any script boxes filled in at all, there's no reason to use 3 event commands instead of just one. So you'd just Control Variable -> Script:
Code:
$gameParty.battleMembers()[$gameParty.battleMembers().length-1].actorId()

Note: I'm presuming that the OP saying "the last position in the party" means the last follower. If you meant the last person of all actors you have recruited (so, I guess, the most recent?), you'd replace both instances of battleMembers with just members.

Original thread: https://forums.rpgmakerweb.com/threads/find-actor-id-last-position-in-party.141252/