Reputation, Loyalty & Legend


Author: jwt3
Created: 2013-10-23T09:28:36-0400
Edited: 2013-10-23T09:35:32-0400
Denizen Version: 9.2
Views: 11
Downloads: 804
Likes: 0


WGET
Description: Rep & Loyalty: Tasks for tracking NPC to player loyalty and reputation and legend
This was developed to add to NPC reations. (Henchmen Loyalty, Town reputations etc.)

This script provides three sets of funtions to estalish
1) NPC LOYALTY: Each NPC will have a loyalty associated with each
player. This allows you to tailor the NPCs reaction to the player
2) PLAYER REPUTATION: This number is specific to World Edit regions.
Each player will carry a repution number specific to each region.
This allows seperate areas of player noteriety (e.g. certian towns
could have seperate values for each player).
3) LEGEND: Similar to PLAYER REPUTATION but world specific. Each player
will have a number representing their legendaryness (if that is a word)
on a world to world basis

NOTES:
- Nothing is created util accessed. (i.e. the flags are only created as
they are accesed/used)
- Each statistic has a min/max value to it. This prevents the values
from getting too high or low. These are set in the 'Add' tasks
- create a LLTester NPC to test this stuff (provided below)

Creation & use:

From within your scripts use the following tasks/procedures......
NPC LOYALTY:
PROCEDURE "NPC_Get_Loyalty" Called withing an NPC Script will return the
NPCs loyalty to the player
Examples:
- if < -10 chat "you stink!!!!!"

TASK "NPC Add Loyalty" called to add a number to the loyalty of the
NPC for the player. The first 'def' argument
is the number added/subtracted from the loyalty
Examples:
- run "NPC Add Loyalty" "def:3"
- run "NPC Add Loyalty" "def:-2"

TASK "NPC Set Loyalty" Called to set a NPCs loyalty to a number
Examples:
- run "NPC Set Loyalty" "def:0"

PLAYER REPUTATION:
PROCEDURE "Region_Get_Reputation" Called to retrieve a players reputation.
It will return the greatest reputation.
found within all regions the player is
currently standing in.
Examples:
- if > 10 chat "You are well liked"

TASK "Region Add Reputation" Called to add a number to the players reputation.
The number is added to all regions the player is
standing in.
Examples:
- run "Region Add Reputation" "def:5"
- run "Region Add Reputation" "def:-4"

TASK "Region Set Reputation" Called to set a players reputation to a specific number
- run "NPC Set Loyalty" "def:30"

TASK "Region Scale Reputation" Called to scale the players reputation
Use this to multiply up/down the reputation
Examples:
- run "Region Scale Reputation" "def:0.5"

LEGEND:
(these functions work identical to their reputation/loyalty counterparts)

PROCEDURE "proc:Player_Get_Legend" Returns players legend
Examples:
- if > 5 chat "I have heard of you know who you are"

TASK "Player Add Legend" called to add a number to the loyalty of the
NPC for the player. The first 'def' argument
is the number added/subtracted from the loyalty
Examples:
- run "Player Add Legend" "def:3"
- run "Player Add Legend" "def:-2"

TASK "Player Set Legend" Called to set a NPCs loyalty to a number
Examples:
- run "Player Set Legend" "def:Player Set Legend"

TODO:
- add OP level interface for changing values (needed ???)
- add reputation function for minimum reputation??? (do people use
overlapping regions a lot???)
- add NPC death task that will update all the parameters

Misc.
Author: J Taylor (jwt3)
Version: Denizen 9.2

Revision History:
1.0 initial upload
1.0a formatting fix for description of script

Comments and suggestions are most welcome

