Code: Select all
function gadget:GetInfo()
  return {
    name      = "lava test",
    desc      = "lava that rise",
    author    = "knorke + some edit by zwzsg",
    date      = "Feb 2011, 2011",
    license   = "weeeeeee iam on horse",
    layer     = 0,
    enabled   = true
  }
end
if (gadgetHandler:IsSyncedCode()) then
    function gadget:GameFrame(frame)
        local LavaLevel
        -- Calculate Lava Level
        MapYmin,MapYmax=Spring.GetGroundExtremes()
        LavaLevel = MapYmax-(MapYmax-MapYmin)*math.abs((frame/1800)%2-1)
        -- Damage units in lava
        if frame%10==9 then
            for i,u in pairs(Spring.GetAllUnits()) do
                x,y,z = Spring.GetUnitPosition(u)
                if (y and y < LavaLevel+10) then 
                    Spring.AddUnitDamage (u, 25) 
                    Spring.SpawnCEG("BURN", x, y, z, 0,1,0)
                end
            end
        end
        -- Random FX in lava
        local x,z=math.random(0,Game.mapSizeX),math.random(0,Game.mapSizeZ)
        if Spring.GetGroundHeight(x,z)< LavaLevel then
            Spring.SpawnCEG("BURN", x, LavaLevel, z, 0,1,0)
        end
        -- Pass to unsynced
        _G.LavaLevel = LavaLevel
    end
else --- UNSYNCED:
    local DrawWorldTimer = nil
    function DrawQuadVertices(x1,z1,x2,z2,y,TextureSize)
      -- Where y the the lava plane position
      -- Where TextureSize is the size of texture pattern, in elmos
      gl.TexCoord(0,0) 
      gl.Vertex(x1,y,z1)
      gl.TexCoord((x2-x1)/TextureSize,0)
      gl.Vertex(x2,y,z1)
      gl.TexCoord((x2-x1)/TextureSize,(z2-z1)/TextureSize)
      gl.Vertex(x2,y,z2)
      gl.TexCoord(0,(z2-z1)/TextureSize) 
      gl.Vertex(x1,y,z2)
    end
    function DrawLavaSquare(LavaLevel)
        DrawWorldTimer=DrawWorldTimer or Spring.GetTimer()
        local cm1=(math.abs(((Spring.DiffTimers(Spring.GetTimer(),DrawWorldTimer)/0.78)%2)-1)^2)*0.5
        local cm2=(math.abs(((Spring.DiffTimers(Spring.GetTimer(),DrawWorldTimer)/1.13)%2)-1)^2)*0.5
        local cm3=math.abs(((Spring.DiffTimers(Spring.GetTimer(),DrawWorldTimer)/2.87)%2)-1)
        gl.PushAttrib(GL.ALL_ATTRIB_BITS)
        gl.DepthTest(true)
        gl.DepthMask(true)
        gl.Texture(":a:LuaRules/Gadgets/lava.png")-- Texture file
        gl.Color(1-cm1,1-cm1-cm2,0.5,1)
        gl.BeginEnd(GL.QUADS,DrawQuadVertices,0,0,Game.mapSizeX,Game.mapSizeZ,LavaLevel,64)
        gl.Texture(false)
        gl.DepthMask(false)
        gl.DepthTest(false)
        gl.Color(1,1,1,1)
        gl.PopAttrib()
    end
    function gadget:DrawWorld()
        if (SYNCED.LavaLevel) then
            DrawLavaSquare(SYNCED.LavaLevel)
        end
    end
end--end unsync