Home Showcase
Welcome to the new Diaspora forums, please let us know if you see anything broken! Notice: Some users may need to reupload their avatars due to an issue during forum setup!

Ship saver and loaders

KatelynKatelyn Registered, Administrator Posts: 171
edited March 2011 in Showcase #1
These nifty chips I just made should help when building ship hulls. The saver saves all the props in a ship every minute when you paste it on your ship. Just set a file name in the code and it will auto-save. Keep in mind entities can not be saved since ent core is not enabled on the server.
@name Ship Saver
@persist Contraption:table
@persist [Con, Pos, Color, Mat, Mod, Ang, Skin]:array
@persist File:string I
    if (first())
    {
        #By Katelyn
       
        ##### EDIT ONLY THIS #####
        Name = "testship"    #  This variable is the name of your save file. You use it to recall it.
        ##### EDIT ONLY THIS #####
       
       
       
        File = "Advduper/" + Name + ".txt"
        timer("save", 100)
    }
    if (clk("save"))
    {
        Con = entity():getConstraints()
        timer("vars", 100)
        print("Saving...")
        I = 1
    }
    if (clk("vars"))
    {
        if (I <= Con:count())
        {
            Pos[I, vector] = Con[I, entity]:pos()
            Color[I, vector4] = Con[I, entity]:getColor4()
            Mat[I, string] = Con[I, entity]:getMaterial()
            Mod[I, string] = Con[I, entity]:model()
            Ang[I, angle] = Con[I, entity]:angles()
            Skin[I, number] = Con[I, entity]:getSkin()
           
            I++
            timer("vars", 25)
        }
        else
        {
            Contraption["pos", array] = Pos
            Contraption["color", array] = Color
            Contraption["mat", array] = Mat
            Contraption["mod", array] = Mod
            Contraption["ang", array] = Ang
            Contraption["skin", array] = Skin
           
            fileWrite(File, glonEncode(Contraption))
            timer("save", 60000)
            print("Saved " + Con:count() + " props.")
        }
    }


Now, that saves your ship, but you're going to need something for loading your ship. This chip will load the file you put in. It will repaste everything back where you were building it originally, with all colors, alphas, materials, skins, and angles the same as before. The constraints will re-weld every prop to the first one spawned, so you will have to re-do any special welds. It's better than losing it all though!
@name Ship Loader
@persist Contraption:table
@persist [Con, Pos, Color, Mat, Mod, Ang, Skin]:array 
@persist File:string I

if (first())
{
    #By Katelyn
    
    Name = "testship" #for loading reasons.
    File = "Advduper/" + Name + ".txt"
    if (fileCanLoad())
    {
        fileLoad(File)
    }
    runOnFile(1)
}
if (fileClk())
{
    if (fileStatus() == _FILE_OK)
    {
        Contraption = glonDecodeTable(fileRead())
        timer("vars", 100)
        Pos = Contraption["pos", array]
        Color = Contraption["color", array]
        Mat = Contraption["mat", array]
        Mod = Contraption["mod", array]
        Ang = Contraption["ang", array]
        Skin = Contraption["skin", array]
        
        I = 1
    }
}
if (clk("vars"))
{
    if (I <= Pos:count())
    {
        Temp = propSpawn(Mod[I, string], Pos[I, vector], Ang[I, angle], 1)
        Temp:setColor(Color[I, vector4])
        Temp:setMaterial(Mat[I, string])
        Temp:setSkin(Skin[I, number])
        
        if (I > 0)
        {
            Temp:weld(Con[1, entity])
        }
        
        Con:pushEntity(Temp)
        I++
        timer("vars", 250)
    }
    else
    {
        print("Finished " + Con:count() + " props spawned.")
        selfDestruct()
    }
}

Comments

  • Mr.Niceguy976Mr.Niceguy976 Registered Posts: 33
    This is pretty nice! I'll use it on my next project :D
    MrNiceguy9765.jpg
    geo.php
  • KatelynKatelyn Registered, Administrator Posts: 171
    I am working on a v2 right now that will save constraints as well.
  • Paper ClipPaper Clip Registered, Moderator, Administrator Posts: 87
    Looking forward to the updated version :) I know there was a cool lua addon design for this as well, where you can quicksave everything of yours on the map by pressing a key.
  • SteeveeoSteeveeo Registered, Administrator Posts: 849
    Katelyn, one thing to keep in mind is that E2 text files are limited to 100KB, so you're going to have to figure out how to optimize that for the larger ships should anything surpass that (especially when dealing with constraints).

    What I would do with the constraints is ignore what's welded to what and just set a parent prop flag in the save file, then weld everything to that (multi-weld style).
  • KatelynKatelyn Registered, Administrator Posts: 171
    It already does that kind of. It treats the first prop spawned as the parent.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file