Index: /code/branches/script_trigger/bin/levels/sample.oxw
===================================================================
--- /code/branches/script_trigger/bin/levels/sample.oxw	(revision 1850)
+++ /code/branches/script_trigger/bin/levels/sample.oxw	(revision 1851)
@@ -38,5 +38,5 @@
 <Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" /-->
 
-<DistanceTrigger position="100,0,0" scale="2" distance="80" delay="10.0" target="SpaceShip"/>
+<DistanceTrigger position="100,0,0" scale="2" distance="80" activations="2" target="SpaceShip"/>
 
 
Index: /code/branches/script_trigger/src/core/LuaBind.cc
===================================================================
--- /code/branches/script_trigger/src/core/LuaBind.cc	(revision 1851)
+++ /code/branches/script_trigger/src/core/LuaBind.cc	(revision 1851)
@@ -0,0 +1,313 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "LuaBind.h"
+
+#include <fstream>
+#include <map>
+
+#include "CoreIncludes.h"
+
+extern "C" {
+#include <lualib.h>
+#include <lauxlib.h>
+}
+
+#include "tolua++.h"
+#include "tolua/tolua_bind.h"
+
+namespace orxonox
+{
+  LuaBind* LuaBind::singletonRef = NULL;
+
+  LuaBind::LuaBind()
+  {
+    luaState_ = lua_open();
+    luaSource_ = "";
+#if LUA_VERSION_NUM == 501
+    luaL_openlibs(luaState_);
+#else
+    luaopen_base(luaState_);
+    luaopen_string(luaState_);
+    luaopen_table(luaState_);
+    luaopen_math(luaState_);
+    luaopen_io(luaState_);
+    luaopen_debug(luaState_);
+#endif
+    tolua_core_open(luaState_);
+    output_ = "";
+    isRunning_ = false;
+  }
+
+  void LuaBind::luaPrint(std::string str)
+  {
+    output_ += str;
+    COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
+  }
+
+  /**
+      @brief Loads the specified file line by line
+      @param filename The filename of the file
+      @param luaTags if true, the loaded file gets stripped off luaTags
+  */
+  void LuaBind::loadFile(std::string filename, bool luaTags)
+  {
+    output_ = "";
+    std::ifstream file;
+    file.open(filename.c_str(), std::fstream::in);
+
+    if (!file.is_open())
+    {
+      // some error msg
+    }
+
+    char line[1024];
+    std::string levelString = "";
+
+    while (file.good() && !file.eof())
+    {
+      file.getline(line, 1024);
+      levelString += line;
+      levelString += "\n";
+    }
+
+    file.close();
+    //std::string output;
+
+    if (luaTags) luaSource_ = replaceLuaTags(levelString);
+    COUT(4) << "ParsedSourceCode: " << luaSource_ << std::endl;
+  }
+
+  void LuaBind::loadString(std::string code)
+  {
+    luaSource_ = code;
+    output_ = "";
+  }
+
+#if LUA_VERSION_NUM != 501
+  const char * LuaBind::lua_Chunkreader(lua_State *L, void *data, size_t *size)
+  {
+    LoadS* ls = ((LoadS*)data);
+    if (ls->size == 0) return NULL;
+    *size = ls->size;
+    ls->size = 0;
+    return ls->s;
+  }
+#endif
+  void LuaBind::run()
+  {
+    if (!isRunning_)
+    {
+      isRunning_ = true;
+      int error = 0;
+      std::string init = "local scr = orxonox.LuaBind:getInstance()\nlocal debug = print\nprint = function(s)\nscr:luaPrint(s)\nend\ninclude = function(f)\nfile = io.open(f)\ncontent = file:read(\"*a\")\nfile:close()\nsource = scr:replaceLuaTags(content)\ndebug(source)\nassert(loadstring(source))()\nend\n";
+      init += luaSource_;
+  #if LUA_VERSION_NUM == 501
+      error = luaL_loadstring(luaState_, init.c_str());
+  #else
+      LoadS ls;
+      ls.s = init.c_str();
+      ls.size = init.size();
+      error = lua_load(luaState_, &orxonox::LuaBind::lua_Chunkreader, &ls, init.c_str());
+  #endif
+      if (error == 0)
+      {
+        error = lua_pcall(luaState_, 0, 0, 0);
+      }
+      if (error != 0)
+      {
+        COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
+      }
+      isRunning_ = false;
+    }
+    else
+    {
+      COUT(2) << "Warning: Lua's run is called while running!" << std::endl;
+    }
+  }
+
+  unsigned int LuaBind::getNextQuote(const std::string& text, unsigned int start)
+  {
+    unsigned int quote = start - 1;
+
+    while ((quote = text.find('\"', quote + 1)) != std::string::npos)
+    {
+      unsigned int backslash = quote;
+      unsigned int numbackslashes = 0;
+      for (; backslash > 0; backslash--, numbackslashes++)
+        if (text[backslash - 1] != '\\')
+          break;
+
+      if (numbackslashes % 2 == 0)
+        break;
+    }
+
+    return quote;
+  }
+
+  std::string LuaBind::replaceLuaTags(const std::string& text)
+  {
+    // chreate map with all Lua tags
+    std::map<unsigned int, bool> luaTags;
+    {
+      unsigned int pos = 0;
+      while ((pos = text.find("<?lua", pos)) != std::string::npos)
+        luaTags[pos++] = true;
+    }
+    {
+      unsigned int pos = 0;
+      while ((pos = text.find("?>", pos)) != std::string::npos)
+        luaTags[pos++] = false;
+    }
+
+    // erase all tags from the map that are between two quotes
+    {
+      std::map<unsigned int, bool>::iterator it = luaTags.begin();
+      std::map<unsigned int, bool>::iterator it2 = it;
+      bool bBetweenQuotes = false;
+      unsigned int pos = 0;
+      while ((pos = getNextQuote(text, pos)) != std::string::npos)
+      {
+        while ((it != luaTags.end()) && (it->first < pos))
+        {
+          if (bBetweenQuotes) {
+            it2++;
+            if(it->second && !(it2->second) && it2->first < pos)
+              it = ++it2;
+            else
+              luaTags.erase(it++);
+          }
+          else
+            ++it;
+        }
+        bBetweenQuotes = !bBetweenQuotes;
+        pos++;
+      }
+    }
+
+    // check whether on every opening <?lua tag a closing ?> tag follows
+    {
+      bool expectedValue = true;
+      for (std::map<unsigned int, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
+      {
+        if ((*it).second == expectedValue)
+          expectedValue = !expectedValue;
+        else
+        {
+          expectedValue = false;
+          break;
+        }
+      }
+      if (!expectedValue) {
+        COUT(2) << "Warning: Error in level file" << std::endl;
+        // todo: errorhandling
+        return "";
+      }
+    }
+
+    // cut the original string into pieces and put them together with print() instead of lua tags
+    std::string output;
+    {
+      std::map<unsigned int, bool>::iterator it = luaTags.begin();
+      bool bInPrintFunction = true;
+      unsigned int start = 0;
+      unsigned int end = 0;
+
+      do
+      {
+        if (it != luaTags.end())
+          end = (*(it++)).first;
+        else
+          end = std::string::npos;
+
+        unsigned int equalSignCounter = 0;
+
+        if (bInPrintFunction)
+        {
+          // count ['='[ and ]'='] and replace tags with print([[ and ]])
+          std::string temp = text.substr(start, end - start);
+          {
+            unsigned int pos = 0;
+            while ((pos = temp.find('[', pos)) != std::string::npos)
+            {
+              unsigned int tempCounter = 1;
+              unsigned int tempPos = pos++;
+              while(temp[++tempPos] == '=') {
+                tempCounter++;
+              }
+              if(temp[tempPos] != '[') {
+                tempCounter = 0;
+              }
+              else if(tempCounter == 0) {
+                tempCounter = 1;
+              }
+              if (tempCounter > equalSignCounter)
+                equalSignCounter = tempCounter;
+            }
+          }
+          {
+            unsigned int pos = 0;
+            while ((pos = temp.find(']', pos)) != std::string::npos)
+            {
+              unsigned int tempCounter = 1;
+              unsigned int tempPos = pos++;
+              while(temp[++tempPos] == '=') {
+                tempCounter++;
+              }
+              if(temp[tempPos] != ']') {
+                tempCounter = 0;
+              }
+              else if(tempCounter == 0) {
+                tempCounter = 1;
+              }
+              if (tempCounter > equalSignCounter)
+                equalSignCounter = tempCounter;
+            }
+          }
+          std::string equalSigns = "";
+          for(unsigned int i = 0; i < equalSignCounter; i++) {
+            equalSigns += "=";
+          }
+          output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
+          start = end + 5;
+        }
+        else
+        {
+          output += text.substr(start, end - start);
+          start = end + 2;
+        }
+
+        bInPrintFunction = !bInPrintFunction;
+      }
+      while (end != std::string::npos);
+    }
+
+    return output;
+  }
+
+}
Index: /code/branches/script_trigger/src/core/LuaBind.h
===================================================================
--- /code/branches/script_trigger/src/core/LuaBind.h	(revision 1851)
+++ /code/branches/script_trigger/src/core/LuaBind.h	(revision 1851)
@@ -0,0 +1,90 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+ @file  LuaBind.h
+ @brief Representation of an interface to lua
+ @author Benjamin Knecht <beni_at_orxonox.net>
+ */
+
+#ifndef _LuaBind_H__
+#define _LuaBind_H__
+
+#include "CorePrereqs.h"
+
+extern "C" {
+#include <lua.h>
+}
+
+#include <list>
+#include <string>
+
+namespace orxonox // tolua_export
+{ // tolua_export
+
+  class _CoreExport LuaBind // tolua_export
+  { // tolua_export
+    struct LoadS {
+      const char *s;
+      size_t size;
+    };
+
+    public:
+      inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
+      inline ~LuaBind() { LuaBind::singletonRef = NULL; };
+
+    void loadFile(std::string filename, bool luaTags);
+    void loadString(std::string code);
+    //void init(lua_State *state_);
+    //void xmlToLua();
+    void run();
+    void luaPrint(std::string str); // tolua_export
+
+#if LUA_VERSION_NUM != 501
+    static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
+#endif
+
+    inline lua_State* getLuaState() { return luaState_; };
+    inline std::string getLuaOutput() { return output_; };
+    //inline std::string* getFileString() { return &fileString_; };
+
+    unsigned int getNextQuote(const std::string& text, unsigned int start);
+    std::string replaceLuaTags(const std::string& text); // tolua_export
+
+    private:
+      LuaBind();
+      static LuaBind* singletonRef;
+
+      std::string luaSource_;
+      std::string output_;
+      lua_State* luaState_;
+      bool isRunning_;
+
+  }; // tolua_export
+} // tolua_export
+#endif /* _LuaBind_H__ */
Index: /code/branches/script_trigger/src/core/LuaBind_clean.h
===================================================================
--- /code/branches/script_trigger/src/core/LuaBind_clean.h	(revision 1851)
+++ /code/branches/script_trigger/src/core/LuaBind_clean.h	(revision 1851)
@@ -0,0 +1,85 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+ @file  LuaBind.h
+ @brief Representation of an interface to lua
+ @author Benjamin Knecht <beni_at_orxonox.net>
+ */
+
+#ifndef _LuaBind_H__
+#define _LuaBind_H__
+
+#include "CorePrereqs.h"
+
+extern "C" {
+#include <lua.h>
+}
+
+#include <list>
+#include <string>
+
+namespace orxonox // tolua_export
+{ // tolua_export
+
+  class  LuaBind // tolua_export
+  { // tolua_export
+    public:
+      inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
+      inline ~LuaBind() { LuaBind::singletonRef = NULL; };
+
+    void loadFile(std::string filename, bool luaTags);
+    void loadString(std::string code);
+    //void init(lua_State *state_);
+    //void xmlToLua();
+    void run();
+    void luaPrint(std::string str); // tolua_export
+
+#if LUA_VERSION_NUM != 501
+    inline static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size) { return NULL;};
+#endif
+
+    inline lua_State* getLuaState() { return luaState_; };
+    inline std::string getLuaOutput() { return output_; };
+    //inline std::string* getFileString() { return &fileString_; };
+
+    unsigned int getNextQuote(const std::string& text, unsigned int start);
+    std::string replaceLuaTags(const std::string& text); // tolua_export
+
+    private:
+      LuaBind();
+      static LuaBind* singletonRef;
+
+      std::string luaSource_;
+      std::string output_;
+      lua_State* luaState_;
+      bool isRunning_;
+
+  }; // tolua_export
+} // tolua_export
+#endif /* _LuaBind_H__ */
Index: de/branches/script_trigger/src/core/Script.cc
===================================================================
--- /code/branches/script_trigger/src/core/Script.cc	(revision 1850)
+++ 	(revision )
@@ -1,290 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-#include "Script.h"
-
-#include <fstream>
-#include <map>
-
-#include "CoreIncludes.h"
-
-extern "C" {
-#include <lualib.h>
-#include <lauxlib.h>
-}
-
-#include "tolua++.h"
-#include "tolua/tolua_bind.h"
-
-namespace orxonox
-{
-  Script* Script::singletonRef = NULL;
-
-  Script::Script()
-  {
-    luaState_ = lua_open();
-    luaSource_ = "";
-#if LUA_VERSION_NUM == 501
-    luaL_openlibs(luaState_);
-#else
-    luaopen_base(luaState_);
-    luaopen_string(luaState_);
-    luaopen_table(luaState_);
-    luaopen_math(luaState_);
-    luaopen_io(luaState_);
-    luaopen_debug(luaState_);
-#endif
-    tolua_core_open(luaState_);
-    output_ = "";
-  }
-
-  void Script::luaPrint(std::string str)
-  {
-    output_ += str;
-    COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
-  }
-
-  /**
-      @brief Loads the specified file line by line
-      @param filename The filename of the file
-      @param luaTags if true, the loaded file gets stripped off luaTags
-  */
-  void Script::loadFile(std::string filename, bool luaTags)
-  {
-    std::ifstream file;
-    file.open(filename.c_str(), std::fstream::in);
-
-    if (!file.is_open())
-    {
-      // some error msg
-    }
-
-    char line[1024];
-    std::string levelString = "";
-
-    while (file.good() && !file.eof())
-    {
-      file.getline(line, 1024);
-      levelString += line;
-      levelString += "\n";
-    }
-
-    file.close();
-    //std::string output;
-
-    if (luaTags) luaSource_ = replaceLuaTags(levelString);
-    COUT(4) << "ParsedSourceCode: " << luaSource_ << std::endl;
-  }
-
-#if LUA_VERSION_NUM != 501
-  const char * Script::lua_Chunkreader(lua_State *L, void *data, size_t *size)
-  {
-    LoadS* ls = ((LoadS*)data);
-    if (ls->size == 0) return NULL;
-    *size = ls->size;
-    ls->size = 0;
-    return ls->s;
-  }
-#endif
-  void Script::run()
-  {
-    int error = 0;
-    std::string init = "local scr = orxonox.Script:getInstance()\nprint = function(s)\nscr:luaPrint(s)\nend\n";
-    init += luaSource_;
-#if LUA_VERSION_NUM == 501
-    error = luaL_loadstring(luaState_, init.c_str());
-#else
-    LoadS ls;
-    ls.s = init.c_str();
-    ls.size = init.size();
-    error = lua_load(luaState_, &orxonox::Script::lua_Chunkreader, &ls, init.c_str());
-#endif
-    if (error == 0)
-      error = lua_pcall(luaState_, 0, 0, 0);
-    if (error != 0) COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
-  }
-
-  unsigned int Script::getNextQuote(const std::string& text, unsigned int start)
-  {
-    unsigned int quote = start - 1;
-
-    while ((quote = text.find('\"', quote + 1)) != std::string::npos)
-    {
-      unsigned int backslash = quote;
-      unsigned int numbackslashes = 0;
-      for (; backslash > 0; backslash--, numbackslashes++)
-        if (text[backslash - 1] != '\\')
-          break;
-
-      if (numbackslashes % 2 == 0)
-        break;
-    }
-
-    return quote;
-  }
-
-  std::string Script::replaceLuaTags(const std::string& text)
-  {
-    // chreate map with all Lua tags
-    std::map<unsigned int, bool> luaTags;
-    {
-      unsigned int pos = 0;
-      while ((pos = text.find("<?lua", pos)) != std::string::npos)
-        luaTags[pos++] = true;
-    }
-    {
-      unsigned int pos = 0;
-      while ((pos = text.find("?>", pos)) != std::string::npos)
-        luaTags[pos++] = false;
-    }
-
-    // erase all tags from the map that are between two quotes
-    {
-      std::map<unsigned int, bool>::iterator it = luaTags.begin();
-      std::map<unsigned int, bool>::iterator it2 = it;
-      bool bBetweenQuotes = false;
-      unsigned int pos = 0;
-      while ((pos = getNextQuote(text, pos)) != std::string::npos)
-      {
-        while ((it != luaTags.end()) && (it->first < pos))
-        {
-          if (bBetweenQuotes) {
-            it2++;
-            if(it->second && !(it2->second) && it2->first < pos)
-              it = ++it2;
-            else
-              luaTags.erase(it++);
-          }
-          else
-            ++it;
-        }
-        bBetweenQuotes = !bBetweenQuotes;
-        pos++;
-      }
-    }
-
-    // check whether on every opening <?lua tag a closing ?> tag follows
-    {
-      bool expectedValue = true;
-      for (std::map<unsigned int, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
-      {
-        if ((*it).second == expectedValue)
-          expectedValue = !expectedValue;
-        else
-        {
-          expectedValue = false;
-          break;
-        }
-      }
-      if (!expectedValue) {
-        // todo: errorhandling
-        return "";
-      }
-    }
-
-    // cut the original string into pieces and put them together with print() instead of lua tags
-    std::string output;
-    {
-      std::map<unsigned int, bool>::iterator it = luaTags.begin();
-      bool bInPrintFunction = true;
-      unsigned int start = 0;
-      unsigned int end = 0;
-
-      do
-      {
-        if (it != luaTags.end())
-          end = (*(it++)).first;
-        else
-          end = std::string::npos;
-
-        unsigned int equalSignCounter = 0;
-
-        if (bInPrintFunction)
-        {
-          // count ['='[ and ]'='] and replace tags with print([[ and ]])
-          std::string temp = text.substr(start, end - start);
-          {
-            unsigned int pos = 0;
-            while ((pos = temp.find('[', pos)) != std::string::npos)
-            {
-              unsigned int tempCounter = 1;
-              unsigned int tempPos = pos++;
-              while(temp[++tempPos] == '=') {
-                tempCounter++;
-              }
-              if(temp[tempPos] != '[') {
-                tempCounter = 0;
-              }
-              else if(tempCounter == 0) {
-                tempCounter = 1;
-              }
-              if (tempCounter > equalSignCounter)
-                equalSignCounter = tempCounter;
-            }
-          }
-          {
-            unsigned int pos = 0;
-            while ((pos = temp.find(']', pos)) != std::string::npos)
-            {
-              unsigned int tempCounter = 1;
-              unsigned int tempPos = pos++;
-              while(temp[++tempPos] == '=') {
-                tempCounter++;
-              }
-              if(temp[tempPos] != ']') {
-                tempCounter = 0;
-              }
-              else if(tempCounter == 0) {
-                tempCounter = 1;
-              }
-              if (tempCounter > equalSignCounter)
-                equalSignCounter = tempCounter;
-            }
-          }
-          std::string equalSigns = "";
-          for(unsigned int i = 0; i < equalSignCounter; i++) {
-            equalSigns += "=";
-          }
-          output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
-          start = end + 5;
-        }
-        else
-        {
-          output += text.substr(start, end - start);
-          start = end + 2;
-        }
-
-        bInPrintFunction = !bInPrintFunction;
-      }
-      while (end != std::string::npos);
-    }
-
-    return output;
-  }
-
-}
Index: de/branches/script_trigger/src/core/Script.h
===================================================================
--- /code/branches/script_trigger/src/core/Script.h	(revision 1850)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-/**
- @file  script.h
- @brief Representation of an interface to lua
- @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _Script_H__
-#define _Script_H__
-
-#include "CorePrereqs.h"
-
-extern "C" {
-#include <lua.h>
-}
-
-#include <list>
-#include <string>
-
-namespace orxonox // tolua_export
-{ // tolua_export
-
-  class _CoreExport Script // tolua_export
-  { // tolua_export
-    struct LoadS {
-      const char *s;
-      size_t size;
-    };
-
-    public:
-      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export
-      inline ~Script() { Script::singletonRef = NULL; };
-
-    void loadFile(std::string filename, bool luaTags);
-    //void init(lua_State *state_);
-    //void xmlToLua();
-    void run();
-    void luaPrint(std::string str); // tolua_export
-
-#if LUA_VERSION_NUM != 501
-    static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
-#endif
-
-    inline lua_State* getLuaState() { return luaState_; };
-    inline std::string getLuaOutput() { return output_; };
-    //inline std::string* getFileString() { return &fileString_; };
-
-    unsigned int getNextQuote(const std::string& text, unsigned int start);
-    std::string replaceLuaTags(const std::string& text);
-
-    private:
-      Script();
-      static Script* singletonRef;
-
-      std::string luaSource_;
-      std::string output_;
-      lua_State* luaState_;
-
-  }; // tolua_export
-} // tolua_export
-#endif /* _Script_H__ */
Index: de/branches/script_trigger/src/core/Script_clean.h
===================================================================
--- /code/branches/script_trigger/src/core/Script_clean.h	(revision 1850)
+++ 	(revision )
@@ -1,83 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-/**
- @file  script.h
- @brief Representation of an interface to lua
- @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _Script_H__
-#define _Script_H__
-
-#include "CorePrereqs.h"
-
-extern "C" {
-#include <lua.h>
-}
-
-#include <list>
-#include <string>
-
-namespace orxonox // tolua_export
-{ // tolua_export
-
-  class  Script // tolua_export
-  { // tolua_export
-    public:
-      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export
-      inline ~Script() { Script::singletonRef = NULL; };
-
-    void loadFile(std::string filename, bool luaTags);
-    //void init(lua_State *state_);
-    //void xmlToLua();
-    void run();
-    void luaPrint(std::string str); // tolua_export
-
-#if LUA_VERSION_NUM != 501
-    inline static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size) { return NULL;};
-#endif
-
-    inline lua_State* getLuaState() { return luaState_; };
-    inline std::string getLuaOutput() { return output_; };
-    //inline std::string* getFileString() { return &fileString_; };
-
-    unsigned int getNextQuote(const std::string& text, unsigned int start);
-    std::string replaceLuaTags(const std::string& text);
-
-    private:
-      Script();
-      static Script* singletonRef;
-
-      std::string luaSource_;
-      std::string output_;
-      lua_State* luaState_;
-
-  }; // tolua_export
-} // tolua_export
-#endif /* _Script_H__ */
Index: /code/branches/script_trigger/src/orxonox/objects/DistanceTrigger.h
===================================================================
--- /code/branches/script_trigger/src/orxonox/objects/DistanceTrigger.h	(revision 1850)
+++ /code/branches/script_trigger/src/orxonox/objects/DistanceTrigger.h	(revision 1851)
@@ -52,6 +52,8 @@
       void setDistance(float dist);
       virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+      bool checkDistance();
+
+    protected:
       bool isTriggered(TriggerMode mode);
-      bool checkDistance();
 
     private:
Index: /code/branches/script_trigger/src/orxonox/objects/Trigger.cc
===================================================================
--- /code/branches/script_trigger/src/orxonox/objects/Trigger.cc	(revision 1850)
+++ /code/branches/script_trigger/src/orxonox/objects/Trigger.cc	(revision 1851)
@@ -53,4 +53,7 @@
     bTriggered_ = false;
     bUpdating_ = false;
+    remainingActivations_ = -1;
+    bStayTriggered_ = false;
+    latestState_ = 0x0;
 
     debugBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
@@ -79,29 +82,26 @@
   {
 
-    bool newTriggered = this->isTriggered();
-
-
-    // check if new triggering event is really new
-    if(this->latestState_ % 2 != newTriggered)
-    {
-      // create new state
-      if(newTriggered)
+    bool newTriggered;
+    if (latestState_ % 2 == 1 && this->bStayTriggered_)
+      newTriggered = true;
+    else
+      newTriggered = this->isTriggered();
+
+
+      // check if new triggering event is really new
+      if(this->latestState_ % 2 != newTriggered)
       {
-        latestState_ |= 0x1; // set trigger bit
-        latestState_ ^= 0x10; // toggle state bit
+        // create new state
+        if(newTriggered)
+        {
+          latestState_ |= 1; // set trigger bit
+          this->switchState();
+        }
+        else
+        {
+          latestState_ &= 0xFE; // set trigger bit
+          this->storeState();
+        }
       }
-      else
-      {
-        latestState_ &= 0x11111110; // set trigger bit
-      }
-
-      // put state change into queue
-      this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_));
-      // reset time since last event
-      timeSinceLastEvent_ = 0.0;
-
-      if(this->stateChanges_.size() == 1)
-        remainingTime_ = stateChanges_.front().first;
-    }
 
     if(remainingTime_ > 0.0)
