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 .
×
Create a free account

[Script] LazyExperience

1523539683
Robin
API Scripter
I just finished the first version of my experience script. Github Link LazyExperience is a script to record experience during a game (the idea comes from  EasyExperience ). Biggest difference is that it has an option to reward experience directly, and keeps track on statusmarker changes on tokens. Config The first time you add this script you get a first time config menu in chat. Command - The command you want to use with this script, eg. !xp. Marker - The "dead" marker you want to use to give an option to reward experience when something dies. Player XP Attribute - The player's experience attribute in the sheet you are using, this is defaulted to the 5e OGL sheet (experience). NPC XP Attribute - The npc's experience attribute in the sheet you are using, this is defaulted to the 5e OGL sheet (npc_xp). Extra Players - This can be used to add to the experience divisors (eg. for npc under no one's control, etc). Give XP Instant - If you want to instantly give experience to the players when you reward it, otherwise it will be rewarded at the end of the session. Update Sheets - If you want to update the characters sheets when experience is rewarded. Refresh Players - Refresh the player list (eg. when a new player joins or someone leaves). Reset Experience - Resets the experience back to 0. Reset Config - Resets the config options to default. Player Config Active Toggles - Sets the player/character active (or not). A player/character who is not active will not be rewarded xp at the end of the session and will not be in the LazyExperience menu list. Add Experience - Reward experience to (one of) the player's character(s). Back - Back to the config menu. Remove - Removes the player entirely from the LazyExperience config. Commands !xp help - Shows the help menu. !xp config - Shows the config menu. !xp menu - Shows the LazyExperience menu (more below). !xp add session [XP] - Adds (or gives if you want to give instantly) experience to the session experience threshold, where [XP] is the amount of experience. !xp add [characterid] [XP] - Adds (or gives if you want to give instantly) experience to the character experience threshold, where [characterid] is the character's id and [XP] is the amount of experience. !xp end - Ends the session, reset experience, and rewards experience to the players (if you didn't reward it instantly). LazyExperience Menu This menu shows the current experience in the session threshold. It also show the amount it will be divised with when rewarded. A list of active players with there active characters is also shown here, and experience can be rewarded. Statusmarker Dead When a token is given the statusmarker you have set up in the config ("dead" by default), you will get the question if you want to add the experience to the session experience threshold. Github Link
Sweet. I'm using EasyExperience for quite some time now, but I'll definitely give this one a try over the weekend. 
1523541557

Edited 1523541620
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Nice adaptation. Looks like a great script.
1523553117
Gold
Forum Champion
I like the idea. I've been giving XP to full group and have them split it (divide it). I like how this script would make it super-easier to award individuals XP.
Anyone else having an issue with the script not finding your PC's?
I'm getting this error For reference, the error message generated was: ReferenceError: player is not defined ReferenceError: player is not defined at array_diff.forEach (apiscript.js:9449:46) at Array.forEach (native) at refreshPlayers (apiscript.js:9448:49) at Object.checkInstall [as CheckInstall] (apiscript.js:9419:9) at on (apiscript.js:9575:20) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at checkForReady (/home/node/d20-api-server/api.js:1438:12) at /home/node/d20-api-server/api.js:1518:9 at c (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:14:64) Please help me fix it.
1524846775

Edited 1524846846
The Aaron
Pro
API Scripter
Not sure if this fixes the problem, but this should fix the crash.  On line 555, adjust the refreshPlayers function:     refreshPlayers = () => {         let saved_players = Object.keys(state[state_name].players).map((playerid, i) => { return playerid });         // Player added?         array_diff(saved_players, getPlayers()).forEach((playerid) => {             let player = getPlayerById(playerid);             if(player){                 state[state_name].players[playerid] = {                     name: player.get('_displayname'),                     id: playerid,                     active: true,                     experience: 0,                     characters: getPlayerCharacters(playerid)                 };             }         });         // Player removed?         array_diff(getPlayers(), saved_players).forEach((playerid) => {             delete state[state_name].players[player];         });     }, I'm guessing you removed a player from the game at some point, or they left, or whatever.  Basically, it's trying to get a player that isn't part of the game anymore, so player ends up as undefined.
The Aaron said: Not sure if this fixes the problem, but this should fix the crash.  On line 555, adjust the refreshPlayers function:     refreshPlayers = () => {         let saved_players = Object.keys(state[state_name].players).map((playerid, i) => { return playerid });         // Player added?         array_diff(saved_players, getPlayers()).forEach((playerid) => {             let player = getPlayerById(playerid);             if(player){                 state[state_name].players[playerid] = {                     name: player.get('_displayname'),                     id: playerid,                     active: true,                     experience: 0,                     characters: getPlayerCharacters(playerid)                 };             }         });         // Player removed?         array_diff(getPlayers(), saved_players).forEach((playerid) => {             delete state[state_name].players[player];         });     }, I'm guessing you removed a player from the game at some point, or they left, or whatever.  Basically, it's trying to get a player that isn't part of the game anymore, so player ends up as undefined. The Aaron, reliable as always  I kinda brute forced it by just copy the whole game and recreate the API Sandbox, and that fixed it. But still thank you the help, I now know what to do if that happen again. 
1524848212
Robin
API Scripter
The fix from The Aaron should indeed fix this. Do you know what happened before this error happened? Did indeed a player leave?
1524848811
The Aaron
Pro
API Scripter
Moving the Player Removed above the Player Added should also solve the problem, provided you re-set the saved_players variable.
Robin said: The fix from The Aaron should indeed fix this. Do you know what happened before this error happened? Did indeed a player leave? No, not really, but I'm Co-GMing, not GM or the player. Could that be the cause? And it happened again, after a while, when I add new API. I tried to copy and redo the API multiple times, even change the code like The Aaron said, but it only work when I just redo it. When I tried to add another API, even just the 5th Edition OGL by Roll20 Companion Script, the same error show up.
1525380746
Robin
API Scripter
James S. said: No, not really, but I'm Co-GMing, not GM or the player. Could that be the cause? And it happened again, after a while, when I add new API. I tried to copy and redo the API multiple times, even change the code like The Aaron said, but it only work when I just redo it. When I tried to add another API, even just the&nbsp;5th Edition OGL by Roll20 Companion&nbsp;Script, the same error show up. There was indeed a bug in my script when a player left. It should be fixed now, get the latest version here: <a href="https://github.com/RobinKuiper/Roll20APIScripts/tr" rel="nofollow">https://github.com/RobinKuiper/Roll20APIScripts/tr</a>... It will be updated in the one click installer soon.
Robin said: James S. said: No, not really, but I'm Co-GMing, not GM or the player. Could that be the cause? And it happened again, after a while, when I add new API. I tried to copy and redo the API multiple times, even change the code like The Aaron said, but it only work when I just redo it. When I tried to add another API, even just the&nbsp;5th Edition OGL by Roll20 Companion&nbsp;Script, the same error show up. There was indeed a bug in my script when a player left. It should be fixed now, get the latest version here: <a href="https://github.com/RobinKuiper/Roll20APIScripts/tr" rel="nofollow">https://github.com/RobinKuiper/Roll20APIScripts/tr</a>... It will be updated in the one click installer soon. Wonderful,&nbsp; I'll update my sandbox.