Dynamic create/remove foliage on client/server
by NewYork Virtual · 11/02/2006 (5:42 pm) · 6 comments
This is an example of dynamic create fxShapeReplicator type object
on both clients and server, will generalte flowers from player's current
position, hope others can find this helpful.
I was looking for a solution to do this, and i found this thread
www.garagegames.com/mg/forums/result.thread.php?qt=18448,
so here we have some example code here.
Some notes:
1. you need to replace shapeFile = "~/data/shapes/Plants/flower.dts";
with your own shape file.
2. to remove object, this may not need commandToclient(%cl, 'doReplicate');
3. you can change fxShapeReplicator to fxFoliageReplicator, it should works
also, but not tested.
4. This is just a testing code.
--------------------------Client code:-----------------------------------------------------
---------------------------------Server code: -----------------------------------------------
on both clients and server, will generalte flowers from player's current
position, hope others can find this helpful.
I was looking for a solution to do this, and i found this thread
www.garagegames.com/mg/forums/result.thread.php?qt=18448,
so here we have some example code here.
Some notes:
1. you need to replace shapeFile = "~/data/shapes/Plants/flower.dts";
with your own shape file.
2. to remove object, this may not need commandToclient(%cl, 'doReplicate');
3. you can change fxShapeReplicator to fxFoliageReplicator, it should works
also, but not tested.
4. This is just a testing code.
--------------------------Client code:-----------------------------------------------------
$rshapes = new simGroup(rshapes);
function clientCmdCreateFlowers(%pos)
{
schedule(1000, 0, "CreateFlowers", %pos);
}
function clientCmdDoReplicate()
{
schedule(2000, 0, "startFoliageReplication");
schedule(2800, 0, "startClientReplication");
}
function CreateFlowers(%pos)
{
logMessage("clientCmdCreateFlower:" @ %pos, 1);
%flowers = new fxShapeReplicator(Flowers) {
position = %pos;
rotation = "1 0 0 0";
scale = "1 1 1";
HideReplications = "0";
ShowPlacementArea = "1";
PlacementAreaHeight = "25";
PlacementColour = %pos;
shapeFile = "~/data/shapes/Plants/flower.dts";
Seed = "1376312589";
ShapeCount = "148";
ShapeRetries = "80";
InnerRadiusX = "0";
InnerRadiusY = "0";
OuterRadiusX = "280";
OuterRadiusY = "280";
AllowOnTerrain = "1";
AllowOnInteriors = "1";
AllowOnStatics = "1";
AllowOnWater = "0";
AllowWaterSurface = "0";
AlignToTerrain = "0";
Interactions = "1";
AllowedTerrainSlope = "90";
TerrainAlignment = "1 1 1";
FixShapeAspect = "0";
ShapeScaleMin = "0.43 0.43 0.43";
ShapeScaleMax = "1.18 1.18 1.18";
ShapeRotateMin = "0 0 0";
ShapeRotateMax = "0 0 0";
OffsetZ = "0";
};
rshapes.add(%flowers);
}
function clientCmdRMFlowers()
{
schedule(100, 0, "rmFlowers");
}
function rmFlowers()
{
%count = rshapes.getCount();
logMessage("rmFlowers:" @ %count, 1);
for(%i=0; %i<%count; %i++)
{
%obj = rshapes.getObject(%i);
logMessage("rmFlowers:" @ %obj, 1);
rshapes.remove(%obj);
%obj.schedule(10, "delete");
%count --;
%i--;
}
}---------------------------------Server code: -----------------------------------------------
$rshapes = new simGroup(rshapes);
function ServerCmdCreateFlowers(%client)
{
%count = ClientGroup.getCount();
%pos = vectorAdd(%client.player.getPosition(), "0 0 2");
createFlowers(%pos);
logMessage("CmdCreateFlowers:" @ %pos, 1);
for (%i = 0; %i < %count; %i++)
{
%cl = ClientGroup.getObject(%i);
if( !%cl.isAIControlled() ){
commandToclient(%cl, 'CreateFlowers', %pos);
commandToclient(%cl, 'doReplicate');
}
}
}
function createFlowers(%pos)
{
logMessage("clientCmdCreateFlower:" @ %pos, 1);
%flowers = new fxShapeReplicator(Flowers) {
position = "-188.838 -108.911 168.018";
rotation = "1 0 0 0";
scale = "1 1 1";
HideReplications = "0";
ShowPlacementArea = "1";
PlacementAreaHeight = "25";
PlacementColour = "0.400000 0.000000 0.800000 1.000000";
shapeFile = "~/data/shapes/Plants/flower.dts";
Seed = "1376312589";
ShapeCount = "148";
ShapeRetries = "80";
InnerRadiusX = "0";
InnerRadiusY = "0";
OuterRadiusX = "280";
OuterRadiusY = "280";
AllowOnTerrain = "1";
AllowOnInteriors = "1";
AllowOnStatics = "1";
AllowOnWater = "0";
AllowWaterSurface = "0";
AlignToTerrain = "0";
Interactions = "1";
AllowedTerrainSlope = "90";
TerrainAlignment = "1 1 1";
FixShapeAspect = "0";
ShapeScaleMin = "0.43 0.43 0.43";
ShapeScaleMax = "1.18 1.18 1.18";
ShapeRotateMin = "0 0 0";
ShapeRotateMax = "0 0 0";
OffsetZ = "0";
};
rshapes.add(%flowers);
}
function ServerCmdRMFlowers(%client)
{
rmFlowers();
%count = ClientGroup.getCount();
logMessage("CmdRMFolowers:"@%count);
for (%i = 0; %i < %count; %i++)
{
%cl = ClientGroup.getObject(%i);
if( !%cl.isAIControlled() ){
commandToclient(%cl, 'rmFlowers');
commandToclient(%cl, 'doReplicate');
}
}
}
function rmFlowers()
{
%count = rshapes.getCount();
logMessage("rmFlowers:" @ %count, 1);
for(%i=0; %i<%count; %i++)
{
%obj = rshapes.getObject(%i);
logMessage("rmFlowers:" @ %obj, 1);
rshapes.remove(%obj);
%obj.schedule(10, "delete");
%count --;
%i--;
}
}About the author
#2
11/02/2006 (8:52 pm)
Hey, that's cool. How about a screen shot?
#4
11/03/2006 (11:09 pm)
ouch my eyes
#5
11/04/2006 (3:23 am)
Can we get a larger shot of that? lol
#6
larger pictures ( 800x600):
1st one: www.coolsailors.com/photos/screenshot_001-000031.png
2nd one: www.coolsailors.com/photos/screenshot_001-000041.png
11/04/2006 (5:17 pm)
Look above pictures, the second picture shows flowers ( arrow pointed ) are created in game, here arelarger pictures ( 800x600):
1st one: www.coolsailors.com/photos/screenshot_001-000031.png
2nd one: www.coolsailors.com/photos/screenshot_001-000041.png


Torque Owner Clint S. Brewer