Skip to content

Permissions

Daniel Böttner edited this page Nov 29, 2021 · 5 revisions

LootSheetNPC5e comes with a permission system that allows observers to interact with the sheet.

There are two relevant Permissions for LootSheetNPC5e.

Permission Description
observer Minimum permissions need for players to interact with the sheet.
owner Grant full control to a sheets token (edit inventory, move, speak as)

To allow players to loot or buy items from a sheet the players need at least observer permissions.

Permissions via API

Get permissions

Get the tokens current permissions

const API =  game.modules.get("lootsheetnpc5e").public.API; // get the LootSheetNPC5e public API
API.getLootPermissionForPlayers(token); //  Return the players current permissions or the sheets default permissions

Get a tokens current permission for a list of players

const API =  game.modules.get("lootsheetnpc5e").public.API; // get the LootSheetNPC5e public API

// The api defaults to all players anyway
const API =  game.modules.get("lootsheetnpc5e").public.API,
      verbose = true; //get verbose output
      
if(verbose) {

/** 
* Get all players 
* The api defaults to this anyway, can be omitted
**/
 const players = game.users.filter((user) => {return (user.role == 'player' || user.role == 'trusted' )});  
 
   console.log(
        'LSNPC5e_getPermissions Macro',
        API.getPermissionForPlayers(token, players, verbose)
        );
} else {
    let result = API.getPermissionForPlayers();
    // do something with result
    console.log(result);
}

Set observable Permissions

const API =  game.modules.get("lootsheetnpc5e").public.API, // get the LootSheetNPC5e public API
      token = canvas.tokens.controlled[0], //get first selected token
      players = game.users.filter((user) => {return (user.role == 'player' || user.role == 'trusted' )});  

/*
* Both parameters could be omitted
* defaults to 
*  - selected tokens (game.canvas.tokens.controlled)
*  - all players
*/
API.makeObservable(token,players);

Convert a single token to a lootable token/sheet

const API =  game.modules.get("lootsheetnpc5e").public.API,
type = 'merchant', // could be merchant or loot
    verbose = false; //generate console.logs
    
if(verbose) {
    API.getPermissionForPlayers(token,undefined,verbose);
    await API.convertToken(token, type, undefined, verbose);
    API.getPermissionForPlayers(token,undefined,verbose);
} else {
   let res = await API.convertToken();
   // do something with the result or ignore it
   console.log(res)
}

Convert an array of tokens to a lootable token/sheet

//get the LootSheetNPC5e public API
const API =  game.modules.get("lootsheetnpc5e").public.API,
    type= 'loot',
    // example of options, unused below
    options = {
        chanceOfDamagedItems: 0,
        damagedItemsMultiplier: 0,
        removeDamagedItems: false
    },
    verbose = false; //generate console.logs
    
if(verbose) {
    let res = await API.convertTokens(
            canvas.tokens.controlled,
            type,
            undefined,
            verbose
        );
   // do something with the result or ignore it
   console.log(res) 
} else {
   let res = await API.convertTokens();
   // do something with the result or ignore it
   console.log(res)
}

Permissions via Macros

You can find Macros making use of all the following Examples in the macro compendium shipped with the module.