-- LUA Script - precede every function and global member with lowercase name of script -- My save game script, version 1.0 (modified from Moshroom's script) -- This script saves certain stats at end of each level so it can be loaded into next level -- Saved Stats are player health and lives, cash, weapons collected and a mobcount variable -- you will need to initialize the mobcount as a global variable and add a mobcount = mobcount + 1 -- to the mob scripts you use at the end when the mob is killed also add a cash global variable for -- any money collected there is also a fourth saved variable for other use - haven't figured out ammo -- or weapons already owned but not collected this level -- Modify for each level end to show activeslot for that level - supports up to 10 level game -- This is first level script -- init when level first runs function save_to_zone1_init(e) activeSlot = 0 end function save_to_zone1_main(e) if g_Entity[e]['plrinzone']==1 then g_First = cash g_Third = mobcount g_Fourth = g_PlayerGunCount activeSlot = 1 -- Phase 2 = Open file and write -- If (and only if) global placeholder variables return nil, define them as 0 if g_First == nil then g_First = 0 end for i = 1,10 do if g_Second[i] == nil then g_Second[i] = 0 end end if g_Third == nil then g_Third = 0 end if g_Fourth == nil then g_Fourth = 0 end -- Create local variable file and link it to slotX.dat local file = io.open("slot" .. activeSlot .. ".dat", "w") -- Write player data and custom variables to file file:write( g_PlayerHealth .. "\n" .. g_PlayerLives .. "\n" .. g_First .. "\n") for i = 1,10 do file:write(g_Second[i] .. "\n") end file:write( g_Third .. "\n" .. g_Fourth .. "\n") -- Save file to disk file:close() JumpToLevelIfUsed(e) end end