Paste #63533: check

Date: 2020/01/04 18:37:34 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


world_script:
    type: world
    events:
        #todo 
        #/ex narrate "<server.list_notables>"
        #convert to - flag server cuboids:notabe/owner
        on world loads:
        - if <server.flag[index]>|| null == null:
            - flag server index:1
        - if <farmcube||null> == null:
            - note <cuboid[0,0,0,world|0,0,0,world]> as:farmcube
        #mayor creation
        on player right clicks stone_bricks with wheat:
        - take iteminhand
        - drop mayor_placer <context.location>
        on player right clicks block with mayor_placer:
        - if !<player.has_flag[has_mayor]>:
            - take iteminhand
            - create player mayor <context.location.add[0,2,0]> save:mayorID
            - assignment set script:mayor_assignment npc:<entry[mayorID].created_npc>
            - adjust <entry[mayorID].created_npc> owner:<player.name> 
            - adjust <entry[mayorID].created_npc> lookclose:true
            - flag player has_mayor:<entry[mayorID].created_npc>
            - determine cancelled
        - else:
            - narrate "you already have a mayor"
            - narrate "dismiss your mayor to spawn a new one"
            - narrate "or type /resetmayor to remove your mayor"
            - determine cancelled
        #mayor creation end

        ##mayor interactions
        ##
        ##
        #create a soldier npc
        on player clicks mayor_hire_soldier in mayor_menu:
        - if  <player.inventory.quantity.material[wheat]> >= 64  && <player.flag[soldier]||0> < 5:
            - take wheat quantity:64
            - narrate "you hired a soldier"
            - create player soldier <player.location.add[0,2,0]> trait:sentinel save:soldierID
            - flag player soldier:++
            - assignment set script:soldier_assignment npc:<entry[soldierID].created_npc>

            #configure soldier as sentinel owned by player
            - adjust <entry[soldierID].created_npc> owner:<player.name>
            - adjust <entry[soldierID].created_npc> speed:1.3
            - execute as_op "npc select <entry[soldierID].created_npc.id>" silent
            - execute as_op "npc skin --url https://i.imgur.com/nwUVLKc.png" silent
            - execute as_server "sentinel chaserange 15 --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel addtarget monsters --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel guard <player.name> --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel attackrate 1 --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel realistic --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel safeshot true --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel speed 1.5 --id <entry[soldierID].created_npc.id>"
            - execute as_server "sentinel respawntime -1 --id <entry[soldierID].created_npc.id>"
            - inventory open d:mayor_menu
            - determine cancelled
        - else:
            - if <player.flag[soldier]> > 5:
                - narrate "soldier limit reached for mayor(5)"
                - determine cancelled
            - else:
                - narrate "you dont have enough wheat"
                - determine cancelled
        #soldier creation end

        #create a farmer npc
        on player clicks mayor_hire_farmer in mayor_menu:
        - if  <player.inventory.quantity.material[iron_ingot]> >= 10  && <player.flag[farmer]||0> < 3:
            - take iron_ingot quantity:10
            - narrate "you hired a farmer"
            - create player farmer <player.location.add[0,2,0]> save:farmerID
            - flag player farmer:++
            - assignment set script:farmer_assignment npc:<entry[farmerID].created_npc>
            - adjust <entry[farmerID].created_npc> owner:<player.name>
            - inventory open d:mayor_menu
            - determine cancelled
        - else:
            - if <player.flag[farmer]> > 5:
                - narrate "farmer limit reached for mayor(3)"
                - determine cancelled
            - else:
                - narrate "you dont have enough iron"
                - determine cancelled
        #create farmer end

        #remove the npc the player is talking with
        on player clicks mayor_dismiss in mayor_menu:
        - narrate "goodbye"
        - remove <npc[<player.flag[interact_ID]>]>
        - flag player has_mayor:!
        - inventory close
        - determine cancelled

        on npc death:
        #todo FIX
        - flag <npc.owner> <npc.name>:--
        - note remove as:<npc.id>

        on player left clicks with air:
        - if <player.has_flag[equiping]> && <player.is_sneaking>:
            - execute as_op "npc equip"
            - flag player equiping:!
            - determine cancelled
        - if <player.has_flag[pathing]> && <player.is_sneaking>:
            - execute as_op "npc path"
            - execute as_op "sentinel guard"
            - narrate "the soldier will now guard this area"
            - flag player pathing:!
            - determine cancelled
        ##
        ##
        ##
        #soldier interactions
        ##
        ##
        ##
        on player clicks soldier_equip in soldier_menu:
        - if !( player.flag[equiping] == <player.flag[interact_ID]> ) && !<player.has_flag[pathing]>:
            - execute as_op "npc select <player.flag[interact_ID].as_npc.id>" silent
            - execute as_op "npc equip"
            - narrate "<yellow>Shift left click <green>with an empty hand to exit"
            - flag player equiping:!|:<player.flag[interact_ID]>
            - inventory close
            - determine cancelled
        - else:
            - inventory close
            - wait 8t
            - narrate "already equiping a soldier or assigning waypoints"
            - determine cancelled

        on player clicks soldier_path in soldier_menu:
        - if !( player.flag[pathing] == <player.flag[interact_ID]> ) && !<player.has_flag[pathing]>:
            - execute as_op "npc select <player.flag[interact_ID].as_npc.id>" silent
            - execute as_op "npc path"
            - flag player pathing:!|:<player.flag[interact_ID]>
            - inventory close
            - determine cancelled
        - else:
            - inventory close
            - wait 8t
            - narrate "already assigning waypoints or equiping a soldier"
            - determine cancelled

        on player clicks soldier_guard in soldier_menu:
        - execute as_op "sentinel guard <player.name> --id <player.flag[interact_ID].as_npc.id>"
        - narrate "soldier is now following"
        - determine cancelled
        #remove the npc the player is interacting with
        on player clicks soldier_dismiss in soldier_menu:
        - narrate "goodbye"
        - remove <npc[<player.flag[interact_ID]>]>
        - flag player soldier:--
        - inventory close
        - determine cancelled
        ##
        ##
        ##
        #farmer interactions
        ##
        ##
        on player clicks farmer_area in farmer_menu:
        - narrate "right click corners with an empty hand to mark the area"
        - narrate "shift click with an empty hand to cancel"
        - flag player editing:<player.flag[interact_ID]>
        - flag player farming:1
        - inventory close
        - determine cancelled

        #defining farm area and add to farm cube
        on player right clicks block with air:
        - if <player.flag[farming]> == 1:
            - narrate "corner set at <context.location.xyz.replace[,].with[ ]>"
            - flag player corner1:<context.location>
            - flag player farming:++
            - determine cancelled
        - else:     
            - if <player.flag[farming]> == 2:
                - define new_area:<cuboid[<player.flag[corner1]>|<context.location>]>
                - define area_name:<server.flag[cuboids].map_get[<player.flag[editing]>]>
                - define area_index:<server.flag[cuboids].map_get[<player.flag[editing]>].replace[farm_area_]>
                #check if the player is overwriting a previous region
                - if <[area_name].length> > 3:
                    #overwrites the old cuboid with one at 0.0.0 so it does not intersect with the previous area
                    - note <farmcube.add_member[cuboid[0,0,0,world|0,0,0,world]].at[[area_index]]> as:farmcube
                    #if the new area does not overlap another area replace the old area and add it to the world area
                    - if !<cuboid[farmcube].intersects[new_area]>:
                        - note new_area as:farm_area_[area_index]
                        - note <cuboid[farmcube].add_member[new_area]> as:farmcube
                        #if it overlaps restore the previous area to the farm cube and return an error
                    - else:
                    - narrate "Error: this area overlaps another farm area &nl Restoring previous area &nl right click to select a new are &nl shift left click to cancel"
                    - note <cuboid[farmcube].add_member[<cuboid[[area_name]]>]> as:farmcube
                    #restarts the new area definition
                    - flag player farming:1
                    - determine cancelled
                #else create a new one with the next available index
                - else:
                    - if !<cuboid[farmcube].intersects[new_area]>:
                        #create the farm area and add it to the farm cube and cuboids list
                        - note new_area as:farm_area_<server.flag[index]>
                        #list the npc that the area belongs to and advance the index for the next area
                        - flag server cuboids:->:<player.flag[editing]>/farm_area_<server.flag[index]>
                        - flag server index:++
                        - note <cuboid[farmcube].add_member[new_area]> as:farmcube
                        - narrate "farm area created"
                        - flag player farming:!
                        - determine cancelled
                    - else:
                        #if it overlaps restore the previous area to the farm cube and return an error
                        - narrate "Error: this area overlaps another farm area &nl Restoring previous area &nl right click to select a new are &nl shift left click to cancel"
                        - note <cuboid[farmcube].add_member[<cuboid[<area_name>]>]> as:farmcube
                        - flag player farming:1
                        - determine cancelled
        ##
        ##
        #world events
        ##
        ##
        ##
        on wheat grows in:farmcube:
        - wait 1t
        - if <context.location.material> == <material[wheat[age=7]]>:
        #if the location is contained within a cuboid
            - if <context.location.cuboids.get[2].notable_name||null> == farmcube:
                - adjust <npc[<list[<server.flag[cuboids]>].map_get[<area_id>]>]> add_waypoint:<context.location.center>
                - adjust <npc[<list[<server.flag[cuboids]>].map_get[<area_id>]>]> clear_waypoints