# Rep & Loyalty: Tasks for tracking NPC to player loyalty and reputation and legend
# This was developed to add to NPC reactions. (Henchmen Loyalty, Town reputations etc.)
#
# This script provides three sets of funtions to estalish 
#  1) NPC LOYALTY: Each NPC will have a loyalty associated with each
#     player. This allows you to tailor the NPCs reaction to the player
#  2) PLAYER REPUTATION: This number is specific to World Edit regions. 
#     Each player will carry a repution number specific to each region. 
#     This allows seperate areas of player noteriety (e.g. certian towns
#     could have seperate values for each player).
#  3) LEGEND: Similar to PLAYER REPUTATION but world specific. Each player
#     will have a number representing their legendaryness (if that is a word)
#     on a world to world basis
#
# NOTES:
#   - Nothing is created util accessed. (i.e. the flags are only created as
#     they are accesed/used)
#   - Each statistic has a min/max value to it. This prevents the values
#     from getting too high or low. These are set in the 'Add' tasks
#   - create a LLTester NPC to test this stuff (provided below)
#
# Creation & use:
#
#   From within your scripts use the following tasks/proceedures......
#   NPC LOYALTY:
#     <proc:NPC_Get_Loyalty> Called withing an NPC Script will return the 
#                            NPCs loyalty to the player
#                            Examples:
#                            - if <proc:NPC_Get_Loyalty> < -10 chat "<red>you stink!!!!!"
#
#     "NPC Add Loyalty"      called to add a number to the loyalty of the 
#                            NPC for the player. The first 'def' argument
#                            is the number added/subtracted from the loyalty
#                            Examples:
#                              - run "NPC Add Loyalty" "def:3"
#                              - run "NPC Add Loyalty" "def:-2"
#
#     "NPC Set Loyalty"      Called to set a NPCs loyalty to a number
#                            Examples:
#                              - run "NPC Set Loyalty" "def:0"
#                      
#   PLAYER REPUTATION:
#     <proc:Region_Get_Reputation>  Called to retrieve a players reputation.
#                                   It will return the greatest reputation.
#                                   found within all regions the player is 
#                                   currently standing in.
#                                   Examples:
#                                   - if <proc:Region_Get_Reputation> > 10 chat "<red>You are well liked"
#
#     "Region Add Reputation"  Called to add a numner to the players reputation.
#                              The number is added to all regions the player is
#                              standing in (including overlapping)
#                              Examples:
#                              - run "Region Add Reputation" "def:5"
#                              - run "Region Add Reputation" "def:-4"
#
#     "Region Set Reputation"    Called to set a players reputation to a specific number
#                                - run "NPC Set Loyalty" "def:30"
#
#     "Region Scale Reputation"    Called to scale the players reputation
#                                  Use this to multiply up/down the reputation
#                                  Examples:
#                                  - run "Region Scale Reputation" "def:0.5"
#
#   LEGEND:
#     (these funtions work identical to their reputation/loyalty counterparts)
#
#    <proc:Player_Get_Legend>   Returns players legend
#                               Examples:
#                               - if <proc:Player_Get_Legend> > 5 chat "<red>I have heard of you know who you are"
#
#     "Player Add Legend"      called to add a number to the loyalty of the 
#                            NPC for the player. The first 'def' argument
#                            is the number added/subtracted from the loyalty
#                            Examples:
#                              - run "Player Add Legend" "def:3"
#                              - run "Player Add Legend" "def:-2"
#
#     "Player Set Legend"    Called to set a NPCs loyalty to a number
#                            Examples:
#                            - run "Player Set Legend" "def:Player Set Legend"
#
# TODO:
#   - add OP level interface for changing values (needed ???)
#   - add reputation function for minimum reputation??? (do people use
#     overlapping regions a lot???)
#   - add NPC death task that will update all the parameters
#
# Misc.
#  Author: J Taylor (jwt3)
#  Version: Denizen 9.2
#
# Revision History:
#   1.0     initial upload
#
# Comments and suggestions are most welcome
# *****************************************************************************
 
# Test/demonstrator NPC
# /npc create ltest
# /npc assignment --set LLTester
"LLTester":
    type: assignment

    actions:
        on assignment:
        - trigger name:click toggle:true

    interact scripts:
    - 20 LLTester Interact

