Browse Source

Merge pull request #632 from eightyeight/better-explosion-example

Added a better example of using Explosion in a client/server fashion
Daniel Buckmaster 11 năm trước cách đây
mục cha
commit
47dbce1499
1 tập tin đã thay đổi với 21 bổ sung8 xóa
  1. 21 8
      Engine/source/T3D/fx/explosion.cpp

+ 21 - 8
Engine/source/T3D/fx/explosion.cpp

@@ -106,18 +106,31 @@ ConsoleDocClass( Explosion,
    "   lightEndBrightness = 0.0;\n"
    "   lightNormalOffset = 2.0;\n"
    "};\n\n"
-   "function createExplosion()\n"
+   "function ServerPlayExplosion(%position, %datablock)\n"
    "{\n"
-   "   // Create a new explosion - it will explode automatically\n"
-   "   %pos = \"0 0 100\";\n"
-   "   %obj = new Explosion()\n"
+   "   // Play the given explosion on every client.\n"
+   "   // The explosion will be transmitted as an event, not attached to any object.\n"
+   "   for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)\n"
    "   {\n"
-   "      position = %pos;\n"
-   "      dataBlock = GrenadeLauncherExplosion;\n"
-   "   };\n"
+   "      %client = ClientGroup.getObject(%idx);\n"
+   "      commandToClient(%client, 'PlayExplosion', %position, %datablock.getId());\n"
+   "   }\n"
+   "}\n\n"
+   "function clientCmdPlayExplosion(%position, %effectDataBlock)\n"
+   "{\n"
+   "   // Play an explosion sent by the server. Make sure this function is defined\n"
+   "   // on the client.\n"
+   "   if (isObject(%effectDataBlock))\n"
+   "   {\n"
+   "      new Explosion()\n"
+   "      {\n"
+   "         position = %position;\n"
+   "         dataBlock = %effectDataBlock;\n"
+   "      };\n"
+   "   }\n"
    "}\n\n"
    "// schedule an explosion\n"
-   "schedule(1000, 0, createExplosion);\n"
+   "schedule(1000, 0, ServerPlayExplosion, \"0 0 0\", GrenadeLauncherExplosion);\n"
    "@endtsexample"
 );