Lua wait function and other scripting fixes