"LLTester Interact":
    type: interact
    speed: 5t
    Requirements:
        Mode: All

    steps:
        'idle*':
            click trigger:
                script:
                - engage
                - ^lookclose toggle:true
                - chat "loyalty <proc:NPC_Get_Loyalty>"
                - chat "reputation <proc:Region_Get_Reputation>"
                - chat "legend <proc:Player_Get_Legend>"
                # Examples from script description
                - if <proc:NPC_Get_Loyalty> < -10 chat "<red>you stink!!!!!"
                - if <proc:Player_Get_Legend> > 5 chat "<red>I know who you are"
                - if <proc:Region_Get_Reputation> > 10 chat "<red>You are well liked"
                - disengage

            chat trigger:
                # Testing ***********************************************
                't0':
                    trigger: /t0/, add +3 to loyalty
                    script:
                    - run "NPC Add Loyalty" "def:3"
                't1':
                    trigger: /t1/, add -2 to loyalty
                    script:
                    - run "NPC Add Loyalty" "def:-2"
                't2':
                    trigger: /t2/, add +5 to region rep
                    script:
                    - run "Region Add Reputation" "def:5"
                't3':
                    trigger: /t3/, add -4 to region rep
                    script:
                    - run "Region Add Reputation" "def:-4"
                't4':
                    trigger: /t4/, halve the reputation
                    script:
                    - run "Region Scale Reputation" "def:0.5"
                't5':
                    trigger: /t5/, add +3 to legend
                    script:
                    - run "Player Add Legend" "def:3"
                't6':
                    trigger: /t6/, add -9 to legend
                    script:
                    - run "Player Add Legend" "def:-9"
                't7':
                    trigger: /t7/, clear all to -1
                    script:
                    - run "Player Set Legend" "def:-1"
                    - run "Region Set Reputation" "def:-1"
                    - run "NPC Set Loyalty" "def:-1"
 
 
# ************************** Loyalty and Reputation *************************************        
# ************************** Loyalty and Reputation *************************************        
# ************************** Loyalty and Reputation *************************************        
# Call to change the loyalty of the Henchman.
# e.g. run "Henchman Add Loyalty" "def:2"
"NPC Add Loyalty":
    type: task
    script:
    - define "max" 20
    - define "min" -30
    - run "Add Limited NPC" "def:loyalty|%1%|%min%|%max%"
 
# Call to set the loyalty of the NPC
# e.g. run "Henchman Set Loyalty" "def:100"
"NPC Set Loyalty":
    type: task
    script:
    - flag npc "loyalty_<player.name>:%1%"
 
# Returns the loyalty of the NPC to the player       
"NPC_Get_Loyalty":
    type: procedure
    script:
    # create a 0 loyalty if it does not already exist
    - ^if <npc.flag[loyalty_<player.name>]> == null flag npc "loyalty_<player.name>:0"
    - determine <npc.flag[loyalty_<player.name>]>

# *************************** Reputation *************************************    
# *************************** Reputation *************************************    
# *************************** Reputation *************************************    
# Adds a number to the players reputation for all regions they are in
# e.g. - run "Region Add Reputation" "def:3"
"Region Add Reputation":
    type: task
    script:
    - define "max" 100
    - define "min" -100
    - ^flag player "temp_reg_list:<player.location.regions>"
    - ^foreach <player.flag[temp_reg_list].aslist> {
        - run "Add Limited Player" "def:reg_rep_%value%|%1%|%min%|%max%"
        }
 
# Sets the players reputation to a specific value (no min/max clipping)
# e.g. - run "Region Set Reputation" "def:100"
"Region Set Reputation":
    type: task
    script:
    - ^flag player "temp_reg_list:<player.location.regions>"
    - ^foreach <player.flag[temp_reg_list]> {
        - flag player "reg_rep_%value%:%1%"
        }
 
# Multiplies the players reputation by a number (no min/max clipping)
# e.g. - run "Region Set Reputation" "def:0.75"
"Region Scale Reputation":
    type: task
    script:
    - ^flag player "temp_reg_list:<player.location.regions>"
    - ^foreach <player.flag[temp_reg_list]> {
        - ^if <player.flag[reg_rep_%value%]> == null flag player "reg_rep_%value%:0"
        - ^flag "reg_rep_%value%:*:%1%"
        }
 
