Index: code/trunk/src/modules/objects/Script.cc
===================================================================
--- code/trunk/src/modules/objects/Script.cc	(revision 7481)
+++ code/trunk/src/modules/objects/Script.cc	(revision 7482)
@@ -1,2 +1,3 @@
+
 /*
  *   ORXONOX - the hottest 3D action shooter ever to exist
@@ -47,5 +48,5 @@
     CreateFactory(Script);
 
-    registerMemberNetworkFunction(Script, execute);
+    registerStaticNetworkFunction(Script::executeHelper);
 
     // Initializing constants.
@@ -54,4 +55,6 @@
     /*static*/ const int Script::INF = -1;
 
+    /*static*/ LuaState* Script::LUA_STATE = NULL;
+
     /**
     @brief
@@ -65,5 +68,4 @@
 
         // Initialize variables.
-        this->luaState_ = NULL;
         this->remainingExecutions_ = Script::INF;
         this->mode_ = ScriptMode::normal;
@@ -71,8 +73,4 @@
         this->times_ = Script::INF;
         this->needsGraphics_ = false;
-
-        this->counter_ = 0.0f;
-
-        this->registerVariables();
     }
 
@@ -83,6 +81,6 @@
     Script::~Script()
     {
-        if(this->isInitialized() && this->luaState_ != NULL)
-            delete this->luaState_;
+        //if(this->isInitialized() && this->luaState_ != NULL)
+        //    delete this->luaState_;
     }
 
@@ -108,5 +106,5 @@
         XMLPortEventSink(Script, BaseObject, "trigger", trigger, xmlelement, mode);
 
-        if(this->isOnLoad()) // If the object is onLoad the code is executed at once for all clients.
+        if(this->isOnLoad()) // If the object is onLoad the code is executed at once for the server.
             this->execute(0);
     }
@@ -125,42 +123,4 @@
 
         XMLPortEventState(Script, BaseObject, "trigger", trigger, xmlelement, mode);
-    }
-
-    /**
-    @brief
-        Register the variables that need to be synchronized.
-    */
-    void Script::registerVariables(void)
-    {
-        registerVariable(code_, VariableDirection::ToClient);
-        registerVariable(needsGraphics_, VariableDirection::ToClient);
-        registerVariable(modeStr_, VariableDirection::ToClient, new NetworkCallback<Script>(this, &Script::modeChanged));
-    }
-
-    void Script::modeChanged(void)
-    {
-        this->setMode(this->modeStr_);
-    }
-
-    void Script::tick(float dt)
-    {
-        SUPER(Script, tick, dt);
-
-        if(!this->clientCallbacks_.empty())
-        {
-            if(this->counter_ < 2.0f)
-            {
-                this->counter_ += dt;
-            }
-            else
-            {
-                for(std::vector<unsigned int>::iterator it = this->clientCallbacks_.begin(); it != this->clientCallbacks_.end(); it++)
-                {
-                    this->execute(*it, true);
-                }
-                this->clientCallbacks_.clear();
-                this->counter_ = 0.0f;
-            }
-        }
     }
 
@@ -225,5 +185,7 @@
     void Script::execute(unsigned int clientId, bool fromCallback)
     {
-        if(GameMode::isServer())
+        COUT(0) << "EXECUTE: " << Host::getPlayerID() << " | " << clientId << std::endl; //TODO: Remove.
+        // If this is the server or we're in standalone mode we check whether we still want to execute the code and if so decrease the number of remaining executions.
+        if(GameMode::isServer() || GameMode::isStandalone())
         {
             // If the number of executions have been used up.
@@ -232,25 +194,21 @@
 
             // Decrement the number of remaining executions.
+            //TODO: Mode such that this is consistent in any case.
             if(this->times_ != Script::INF)
                 this->remainingExecutions_--;
         }
 
+        // If this is either the standalone mode or we're on the client we want to be.
         if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
         {
-            // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed.
-            if(this->needsGraphics_ && !GameMode::showsGraphics())
-                return;
-
-            if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'.
-                CommandExecutor::execute(this->code_);
-            else if(this->mode_ == ScriptMode::lua) // If it's 'lua'.
-            {
-                if(this->luaState_ == NULL)
-                    this->luaState_ = new LuaState();
-                this->luaState_->doString(this->code_);
-            }
-        }
+           this->executeHelper(this->getCode(), this->getMode(), this->getNeedsGraphics());
+        }
+
+        // If this is the server and we're not on the client we want to be.
         if(!GameMode::isStandalone() && GameMode::isServer() && Host::getPlayerID() != clientId)
         {
+            COUT(0) << "1" << std::endl; //TODO: Remove.
+            // If this is not the result of a clientConnected callback and we want to execute the code for all clients.
+            //TODO: In this case does the server get executed as well?
             if(!fromCallback && this->isForAll())
             {
@@ -258,21 +216,51 @@
                 for(std::map<unsigned int, PlayerInfo*>::const_iterator it = clients.begin(); it != clients.end(); it++)
                 {
-                    callMemberNetworkFunction(Script, execute, this->getObjectID(), it->first, it->first, false);
+                    callStaticNetworkFunction(Script::executeHelper, it->first, this->getCode(), this->getMode(), this->getNeedsGraphics());
                 }
             }
+            // Else we execute the code just for the specified client.
             else
             {
-                callMemberNetworkFunction(Script, execute, this->getObjectID(), clientId, clientId, false);
+                COUT(0) << "2" << std::endl; //TODO: Remove.
+                callStaticNetworkFunction(Script::executeHelper, clientId, this->getCode(), this->getMode(), this->getNeedsGraphics());
             }
         }
     }
 