mayor_assignment:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - 1 mayor_interact
soldier_assignment:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - 1 soldier_interact
farmer_assignment:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - 1 farmer_interact
mayor_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                #open the menu and flag the npc as the one being interacted with
                - if <player> == <npc.owner>:
                    - inventory open d:mayor_menu
                    - flag player interact_ID:<npc>
                - else:
                    - narrate "this person does not obey you"
soldier_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                #open the menu if the player owns the npc and flag the npc as the one being interacted with
                - if <player> == <npc.owner>:
                    - inventory open d:soldier_menu
                    - flag player interact_ID:<npc>
                - else:
                    - narrate "this soldier does not obey you"


farmer_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                #open the menu and flag the npc as the one being interacted with
                - if <player> == <npc.owner>:
                    - inventory open d:farmer_menu
                    - flag player interact_ID:<npc.id>
                - else:
                    - narrate "this person does not obey you"
mayor_menu:
    type: inventory
    title: Mayor
    size: 27
    slots:
    - "[mayor_dismiss] [] [] [] [] [] [] [] []"
    - "[] [] [] [mayor_hire_farmer] [mayor_hire_soldier] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
soldier_menu:
    type: inventory
    title: Soldier
    size: 9
    slots:
    - "[soldier_dismiss] [] [] [soldier_equip] [soldier_path] [soldier_guard] [] [] []"
