Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

Who moved the token last

I'm trying to find the value for the playerid that last moved a token. I can't seem to find it anywhere, have any of you found this?
1608259051
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
This might be a better question for the API forum. At least you'd be able to get the attention of more scripters.
1608259621
The Aaron
Roll20 Production Team
API Scripter
The only way to know who last moved a token is to only have one person that is capable of moving it.  There's no setting or event or anything that can identify who moves a token. What problem are you trying to solve?  There might be another solution.
I have a teleport script that can teleport someone from one map to another and change the player to that map as well.  If there are two owners of the token then the 20 digit Player Id is now a 40 digit Id, which doesn't work. So any token that has more than one owner cannot move the player to the new map, I still have to move them manually. I thought about just truncating the value to 20 characters and move the first owner, but if the second owner is the one that moved it then the wrong player would be moved to the new map. I could split the Id into the 2 strings and move both, but if the second player moved the token then the first player would be moved to the new map as well. So if I can find a way to record the player that moved the token last then I can get around this issue altogether by just calling that value instead of the owners Id.
1608285803

Edited 1608285935
Oosh
Sheet Author
API Scripter
I think you'd have to set something up for this to work. Have the token only controlled by one person at a time, and give the players a target macro which sends an API command to switch control of the token to them and log the change of ownership. Eg: !takeControl --tokenid @{target|t1|token_id} If the players have that macro on their bar, they just click the button then click the token and it's theirs to control, removing the other player. The takeControl script can grab their playerid from the chat message and store it in the State object, or pass it on to wherever it needs to go. Maybe there's a less clunky way to do it though.
1608290564
Brian C.
Pro
Marketplace Creator
Compendium Curator
Forgive my ignorance, but is there not a way to set a custom attribute/set GM Notes on the token to record the player id? Or is the problem that the script does not know who did the moving?
1608305453
The Aaron
Roll20 Production Team
API Scripter
The API has no way of knowing who moves a token, there is no id attached to the event, just the change to the token itself. I would suggest sending a prompt to each player that controls the token and ask them if they want to follow it.  That would let them move with the token if they were the one that moved it, but wouldn't force anyone to move. If you post the code, we could try to find a way to fix your user id concatenation problem.  It sounds like you need to do a .join(',') somewhere that you have a .join('').