+    /**
+    @brief
+        Helper method that is used to reach this Script object on other clients.
+    */
+    /*static*/ void Script::executeHelper(const std::string& code, const std::string& mode, bool needsGraphics)
+    {
+        COUT(0) << "HELPER: " << code << " | " << mode << " | " << needsGraphics << std::endl; //TODO: Remove.
+
+        // If the code needs graphics to be executed but the GameMode doesn't show graphics the code isn't executed.
+        if(needsGraphics && !GameMode::showsGraphics())
+            return;
+
+        if(mode == Script::NORMAL) // If the mode is 'normal'.
+            CommandExecutor::execute(code);
+        else if(mode == Script::LUA) // If it's 'lua'.
+        {
+            if(Script::LUA_STATE == NULL)
+                Script::LUA_STATE = new LuaState();
+            Script::LUA_STATE->doString(code);
+        }
+    }
+
+    /**
+    @brief
+        Callback that is called when a new client has connected.
+    @param clientId
+        The clientId of the new client that has connected.
+    */
     void Script::clientConnected(unsigned int clientId)
     {
+        // If this is the server and the Script is specified as being 'onLoad'.
         if(!GameMode::isStandalone() && GameMode::isServer() && this->isOnLoad())
         {
-            if(clientId != 0)
-                //TODO: Do better. This is only a temporary fix.
-                this->clientCallbacks_.push_back(clientId);
+            if(clientId != 0) //TODO: Remove if not needed.
+                this->execute(clientId, true);
         }
     }
@@ -295,7 +283,4 @@
             this->setMode(ScriptMode::lua);
             this->modeStr_ = Script::LUA;
-            // Creates a new LuaState.
-            if(this->luaState_ == NULL)
-                this->luaState_ = new LuaState();
         }
         else
@@ -305,4 +290,14 @@
             this->modeStr_ = Script::NORMAL;
         }
+    }
+
+    /**
+    @brief
+        Sets the mode to the mode specified in this->modeStr_.
+        This is used internally for networking purposes.
+    */
+    void Script::modeChanged(void)
+    {
+        this->setMode(this->modeStr_);
     }
 
Index: code/trunk/src/modules/objects/Script.h
===================================================================
--- code/trunk/src/modules/objects/Script.h	(revision 7481)
+++ code/trunk/src/modules/objects/Script.h	(revision 7482)
@@ -1,2 +1,3 @@
+
 /*
  *   ORXONOX - the hottest 3D action shooter ever to exist
@@ -36,5 +37,4 @@
 
 #include "core/BaseObject.h"
-#include "tools/interfaces/Tickable.h"
 #include "network/synchronisable/Synchronisable.h"
 #include "network/ClientConnectionListener.h"
@@ -83,5 +83,5 @@
         Damian 'Mozork' Frick
     */
-    class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener, public Tickable
+    class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener
     {
         public:
@@ -92,8 +92,7 @@
             virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them.
 
-            virtual void tick(float dt);
-
             bool trigger(bool triggered, BaseObject* trigger); //!< Is called when an event comes in trough the event port.
             void execute(unsigned int clientId, bool fromCallback = false); //!< Executes the Scripts code for the input client, depending on the mode.
+            static void executeHelper(const std::string& code, const std::string& mode, bool needsGraphics); //!< Helper method that is used to reach this Script object on other clients.
 
             /**
@@ -160,5 +159,5 @@
                 { return this->forAll_; }
 
-            virtual void clientConnected(unsigned int clientId);
+            virtual void clientConnected(unsigned int clientId); //!< Callback that is called when a new client has connected.
             virtual void clientDisconnected(unsigned int clientid) {}
 
@@ -171,4 +170,5 @@
             std::string code_; //!< The code that is executed by this Script.
             ScriptMode::Value mode_; //!< The mode the Script is in. Determines whether the code is executed the normal way or in lua.
+            std::string modeStr_; //!< The mode the Script is in, as a string. Is used for networking purposes.
             bool onLoad_; //!< Whether the Scripts code is executed upon loading (creation) of this Script.
             int times_; //!< The number of times the Scripts code is executed at the most. -1 denotes infinity.
@@ -176,14 +176,8 @@
             bool forAll_; //!< Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script.
 
-            std::string modeStr_;
-
-            std::vector<unsigned int> clientCallbacks_;
-            float counter_;
-
-            LuaState* luaState_; //!< The LuaState to execute the code in lua.
+            static LuaState* LUA_STATE; //!< The LuaState to execute the code in lua.
             int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity.
 
-            void registerVariables(void);
-            void modeChanged();
+            void modeChanged(); //!< Sets the mode to the mode specified in this->modeStr_.
 
             /**