farmer_menu:
    type: inventory
    title: Farmer
    size: 27
    slots:
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [farmer_area] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
mayor_placer:
    type: item
    material: bat_spawn_egg
    display name: Mayor spawner

mayor_hire_soldier:
    type: item
    material: stone_sword
    display name: Hire a soldier for 64 Wheat  (<player.flag[soldier]>/5)
mayor_hire_farmer:
    type: item
    material: stone_hoe
    display name: Hire a farmer for 10 iron ingots
mayor_dismiss:
    type: item
    material: barrier
    display name: Dismiss the mayor
soldier_path:
    type: item
    material: arrow
    display name: set the patrol path
soldier_guard:
    type: item
    material: shield
    display name: guard the player
soldier_equip:
    type: item
    material: iron_chestplate
    display name: equip your soldier
soldier_dismiss:
    type: item
    material: barrier
    display name: Dismiss this soldier
farmer_area:
    type: item
    material: farmland
    display name: set farming area
reset_command:
    type: command
    name: reset
    description: resets variables
    usage: /reset (type)
    tab complete:
    - determine <list[mayor|farms]>
    script:
    - if <context.args.get[1]> == farms:
        - note <cuboid[0,0,0,world|0,0,0,world]> as:farmcube
        - while <server.flag[index]> != 1:
            - flag server index:--
            - note remove as:farm_area_<server.flag[index]>
        - flag server index:1
        - flag server cuboids:!
        - narrate "farms reset"
    if <context.args.get[1]> == mayor:
        - remove <player.flag[has_mayor]>
        - narrate "mayor removed"
        - flag player has_mayor:!