Hitpoints manager


Author: beecee
Created: 2013-11-03T20:56:37-0500
Edited: 2013-12-15T16:10:38-0500
Denizen Version: 1370
Views: 65
Downloads: 890
Likes: 2


WGET
Description: A script to completely manage players their hitpoints.
You can set default hitpoints by permissions, and add hitpoints on top of that.
You can even set a maximum capacity on the amount of hearts people can get on your server, in case you want to give out hearts in quests and such, but don't want to let it get out of hand.
you can also check how many hitpoints a player has.

commands:
/hp refresh player/all
/hp add/remove/set player amount (-nocap)
/hp cap (amount)
/hp check player
/hp help
permissions:
- hp.refresh
- hp.edit
- hp.cap
- hp.check

-- adjusting the by permission hitpoints --
Currently in the script are 4 hp by permission examples:
hp.knight gets 36 hp
hp.monk gets 32 hp
hp.warrior gets 28 hp
hp.ranger gets 24 hp

in order to adjust these, scroll down to the bottom of the script.
you'll find instructions in there?

If you find any bugs, or have any suggestions can't or don't want to implement yourself, post it in the comments!

Hope people will find this useful!

"hpcmds":
    type: world
    events:
        on hp command:
        - if <context.args.get[1]> == refresh {
          - if <player.has_permission[hp.refresh]> != true {
            - narrate "<&c>You do not have the permission to do this."
            - determine fulfilled
            - queue clear
            }
          - if <context.args.size> < 2 {
            - narrate "<&c>Usage<&co> /hp refresh <<>player/all<>>"
            - determine fulfilled
            - queue clear
            }
          - if <context.args.get[2]> == all {
            - foreach <server.list_online_players> {
            - run hprefresh as:%value%
              }
              - announce "<&b>All player hitpoints have been refreshed." 
            - determine fulfilled
            } else {
            - define hp_player <server.match_player[<context.args.get[2]>]>
            - if %hp_player% == null {
              - narrate "<&c>This player is not online."
              - determine fulfilled
              - queue clear
              }
            - run hprefresh as:%hp_player%
            - narrate "<&b><&c><%hp_player%.name>'s<&b> hitpoints have been refreshed."
            - narrate target:%hp_player% "<&b>Your hitpoints have been refreshed."
            - determine fulfilled
            }
          } else if <context.args.get[1]> == add {
            - if <player.has_permission[hp.edit]> != true {
              - narrate "<&c>You do not have the permission to do this."
              - determine fulfilled
              - queue clear
              }
            - define hp_player <server.match_player[<context.args.get[2]>]>   
            - define hp_amount <context.args.get[3]>            
            - if <context.args.size> < 3 {
              - narrate "<&c>Usage<&co> /hp add <<>player<>> <<>amount<>>"
              - determine fulfilled
              - queue clear
              }
            - if %hp_player% == null {
              - narrate "<&c>This player is not online."
              - determine fulfilled
              - queue clear
              }
            - if %hp_amount% != 0 && <m:%hp_amount%> == 0.0 {
              - narrate "<&c>Amount has to be a number!"
              - determine fulfilled
              - queue clear
              }
            - if <el@val[<math:%hp_amount%+<%hp_player%.flag[bonushp]>>].asint> > <server.flag[hpcap].asint> && <server.flag[hpcap]> != 'unlimited' && <context.args.get[4]> != '-nocap' {
              - narrate "<&c>Doing that would bring <&c><%hp_player%.name>'s<&c> hitpoints over the set maxium hitpoints capacity."
              - narrate ""
              - narrate "<&a>To change the max capacity use<&co> /hp cap <<>amount/unlimited<>>"
              - narrate ""
              - narrate "<&a>To ignore the max capacity in a command add '-nocap' at the end of it."
              - narrate target:%hp_player% "<&c>You can't gain any more hitpoints!"
              - determine fulfilled
              - queue clear
              }
            - flag %hp_player% bonushp:+:%hp_amount%
            - narrate "<&b>You've added <&c>%hp_amount%<&b> bonus hitpoints to <&c><%hp_player%.name><&b>."
            - narrate target:%hp_player% "<&b>You've gained <&c>%hp_amount%<&b> bonus hitpoint(s)!"
            - run hprefresh as:%hp_player%
            - determine fulfilled
            - queue clear
          } else if <context.args.get[1]> == remove || <context.args.get[1]> == take {
            - if <player.has_permission[hp.edit]> != true {
              - narrate "<&c>You do not have the permission to do this."
              - determine fulfilled
              - queue clear
              }
            - if <context.args.size> < 3 {
              - narrate "<&c>Usage<&co> /hp remove <<>player<>> <<>amount<>>"
              - determine fulfilled
              - queue clear
              }
            - define hp_player <server.match_player[<context.args.get[2]>]>
            - if %hp_player% == null {
              - narrate "<&c>This player is not online."
              - determine fulfilled
              - queue clear
              }
            - define hp_amount <context.args.get[3]>
            - if %hp_amount% != 0 && <m:%hp_amount%> == 0.0 {
              - narrate "<&c>Amount has to be a number!"
              - determine fulfilled
              - queue clear
              }
            - if <el@val[<math:<%hp_player%.flag[bonushp]>-%hp_amount%>].asint> > <server.flag[hpcap].asint> && <server.flag[hpcap]> != 'unlimited' && <context.args.get[4]> != '-nocap' {
              - narrate "<&c>Doing that would bring <&c><%hp_player%.name>'s<&c> hitpoints over the set maxium hitpoints capacity."
              - narrate ""
              - narrate "<&a>To change the max capacity use<&co> /hp cap <<>amount/unlimited<>>"
              - narrate ""
              - narrate "<&a>To ignore the max capacity in a command add '-nocap' at the end of it."
              - narrate target:%hp_player% "<&c>You can't gain any more hitpoints!"
              - determine fulfilled
              - queue clear
              }
            - flag %hp_player% bonushp:-:%hp_amount%
            - narrate "<&b>You've removed <&c>%hp_amount%<&b> bonus hitpoints from <&c><%hp_player%.name><&b>."
            - narrate target:%hp_player% "<&b>You've lost <&c>%hp_amount%<&b> bonus hitpoint(s)!"
            - run hprefresh as:%hp_player%
            - determine fulfilled
            - queue clear
          } else if <context.args.get[1]> == set {
            - if <player.has_permission[hp.edit]> != true {
              - narrate "<&c>You do not have the permission to do this."
              - determine fulfilled
              - queue clear
              }
            - if <context.args.size> < 3 {
              - narrate "<&c>Usage<&co> /hp set <<>player<>> <<>amount<>>"
              - determine fulfilled
              - queue clear
              }
            - define hp_player <server.match_player[<context.args.get[2]>]>
            - if %hp_player% == null {
              - narrate "<&c>This player is not online."
              - determine fulfilled
              - queue clear
              }
            - define hp_amount <context.args.get[3]>
            - if %hp_amount% != 0 && <m:%hp_amount%> == 0.0 {
              - narrate "<&c>Amount has to be a number!"
              - determine fulfilled
              - queue clear
              }
            - if %hp_amount% > <server.flag[hpcap].asint> && <server.flag[hpcap]> != 'unlimited' && <context.args.get[4]> != '-nocap' {
              - narrate "<&c>Doing that would bring <&c><%hp_player%.name>'s<&c> hitpoints over the set maxium hitpoints capacity."
              - narrate ""
              - narrate "<&a>To change the max capacity use<&co> /hp cap <<>amount/unlimited<>>"
              - narrate ""
              - narrate "<&a>To ignore the max capacity in a command add '-nocap' at the end of it."
              - narrate target:%hp_player% "<&c>You can't gain any more hitpoints!"
              - determine fulfilled
              - queue clear
              }
            - flag %hp_player% bonushp:%hp_amount%
            - narrate "<&b>You've set <&c><%hp_player%.name>'s<&b> bonus hitpoints to <&c>%hp_amount%.<&b>."
            - narrate target:%hp_player% "<&b>Your bonus hitpoints have been set to <&c>%hp_amount%.<&b>."
            - run hprefresh as:%hp_player%
            - determine fulfilled
            - queue clear
          } else if <context.args.get[1]> == cap {
            - if <player.has_permission[hp.cap]> != true {
              - narrate "<&c>You do not have the permission to do this."
              - determine fulfilled
              - queue clear
              }
            - if <context.args.size> < 2 {
              - narrate "<&b>The maximum hitpoints capacity on this server is set to <&c><server.flag[hpcap]><&b>."
              - narrate "<&c>Usage<&co> /hp cap <<>amount/unlimited<>>"
              - determine fulfilled
              - queue clear
              }
            - define hp_cap <context.args.get[2]>
            - if %hp_cap% != 'unlimited' && %hp_cap% != 0 && <m:%hp_cap%> == 0.0 {
              - narrate "<&c>Amount has to be a number or 'unlimited'!"
              - determine fulfilled
              - queue clear
              }
            - flag global hpcap:%hp_cap%
            - narrate "<&b>You've set the maximum hitpoints capacity to <&c>%hp_cap%<&b>."
            - determine fulfilled
            - queue clear
          } else if <context.args.get[1]> == check {
            - <player.has_permission[hp.health]> != true {
              - narrate "<&c>You do not have the permission to do this."
              - determine fulfilled
              - queue clear
              }
            - if <context.args.size> < 2 {
              - narrate "<&c>usage<&co> /hp check <<>player<>>"
              - determine fulfilled
              - queue clear
              }
            - define hp_player <server.match_player[<context.args.get[2]>]>
            - if <%hp_player%.is_online> == true {
              - narrate "<&b><&c><%hp_player%.name><&b> has a total of <&c><%hp_player%.health.asint> / <%hp_player%.health.max.asint><&b> hitpoints of which <&c><%hp_player%.flag[bonushp].asint||0><&b> are bonus hitpoints and <&c><el@val[<m:<%hp_player%.health.max>-<%hp_player%.flag[bonushp]||0>>].asint><&b> are default or by permission hitpoints."
              - determine fulfilled
              - queue clear
              }
              - narrate "<&c>This player is not online."
              - determine fulfilled
              - queue clear
          } else if <player.has_permission[hp.edit]> != true || <player.has_permission[hp.refresh]> != true || <player.has_permission[hp.health]> != true {
              - narrate "<&c>You do not have the permission to do this."
              - determine fulfilled
              - queue clear
              }
            - narrate ""
            - narrate "<&c>usage<&co> /hp refresh <<>player/all<>>"
            - narrate "<&a>description<&co> Refreshes the amount of hitpoints for a player or all online players."
            - narrate "<&c>usage<&co> /hp <<>add/remove/set<>> <<>player<>> <<>amount<>> (-nocap)"
            - narrate "<&a>description<&co> Edits the bonus hitpoints of a player."
            - narrate "<&c>usage<&co> /hp cap <<>amount/unlimited<>>"
            - narrate "<&a>description<&co> Edits the maximum number hitpoints obtainable on this server. "
            - narrate "<&c>usage<&co> /hp cap"
            - narrate "<&a>description<&co> shows the maximum number hitpoints obtainable on this server. "
            - narrate "<&c>usage<&co> /hp check <<>player<>>"
            - narrate "<&a>description<&co> Returns the amount of hitpoints the player has."
            - narrate "<&c>usage<&co> /hp help"
            - narrate "<&a>description<&co> Shows this page."
            - determine fulfilled
            - queue clear
            } else {
            - narrate "<&c>You do not have the permission to do this."
            - determine fulfilled
            - queue clear
            }
