Jump to content

[Help] Raising Water


BieHDC

Recommended Posts

Hello,

I want to make a script witch raises water to a defined high(example 20m) in a defined time(60secs until water reaches 20m) and the draining should start 15secs after map start

I have found the following as example witch drains water:

-- serverside 
local level = 0 
  
function drainSomeWater() 
    level = level - 0.01 
    setWaterLevel ( level ) 
end 
setTimer ( drainSomeWater, 100, 15000 ) 

if i dont use a negative number the water will raise (i think)

but i want that the water needs 60sec unti have 20m and starts 15secs after map start, but i dont know how to do this.

Please help me^^

Link to comment
  • Moderators

The script is included with the map? or apart?

raising/draining

20 meters

60 sec

20/60 = 0.33333333 per sec

0.33333333 / 10 = 0.033333 per 0.1 sec (100 millisecond)

local level = 0 
local waterState = "raising" 
local runningTimer 
  
function editSomeWater() 
    if waterState == "raising" then 
        level = level + 0.033333 
        setWaterLevel ( level ) 
        if level >= 20 then 
            waterState = "draining"  
            setWaterLevel ( 20 ) 
        end 
    elseif waterState == "draining " then 
        level = level - 0.033333 
        setWaterLevel ( level ) 
        if level <= 0 then 
            waterState = nil --"raising" for repeating 
            setWaterLevel ( 0 ) 
        end 
    elseif isTimer(runningTimer) then 
        killTimer(runningTimer) 
    end 
end 
  
setTimer (function () 
    runningTimer = setTimer ( editSomeWater, 100, 0 ) 
end,15000,1) 

Link to comment
  • Moderators

Must it stay at 20 m?

    local level = 0 
    local runningTimer 
      
    function editSomeWater() 
            level = level + 0.033333 
            setWaterLevel ( level ) 
            if level >= 20 then 
                setWaterLevel ( 20 ) 
                if isTimer(runningTimer) then 
                      killTimer(runningTimer) 
                end 
                runningTimer = nil 
            end 
    end 
      
    setTimer (function () 
        runningTimer = setTimer ( editSomeWater, 100, 0 ) 
    end,15000,1) 

Link to comment

can you make this please with that i can set in directly the highest water level(20) the time to need until 20 (60sec) and the time to start raise and the script would calculate by itself?

If i have to change the numbers, that would be easyer^^

Link to comment
  • Moderators

aha lazy guy. Next time you make your own.

local maxLevel      =   20 -- max level 
local untilW        =   60 -- sec 
  
local raising,level     =   (maxLevel/untilW)/10,0 
untilW = nil 
local runningTimer 
  
  
function editSomeWater() 
    level = level + raising -- level raising 
    setWaterLevel ( level ) -- set the level 
    if level >= maxLevel then -- compare values of level and max level 
        setWaterLevel ( maxLevel ) -- set it back to max level for perfection 
        if isTimer(runningTimer) then -- check if the timer exist 
            killTimer(runningTimer) -- stop the timer  
        end 
        runningTimer,level,maxLevel = nil,nil,nil -- delete data (ram) 
    end 
end 
  
setTimer (function () -- set a timer for 15000 millisec (15 sec), runs one time "1" 
    runningTimer = setTimer ( editSomeWater, 100, 0 ) -- set an invinity timer to set the water level, (0 = invinity) (only stops when you stop him with killTimer)  
end,15000,1) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...