@@ -118,5 +118,5 @@
       char newState = stateChanges_.front().second;
       bTriggered_ = newState % 2;
-      bActive_ = newState>>1 % 2;
+      bActive_ = newState & 2;
       this->stateChanges_.pop();
       if(stateChanges_.size() != 0)
@@ -144,4 +144,15 @@
   }
 
+  void Trigger::storeState()
+  {
+    // put state change into queue
+    this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_));
+    // reset time since last event
+    timeSinceLastEvent_ = 0.0;
+
+    if(this->stateChanges_.size() == 1)
+      remainingTime_ = stateChanges_.front().first;
+  }
+
   bool Trigger::isTriggered(TriggerMode mode)
   {
@@ -186,4 +197,6 @@
 
     XMLPortParamLoadOnly(Trigger, "delay", setDelay, xmlelement, mode);
+    XMLPortParamLoadOnly(Trigger, "stayTriggered", setStayTriggered, xmlelement, mode);
+    XMLPortParamLoadOnly(Trigger, "activations", setActivations, xmlelement, mode);
 
     this->init();
@@ -198,12 +211,14 @@
   bool Trigger::switchState()
   {
-    latestState_ ^= 0x10; // toggle state bit
-    // put state change into queue
-    this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_));
-    // reset time since last event
-    timeSinceLastEvent_ = 0.0;
-
-    if(this->stateChanges_.size() == 1)
-      remainingTime_ = stateChanges_.front().first;
+    if ( remainingActivations_ == -1 || this->latestState_ & 2 || remainingActivations_ > 0)
+    {
+      this->latestState_ ^= 2; // toggle state bit
+      // increase activation count
+      if (this->latestState_ & 2) remainingActivations_--;
+      this->storeState();
+
+      return true;
+    }
+    return false;
   }
 
