Code: Select all
-- $Id: snd_noises.lua 3171 2008-11-06 09:06:29Z det $
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: tests I need to run
-- brief: will be my holly grail of lua scripting
--
-- Copyright (C) 2007.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "tests",
desc = "me messing around",
author = "voidranaut",
date = "blaaa",
license = "GNU GPL, v2 or later",
layer = -10,
enabled = true -- loaded by default?
}
end
local PlaySoundFile = Spring.PlaySoundFile
local GSU = Spring.GetSelectedUnits
local echo = Spring.Echo
local lastbuilt = {}
local cost = 100
local sound_dir = 'Sounds/'
--local path = sound_dir..filename..".WAV"
local timer = Spring.GetGameSeconds
local time = timer()
local lastPlayed = 0
function widget:CommandNotify(cmdID)
local unitID = Spring.GetSelectedUnits()[1]
if(not unitID) then
echo( "oops" )
return
end
local defID = Spring.GetUnitDefID(unitID)
local Nature = UnitDefs[ defID ]["customParams"]["merciless"]
if( "1" == Nature ) then
local rand = math.random(1,1)
if( rand == 1) then
echo( time )
echo( lastplayed )
if ( (time - lastPlayed) >= 10 ) then
Spring.PlaySoundFile("sounds/Regis_ultamate_fight_full.wav")
lastPlayed = time
end
end
end
end
Probleam: the echo command echo( time ) gives back 0 every time and echo( lastplayed ) gives back nil...now this segjests that My primary probleam is I missinterprited what exactly Spring.GetGameSeconds does
Question: is there a way I can get the current time in seconds that have passed since the game began? and if I did get that value would I be able to use it as I intended Spring.GetGameSeconds to be used in the script above? or am I barking up the wrong tree?
oh one more thing.. I have been making alot of threads over the last few days and I dont want to clutter the forum ... is it ok that I have been making so many? or is there a better way for me to post that would be less annoying then seeing threads started by voidranaut everywere? any feed back is welcome
thank you for your time