Index: code/branches/ScriptableController_HS17/src/libraries/tools/Timer.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/libraries/tools/Timer.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/libraries/tools/Timer.cc	(revision 11562)
@@ -158,4 +158,12 @@
     }
 
+    Timer::Timer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
+    {
+        this->init();
+        RegisterObject(Timer);
+
+        this->setTimer(interval, bLoop, func, bKillAfterCall);
+    }
+
     /**
         @brief Initializes the Timer
@@ -193,9 +201,20 @@
         this->executor_ = executor;
         this->bActive_ = true;
+        this->isStdFunction_ = false;
 
         this->time_ = this->interval_;
         this->bKillAfterCall_ = bKillAfterCall;
 
-        executor->getFunctor()->setSafeMode(true);
+        if(executor != nullptr)
+            executor->getFunctor()->setSafeMode(true);
+    }
+
+    void Timer::setTimer(float interval, bool bLoop, std::function<void ()> func, bool bKillAfterCall)
+    {
+        // Without the cast, the call would be ambiguous, because nullptr is castable to
+        // both, ExecutorPtr and std::function.
+        this->setTimer(interval, bLoop, static_cast<ExecutorPtr>(nullptr), bKillAfterCall);
+        this->function_ = func;
+        this->isStdFunction_ = true;
     }
 
@@ -207,5 +226,8 @@
         bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer
 
-        (*this->executor_)();
+        if(this->isStdFunction_)
+            this->function_();
+        else
+            (*this->executor_)();
 
         if (temp)
Index: code/branches/ScriptableController_HS17/src/libraries/tools/Timer.h
===================================================================
--- code/branches/ScriptableController_HS17/src/libraries/tools/Timer.h	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/libraries/tools/Timer.h	(revision 11562)
@@ -108,6 +108,8 @@
 
             Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
+            Timer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
 
             void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
+            void setTimer(float interval, bool bLoop, std::function<void (void)> func, bool bKillAfterCall = false);
 
             void run();
@@ -153,5 +155,7 @@
 
             ExecutorPtr executor_;  //!< The executor of the function that will be called when the time expires
+            std::function<void (void)> function_;
 
+            bool isStdFunction_;
             long long interval_;    //!< The time-interval in micro seconds
             bool bLoop_;            //!< If true, the executor gets called every @a interval seconds
Index: code/branches/ScriptableController_HS17/src/orxonox/Level.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/Level.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/Level.cc	(revision 11562)
@@ -57,4 +57,5 @@
         this->xmlfilename_ = this->getFilename();
         this->xmlfile_ = nullptr;
+        this->controller_.reset(new ScriptableController());
     }
 
@@ -84,10 +85,4 @@
         XMLPortObject(Level, MeshLodInformation, "lodinformation", addLodInfo, getLodInfo, xmlelement, mode);
         XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
-
-        if(this->level_script_ != "")
-        {
-            this->controller_ = new ScriptableController(this->getContext());
-            this->controller_->runScript(this->level_script_);
-        }
     }
 
@@ -177,6 +172,5 @@
     {
         this->objects_.push_back(object);
-        if(this->controller_ != nullptr)
-            object->registerToScriptableController(this->controller_);
+        object->registerToScriptableController(this->controller_.get());
     }
 
@@ -214,4 +208,10 @@
         orxout(internal_info) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ')' << endl;
         player->switchGametype(this->getGametype());
+
+        if(player->isHumanPlayer() && player->isLocalPlayer())
+        {
+            this->getScriptableController()->setPlayer(player);
+            this->controller_->runScript(this->level_script_);
+        }
     }
 
Index: code/branches/ScriptableController_HS17/src/orxonox/Level.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/Level.h	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/Level.h	(revision 11562)
@@ -57,4 +57,7 @@
             MeshLodInformation* getLodInfo(std::string meshName) const;
 
+            inline ScriptableController *getScriptableController(void)
+                { return this->controller_.get(); }
+
 
         private:
@@ -92,5 +95,5 @@
             std::map<std::string,MeshLodInformation*>  lodInformation_;
 
-            ScriptableController* controller_;
+            std::unique_ptr<ScriptableController> controller_;
             std::string           level_script_;
     };
Index: code/branches/ScriptableController_HS17/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/infos/HumanPlayer.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/infos/HumanPlayer.cc	(revision 11562)
@@ -38,4 +38,6 @@
 #include "gametypes/Gametype.h"
 #include "overlays/OverlayGroup.h"
+#include "Level.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 namespace orxonox
Index: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc	(revision 11562)
@@ -2,17 +2,10 @@
 #include "scriptable_controller.h"
 #include "luatb.h"
+#include "infos/PlayerInfo.h"
 
 namespace orxonox
 {
 
-RegisterUnloadableClass(ScriptableController);
-
 // Used https://csl.name/post/lua-and-cpp/ as a reference
-ScriptableController::ScriptableController(Context* context)
-    : BaseObject(context)
-{
-    RegisterObject(ScriptableController);
-}
-
 int ScriptableController::runScript(const std::string &file_path)
 {
@@ -57,6 +50,12 @@
 }
 
+void ScriptableController::setPlayer(PlayerInfo *player)
+{
+    this->player_ = player;
+}
+
 void ScriptableController::registerWorldEntity(int id, WorldEntity *obj)
 {
+    orxout(user_info) << "WorldEntity registered (id: " << id << ")" << std::endl;
     this->worldEntities_[id] = obj;
 }
@@ -64,4 +63,5 @@
 void ScriptableController::registerControllableEntity(int id, ControllableEntity *obj)
 {
+    orxout(user_info) << "ControllableEntity registered (id: " << id << ")" << std::endl;
     this->worldEntities_[id] = obj;
 }
@@ -69,4 +69,7 @@
 WorldEntity *ScriptableController::getWorldEntityByID(int id) const
 {
+    if(id == 0)
+        return this->player_->getControllableEntity();
+
     auto obj = this->worldEntities_.find(id);
     return obj != this->worldEntities_.end() ? obj->second : nullptr;
@@ -75,32 +78,56 @@
 ControllableEntity *ScriptableController::getControllableEntityByID(int id) const
 {
+    if(id == 0)
+        return this->player_->getControllableEntity();
+
     auto obj = this->controllabelEntities_.find(id);
     return obj != this->controllabelEntities_.end() ? obj->second : nullptr;
 }
 
-void ScriptableController::registerTimeout(std::function<void ()> callback, double timeout)
+void ScriptableController::addNearObjectHandler(int obj1, int obj2, double distance, std::function<void (int,int)> callback)
 {
-    this->timeouts.push_back(std::make_pair(callback, static_cast<float>(timeout)));
+    orxout(user_info) << "NearObject registering (id 1: " << obj1 << ", id 2: " << obj2 << ")" << std::endl;
+
+    WorldEntity *entity1 = this->getWorldEntityByID(obj1);
+    WorldEntity *entity2 = this->getWorldEntityByID(obj2);
+
+    NearObjectHandler *handler1 = new NearObjectHandler(entity2, distance, callback);
+    NearObjectHandler *handler2 = new NearObjectHandler(entity1, distance, callback);
+
+    this->nearObjectHandlers_[entity1].push_front(std::unique_ptr<NearObjectHandler>(handler1));
+    this->nearObjectHandlers_[entity2].push_front(std::unique_ptr<NearObjectHandler>(handler2));
+
+    handler1->otherHandler_ = this->nearObjectHandlers_[entity2].begin();
+    handler2->otherHandler_ = this->nearObjectHandlers_[entity1].begin();
 }
 
-void ScriptableController::tick(float dt)
+void ScriptableController::objectMoved(WorldEntity *obj)
 {
-    auto timeout = this->timeouts.begin();
+    // Temp
+    return;
 
-    while(timeout != this->timeouts.end())
+    auto &nearObjectHandlers = this->nearObjectHandlers_[obj];
+    auto handler = nearObjectHandlers.begin();
+    while(handler != nearObjectHandlers.end())
     {
-        timeout->second -= dt;
-        if(timeout->second <= 0)
+        WorldEntity *other = (*handler)->otherObject_;
+        if((obj->getPosition() - other->getPosition()).length() < (*handler)->distance_)
         {
-            timeout->first();
-            timeout = this->timeouts.erase(timeout);
+            (*handler)->callback_(obj->getID(), other->getID());
+
+            auto otherHandler = (*handler)->otherHandler_;
+            handler = nearObjectHandlers.erase(handler);
+            if(nearObjectHandlers.empty())
+                this->nearObjectHandlers_.erase(obj);
+
+            this->nearObjectHandlers_[other].erase(otherHandler);
+            if(this->nearObjectHandlers_[other].empty())
+                this->nearObjectHandlers_.erase(other);
         }
         else
         {
-            timeout++;
+            handler++;
         }
     }
-
-    Tickable::tick(dt);
 }
 
Index: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h	(revision 11562)
@@ -17,11 +17,22 @@
 {
 
-class ScriptableController : public BaseObject, public Tickable
+class ScriptableController
 {
 public:
-    explicit ScriptableController(Context *context);
+    struct NearObjectHandler
+    {
+        NearObjectHandler(WorldEntity *otherObject, double distance, std::function<void (int, int)> callback)
+            : otherObject_(otherObject), distance_(distance), callback_(callback)
+        {}
+
+        WorldEntity *otherObject_;
+        double distance_;
+        std::function<void (int, int)> callback_;
+        std::list<std::unique_ptr<NearObjectHandler> >::iterator otherHandler_;
+    };
 
     int runScript(const std::string &file_path);
 
+    void setPlayer(PlayerInfo *player);
     void registerWorldEntity(int id, WorldEntity *obj);
     void registerControllableEntity(int id, ControllableEntity *obj);
@@ -30,14 +41,15 @@
     ControllableEntity *getControllableEntityByID(int id) const;
 
-    void registerTimeout(std::function<void (void)> callback, double timeout);
+    void addNearObjectHandler(int obj1, int obj2, double distance, std::function<void (int, int)> callback);
 
-    virtual void tick(float dt) override;
+    void objectMoved(WorldEntity *obj);
 
 private:
     std::list<std::unique_ptr<ScriptableControllerAPI> > apis_;
-    ControllableEntity *player_; // TODO
+    PlayerInfo *player_;
     std::map<int, WorldEntity*> worldEntities_;
     std::map<int, ControllableEntity*> controllabelEntities_;
-    std::list<std::pair<std::function<void (void)>, float> > timeouts;
+
+    std::map<WorldEntity*, std::list<std::unique_ptr<NearObjectHandler> > > nearObjectHandlers_;
 
     void printLuaError(lua_State *lua);
Index: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc	(revision 11562)
@@ -3,4 +3,5 @@
 #include "luatb.h"
 #include "scriptable_controller.h"
+#include "tools/Timer.h"
 
 namespace orxonox
@@ -13,4 +14,5 @@
 
     // Haven't found a shorter way yet to write that...
+    LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::orxPrint)>::registerFunction<&ScriptableControllerAPI::orxPrint>(this, lua, "orxPrint");
     LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAfterTimeout)>::registerFunction<&ScriptableControllerAPI::registerAfterTimeout>(this, lua, "registerAfterTimeout");
     LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearObject)>::registerFunction<&ScriptableControllerAPI::registerAtNearObject>(this, lua, "registerAtNearObject");
@@ -26,13 +28,18 @@
 }
 
+void ScriptableControllerAPI::orxPrint(std::string msg)
+{
+    orxout(user_info) << msg << std::endl;
+}
+
 void ScriptableControllerAPI::registerAfterTimeout(std::function<void (void)> callback, double timeout)
 {
-    // TODO Extend timer class to accept std::function
-    this->controller_->registerTimeout(callback, timeout);
+    // Kills itself when the timer fires
+    new Timer(timeout, false, callback, true);
 }
 
 int ScriptableControllerAPI::registerAtNearObject(std::function<void (int, int)> callback, int obj1, int obj2, double distance)
 {
-
+    //this->controller_->addNearObjectHandler(obj1, obj1, distance, callback);
 }
 
Index: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h	(revision 11562)
@@ -22,4 +22,5 @@
     void testOutput(std::function<void(std::string)> callback);
 
+    void orxPrint(std::string msg);
     void registerAfterTimeout(std::function<void (void)> callback, double timeout);
     int registerAtNearObject(std::function<void(int, int)> callback, int obj1, int obj2, double distance);
Index: code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc	(revision 11562)
@@ -36,4 +36,6 @@
 
 #include "Scene.h"
+#include "Level.h"
+#include "scriptablecontroller/scriptable_controller.h"
 
 namespace orxonox
@@ -113,4 +115,5 @@
 
         this->node_->setPosition(position);
+        this->getLevel()->getScriptableController()->objectMoved(this);
     }
 
Index: code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc	(revision 11562)
@@ -184,4 +184,6 @@
         // Attached collision shapes
         XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
+
+        orxout(user_info) << "ID loaded" << std::endl;
     }
 
@@ -280,4 +282,5 @@
     void WorldEntity::registerToScriptableController(ScriptableController *controller)
     {
+        orxout(user_info) << "Registering object to SC (" << this->id_ << ")" << std::endl;
         controller->registerWorldEntity(this->id_, this);
     }
Index: code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h	(revision 11561)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h	(revision 11562)
@@ -110,4 +110,7 @@
             virtual void changedActivity(void) override;
             virtual void changedVisibility(void) override;
+
+            inline int getID(void)
+                { return this->id_; }
 
             inline void setID(int id)