@@ -214,5 +229,5 @@
     for(it = this->children_.begin(); it != this->children_.end(); it++)
     {
-      if(!((*it)->isTriggered()))
+      if(!((*it)->isActive()))
         return false;
     }
@@ -225,5 +240,5 @@
     for(it = this->children_.begin(); it != this->children_.end(); it++)
     {
-      if((*it)->isTriggered())
+      if((*it)->isActive())
         return true;
     }
@@ -237,7 +252,7 @@
     for(it = this->children_.begin(); it != this->children_.end(); it++)
     {
-      if(test && (*it)->isTriggered())
+      if(test && (*it)->isActive())
         return false;
-      if((*it)->isTriggered())
+      if((*it)->isActive())
         test = true;
     }
Index: /code/branches/script_trigger/src/orxonox/objects/Trigger.h
===================================================================
--- /code/branches/script_trigger/src/orxonox/objects/Trigger.h	(revision 1850)
+++ /code/branches/script_trigger/src/orxonox/objects/Trigger.h	(revision 1851)
@@ -54,6 +54,5 @@
       ~Trigger();
 
-      inline bool isTriggered() { return this->isTriggered(this->mode_); }
-      virtual bool isTriggered(TriggerMode mode);
+      inline bool isActive() { return bActive_; }
       void addTrigger(Trigger* trig);
       void setVisibility(bool bVisible);
@@ -63,4 +62,6 @@
       inline TriggerMode getMode() { return mode_; }
       inline void setMode(TriggerMode mode) { this->mode_ = mode; }
+      inline void setStayTriggered(float stayTriggered) { if (stayTriggered == 1.0) this->bStayTriggered_ = true; else this->bStayTriggered_ = false; }
+      inline void setActivations(int activations) { this->remainingActivations_ = activations; }
       void tick(float dt);
 
@@ -71,4 +72,9 @@
       bool checkXor();
       void setBillboardColour(ColourValue colour);
+      void storeState();
+
+    protected:
+      inline bool isTriggered() { return this->isTriggered(this->mode_); }
+      virtual bool isTriggered(TriggerMode mode);
 
     private:
@@ -84,4 +90,6 @@
       BillboardSet debugBillboard_;
       float delay_;
+      int remainingActivations_;
+      bool bStayTriggered_;
       char latestState_;
   };
