Created
April 29, 2018 20:48
-
-
Save birdbrainiac/0d68ff451afc489e19408edd6dc8fdfe to your computer and use it in GitHub Desktop.
For use with Darren's HeroTracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For use with Darren's HeroTracker | |
By The great Aaron | |
Type !sorths | |
*/ | |
on('ready', () => { | |
const sortHeroSystem = (a,b) => { | |
const aInt = (parseInt(a.pr)||0); | |
const aFloat = (parseFloat(a.pr)||0); | |
const bInt = (parseInt(b.pr)||0); | |
const bFloat = (parseFloat(b.pr)||0); | |
if( 12 === aInt && 12 !== bInt){ | |
return -1; | |
} | |
if( 12 !== aInt && 12 === bInt){ | |
return 1; | |
} | |
return (aFloat - bFloat); | |
}; | |
const sortTurnOrderDesc = () => { | |
let turns = JSON.parse(Campaign().get('turnorder')||'[]'); | |
turns.sort( sortHeroSystem ); | |
Campaign().set('turnorder', JSON.stringify(turns)); | |
}; | |
on("chat:message", function(msg) { | |
if (msg.type === "api" && /^!sorths\b/i.test(msg.content) && playerIsGM(msg.playerid) ) { | |
sortTurnOrderDesc(); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment