- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





Staff Pick: Npc skin from url


By Mergu
Created: 2018/11/24 21:35:46 UTC-08:00 (5 years and 125 days ago)
Edited: 2019/01/24 23:01:20 UTC-08:00 (5 years and 64 days ago)
Likes: 2

Staff pick as of: 2018/11/24 21:37:10 UTC-08:00 (5 years and 125 days ago)
Denizen Version: 1.0.3
Script Version: 1.2
Description:

Drop this into your scripts folder to add a new --url/-u flag to /npc skin. Supports setting a url skin from both in-game and the console. Optionally specify `slim` on the end if the file is meant for a slim player model.

Usage examples:

/npc skin --url https://i.imgur.com/Pgu9R1s.png

/npc skin --url https://i.imgur.com/6l1i0uB.png slim


The url must point to a valid skin file.


Download script | View raw script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
7800

# Allows a player to set an npc's skin with a url using /npc skin [-u/--url] <url> (slim)
# Just drop this file into the Denizen/scripts folder and you're done!

skin_url_handler:
    type: world
    debug: false
    events:
        on npc command:
            - if <c.args.get[1].to_lowercase||null> != skin:
                - queue clear
            - if !<li@-u|--url.contains[<c.args.get[2].to_lowercase||null>]>:
                - queue clear
            - determine passively fulfilled

            - define url <c.args.get[3]||null>
            - define model <c.args.get[4].to_lowercase||empty>
            - if <c.server>:
                - define npc <server.selected_npc||null>
            - else:
                - define npc <player.selected_npc||null>

            - if <def[npc]> == null:
                - narrate "<&a>You must have an NPC selected to execute that command."
                - queue clear
            - if <def[npc].entity_type> != PLAYER:
                - narrate "<&a>You must have a player-type NPC selected."
                - queue clear
            - if <def[url]> == null:
                - narrate "<&a>You must specify a valid skin URL."
                - queue clear
            - if <def[model]> != empty && <def[model]> != slim:
                - narrate "<&e><def[model]><&a> is not a valid skin model. Must be <&e>slim<&a> or empty."
                - queue clear

            - narrate "<&a>Retrieving the requested skin..."
            - define key <util.random.uuid>

            # Our own custom ~5s timeout since the builtin hangs
            - run skin_url_task def:<def[key]>|<def[url]>|<def[model]> id:<def[key]> instantly
            - while <queue.exists[<def[key]>]>:
                - if <def[loop_index]> > 20:
                    - queue q@<def[key]> clear
                    - narrate "<&a>The request timed out. Is the url valid?"
                    - queue clear
                - wait 5t

            # Quick sanity check - ideally this should never be true
            - if !<server.has_flag[<def[key]>]>:
                - queue clear

            - if <server.flag[<def[key]>]> == null:
                - narrate "<&a>Failed to retrieve the skin from the provided link. Is the url valid?"
                - flag server <def[key]>:!
                - queue clear

            - yaml loadtext:<server.flag[<def[key]>]> id:response

            - if !<yaml[response].contains[data.texture]>:
                - narrate "<&a>An unexpected error occurred while retrieving the skin data. Please try again."
            - else:
                - narrate "<&e><def[npc].name><&a>'s skin set to <&e><def[url]><&a>."
                - adjust <def[npc]> skin_blob:<yaml[response].read[data.texture.value]>;<yaml[response].read[data.texture.signature]>

            - flag server <def[key]>:!
            - yaml unload id:response

skin_url_task:
    type: task
    debug: false
    definitions: key|url|model
    script:
        - define req "https://api.mineskin.org/generate/url"
        - if <def[model]> == slim:
            - define req "<def[req]>?model=slim"
        - ~webget <def[req]> "post:url=<def[url]>" timeout:5s save:res
        - flag server <def[key]>:<entry[res].result||null>






View History