"hpevents":
    type: world
    events:
        on player joins:
        - run hprefresh as:<player>
"hprefresh":
    type: task
    script:
        - health player:<player> player <el@val[<player.flag[bonushp]||0>].add[20].as_int>
        - ^if <player.has_permission[hp.knight]> == true health player:<player> player <el@val[<player.flag[bonushp]||0>].add[36].as_int>
        - ^if <player.has_permission[hp.monk]> == true health player:<player> player <el@val[<player.flag[bonushp]||0>].add[32].as_int>
        - ^if <player.has_permission[hp.warrior]> == true health player:<player> player <el@val[<player.flag[bonushp]||0>].add[28].as_int>
        - ^if <player.has_permission[hp.ranger]> == true health player:<player> player <el@val[<player.flag[bonushp]||0>].add[24].as_int>

# usage:
  # commands:
    # /hp refresh <player/all>
    # /hp <add/remove/set> <player> <amount> (-nocap)
    # /hp cap (<amount>)
    # /hp check <player>
    # /hp help
  # by permissions:
    # to customize the by permission hitpoints, copy this line and paste it inside the "hprefresh" task script.
    # take in mind if player passes multiple if statements, he gets the hitpoints from the last one that passed.
 
        # - ^if <player.has_permission[hp.ranger]> == true health player:<player> player <el@val[<player.flag[bonushp]||0>].add[24].as_int>
                                      # ^ edit permission node here.                                                            ^ edit amount of HP by permission here.
    #
    # Thank you to mcmonkey from denizen for helping create this.




Comments
2013-11-04 10:02:56 - beecee:

one more small bug remains: I've failed to implement '.asint' inside this tag properly: <&c>-<%hp_player%.flag[bonushp]>> if you know how please let me know!
2013-11-06 13:41:39 - beecee:

^ is now fixed. also fixed various minor mathematical bugs with the cap. any command that will result into bringing the bonus hp above the cap, will not pass without the -nocap. Even not taking enough hp away, to go below the cap (if the player would be above the cap).