# Returns the maximum reputation found all the regions the player is
# currently standing in
# e.g. - if <proc:Region_Get_Reputation> < 10 chat "You Stink!"
"Region_Get_Reputation":
    type: procedure
    script:
    - ^flag player "temp_reg_list:<player.location.regions>"
    - ^if <player.flag[temp_reg_list].aslist.size> > 0 {
        - ^flag player temp_mrep:-100
        - ^foreach <player.flag[temp_reg_list]> {
            - ^if <player.flag[reg_rep_%value%]> == null flag player "reg_rep_%value%:0"
            - ^if <player.flag[reg_rep_%value%]> > <player.flag[temp_mrep]> {
                - ^flag player "temp_mrep:<player.flag[reg_rep_%value%]>"
                }
            }
        - determine <player.flag[temp_mrep]>
        }
    - determine 0
 
# Lists reputations of regions you are standing in (call from world script)
"Region Print Reputation":
    type: task
    script:
    - ^flag player "temp_reg_list:<player.location.regions>"
    - ^if <player.flag[temp_reg_list].aslist.size> > 0 {
        - narrate "<yellow>You are standing in <player.flag[temp_reg_list].aslist.size> regions"
        - ^foreach <player.flag[temp_reg_list]> {
            - narrate "<yellow><player.flag[reg_rep_%value%]> in '%value%'"
            }
        }
        else narrate "<yellow>You are not in a defined region"
 
# ********************************** LEGEND ******************************************        
# ********************************** LEGEND ******************************************        
# ********************************** LEGEND ******************************************        
"Player Add Legend":
    type: task
    script:
    - define "max" 200
    - define "min" -200
    - run "Add Limited Player" "def:legend_<player.location.world.name>|%1%|%min%|%max%"
    
"Player Set Legend":
    type: task
    script:
    - flag player "legend_<player.location.world.name>:%1%"

"Player_Get_Legend":
    type: procedure
    script:
    - ^if <player.flag[legend_<player.location.world.name>]> == null flag player "legend_<player.location.world.name>:0"
    - determine <player.flag[legend_<player.location.world.name>]>
    
# *************************** World Level Commands *********************************    
# *************************** World Level Commands *********************************    
# *************************** World Level Commands *********************************    
"World_Reputation":
    type: world
    
    events:
        # This command lists the reputation of any regions the player is 
        # standing in. It also doubles as the initializer for the min and 
        # max values for reputation and loyalty
        on rrep command:
        - run "Region Print Reputation"
        - determine fulfilled
 
# *********************** Support Functions ******************************        
# *********************** Support Functions ******************************        
# *********************** Support Functions ******************************        
 
# This task adds a number to a player flag (creates it if it does not exist. 
# The 'def' arguments are as follows
#   - run "Add Limited Player" "def:desc|mod|min|max"
#           dsc - is a text entry that is used to create the 
#                 flag.
#           mod - is the number to be added
#           min - is the mimimum value (clipped if below this)
#           max - is the maximum value (clipped if above this)
#   Example
#   - run "Add Limited Player" "def:test|3|-10|10"
#      this will create a player flag (if it does not exist) named 
#      'test_<player_name>' and either set it to 3 (if it does not already
#      exist) or add 3 to the existing flag
"Add Limited Player":    
    type: task
    context: value
    script:
    - ^if <player.flag[%1%]> == null flag player "%1%:%2%"
        else flag player "%1%:+:%2%"
    # clip value
    - ^if <player.flag[%1%]> > %4% flag player "%1%:%4%"
       else if <player.flag[%1%]> < %3% flag player "%1%:%3%"
 
# Same as the "Add Limited Player" but for NPCs
"Add Limited NPC":    
    type: task
    script:
    - ^if <npc.flag[%1%_<player.name>]> == null flag npc "%1%_<player.name>:%2%"
        else flag npc "%1%_<player.name>:+:%2%"
    # clip value
    - ^if <npc.flag[%1%_<player.name>]> > %4% flag npc "%1%_<player.name>:%4%"
       else if <npc.flag[%1%_<player.name>]> < %3% flag npc "%1%_<player.name>:%3%"
 




Comments
No one has posted a comment! Post one below: