Paste #47196: Redshirt2 BlobTasks

Date: 2018/04/14 00:09:34 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


GetAllBlobs:
    type: task
    speed: 0t
    debug: false
    script:
        # type /ex run GetAllBlobs
        #
        # It creates a Blobs-temp.yml with all blobs from all npcs and players on your server
        # there might be redundancy, and blobs you don't want or need.
        #
        # you will need to manually copy and paste  a blob into Blobs-Saved.yml file

        # Blobs-Saved.yml with have one unique key and the blob. The unique Key may be a real or fake playername. It does not need to be the actual
        # name of the npc or player we got the blob from.  Don't use spaces.  Use underscores if needed...
        # In the ReBlob task, you use the real or fake playername to assign a blob to an NPC.  The task has a fallback to try 
        # using the skin, if the blob is not found


        #load or create file
        - if <server.has_file[/scriptdata/Blobs-temp.yml]> {

            #Load
            - narrate "Blobs-temp.yml already exists"
            - yaml "load:/scriptdata/Blobs-temp.yml" id:Blobfile
            - yaml "savefile:/scriptdata/Blobs-temp.yml" id:Blobfile
            } else {

            #Create
            - yaml create id:Blobfile
            - yaml "savefile:/scriptdata/Blobs-temp.yml" id:Blobfile
            }        

        - foreach <w@Prison.npcs> {
            - if <def[value].entity_type> = player {
                - narrate "Getting blob: <def[value].Name>"
                #save record into file
                - yaml id:Blobfile set <def[value].Name>.ID:<def[value]>
                - yaml id:Blobfile set <def[value].Name>.Name:<def[value].Name>
                #- yaml id:Blobfile set <def[value].Name>.OriginalName:<def[value].flag[OriginalName]>
                - yaml id:Blobfile set <def[value].Name>.Blob:<def[value].skin_blob>
                #- yaml id:Blobfile set <def[value].Name>.Skin:<def[value].skin>
                }
            }

        - foreach <server.list_online_players> {
            - narrate "<def[value].Name>"
            #save record into file
            - yaml id:Blobfile set <def[value].Name>.ID:<def[value]>
            - yaml id:Blobfile set <def[value].Name>.Name:<def[value].Name>
            #- yaml id:Blobfile set <def[value].Name>.OriginalName:<def[value].flag[OriginalName]>
            - yaml id:Blobfile set <def[value].Name>.Blob:<def[value].skin_blob>
            #- yaml id:Blobfile set <def[value].Name>.Skin:<def[value].skin>
            }


        #save and unload file
        - yaml "savefile:/scriptdata/Blobs-temp.yml" id:Blobfile
        - yaml unload id:Blobfile 

ReBlob:
    type: task
    speed: 0t
    debug: true
    definitions: NPC_ID|BlobName
    script:
        # AFTER you have manually created a Blobs-Saved.yml file containing playernames and skin blobs, you can use this task
        # to apply the stored blob
        #
        # Create a new NPC:  /npc create steve
        # Make note of the id number of newly created npc (use /npc to get the number) 
        # This example creates n@0
        # This example will use a blob from the example Blobs-Saved.yml file: Grille
        #
        # Type /ex run ReBlob def:n@0|Grille
        #
        # If the blob can't be found, the task will try to apply the skin with the skin mech




        #load or create file
        - if <server.has_file[/scriptdata/Blobs-Saved.yml]> {

            #Load
            - yaml "load:/scriptdata/Blobs-Saved.yml" id:SavedBlobsFile
            #- yaml "savefile:/scriptdata/Blobs-Saved.yml" id:SavedBlobsFile
            } else {

            #Create
            - yaml create id:SavedBlobsFile
            - yaml "savefile:/scriptdata/Blobs-Saved.yml" id:SavedBlobsFile
            }  

        #blob lookup here, install and flag
        - if <yaml[SavedBlobsFile].read[<def[BlobName]>.Blob]||empty> != empty {
            # found a corresponding blob
             - narrate ">>>> Applying blob to:<def[NPC_ID].name> with blob based on: <def[BlobName]>"
            #saving the blob in a npc tag to refresh later without a yaml lookup
            - flag <def[NPC_ID]> Blob:<yaml[SavedBlobsFile].read[<def[BlobName]>.Blob]>

            #- adjust <def[NPC_ID]> skin:<def[BlobName]>
            - adjust <def[NPC_ID]> skin_blob:<def[NPC_ID].flag[Blob]>


            } else {
            #no blob in file, running trying to apply skin based on the blob name
            - narrate "<yellow>No Blob. Applying skin to:<def[NPC_ID].name> with blob name: <def[BlobName]>"
            #- wait 1t
            - adjust <def[NPC_ID]> skin:<def[BlobName]>
            #- wait 1t
            }

        #save and unload file
        #- yaml "savefile:/scriptdata/Blobs-Saved.yml" id:SavedBlobsFile
        - yaml unload id:SavedBlobsFile