Author Topic: Strings || Bricks  (Read 2517 times)

      %player = %client.getControlObject();
      if(!isObject(%player))
         return;
      %start = %player.getEyePoint();
      %scld = vectorScale(%player.getEyeVector(), 5);
      %end = vectorAdd(%start, %scld);
      %result = containerRaycast(%start, %end, $Typemasks::FxBrickObjectType, %client.player);
      //BEEP BEEP, BUILDMODE COMING THROUGH
      if(%client.buildmode == 1 && %client.bmstock !$= "")
      {
         %mat = getWord(%client.bmstock, 1);
         %amt = getWord(%client.bmstock, 0);
         %pos = posFromRaycast(%result);
         %pos = vectorAdd(%pos, "0 0 0.2");
         if(%pos $= "" || %amt <= 0)
            return;
         if(%mat $= "Silver")
         {
            %db = SilverBrickData;
            %color = 46;
            %client.removeFromBP(%mat, 1);
         }
         else if(%mat $= "Iron")
         {
            %db = IronBrickData;
            %color = 51;
            %client.removeFromBP(%mat, 1);
         }
         else if(%mat $= "Steel")
         {
            %db = SteelBrickData;
            %color = 49;
            %client.removeFromBP(%mat, 1);
         }
         else if(%mat $= "String")
         {
            %db = StringBrickData;
            %color = 1;
            %client.removeFromBP(%mat, 1);
         }
         else if(%mat $= "WoodPlank")
         {
            %db = WoodPlankBrickData;
            %color = 57;
            %client.removeFromBP(%mat, 1);
         }
         else
         {
            %client.chatMessage("\c3You aren't allowed to place that item.");
            return;
         }
         if(!isObject(%db))
            return;
         %brick = new fxDTSBrick()
         {
            datablock = %db;
            position = %pos;
            isPlanted = 0;
            colorID = %color;
            client = %client;
         };
         Brickgroup_888888.add(%brick);
         %error = %brick.plant();
         talk(%error);
         if(%error)
         {
            %client.chatMessage("\c3Plant Error!");
            if(isObject(%brick))
               %brick.schedule(33, delete);
            %client.addToBP(%mat, 1);
         }
         %client.bmstock = %amt - 1 SPC %mat;
         return;
      }
      //BUILDMODE ENDED


I'm having troubles, again. I'd artificially place a brick on a baseplate, but it would give me error code 1. If I understand correctly, it's saying there is something it's colliding with. I saw that it was being placed a little bit into the baseplate. So, as you may have seen, I elevated %pos by 0.2 on the Z axis. This works fine, but whenever you try to place any brick on top of it, or within a 1 stud radius to it, it refuses to plant because of collision errors. I checked, and it isn't at some weird height compared to any regular bricks. Anyone know what this is about?

The reason various raycasts weren't detecting the bricks you planted is that the bricks weren't actually there. Its a weird issue that has caused me many headaches in the past. If a brick fails to plant, for whatever reason (with the exception of floating bricks if you bypass the plant function), then it wont exist in the world according to the server, but it is still rendered and exists normally for clients. Client sided prediction code thinks that it is a perfectly fine brick, but if you walk on it, (after a moments hesitation due to latency) you'll teleport through. There's a few other weird things like this, where clients are desynced from the server.

I recommend you make a reliable function that places a brick, then only use that.

Code: [Select]
%lastBrick = new fxDTSBrick() {
...
};
%plant = %lastBrick.plant();

if(!%lastBrick.isPlanted) {
switch(%plant) {
case 2: //Floating brick, force plant
%lastBrick.isPlanted = 1;
%lastBrick.plant();

default:
%lastBrick.delete();
return 0;
}
}

%lastBrick.setTrusted(1);
%lastBrick.dataBlock.onTrustCheckFinished(%lastBrick);

%brickGroup.add(%lastBrick);
if(isObject(%brickGroup.client))
%brickGroup.client.wrenchBrick = %lastBrick; //Removes some errors with events

That should handle most errors you'll find.
« Last Edit: July 10, 2015, 09:57:25 AM by boodals 2 »

Mysterious magic man saves the day! Everything works, thanks so much.

Thanks!
I did use $Typemasks::All? Or did you make a typo and are you saying I shouldn't?
I'm sure he meant you shouldn't be using it since it will collide with everything else

use $TypeMasks::FxBrickObjectType instead


Sorry for changing the subject thrice already but I have a .dts file, how'd I go about getting it in-game? I don't mean like as a weapon or a vehicle or anything, but just spawning it in the world. I'd probably have to create a datablock for it. What would the datablock type even be? For reference it's a dome that players could summon over them. Another situation that I might have to use this for is if someone dies, and they drop their inventory, how would I make .dts files that I've created pop outta em? How would players be able to pick that up? Sorry if this is a bit incoherent, it's 1am.

Sorry for changing the subject thrice already but I have a .dts file, how'd I go about getting it in-game? I don't mean like as a weapon or a vehicle or anything, but just spawning it in the world. I'd probably have to create a datablock for it. What would the datablock type even be? For reference it's a dome that players could summon over them.

datablock StaticShapeData(MyShape)
{
    shapeFile = "foo/bar/shape.dts";
};

...

%obj = new StaticShape()
{
    datablock = MyShape;
};

MissionCleanup.add(%obj);


Another situation that I might have to use this for is if someone dies, and they drop their inventory, how would I make .dts files that I've created pop outta em? How would players be able to pick that up? Sorry if this is a bit incoherent, it's 1am.

datablock ItemData(MyItem)
{
    shapeFile = "foo/bar/shape.dts";
    ... there's a few more things you might want here, check a default item for reference
};

...

%obj = new Item()
{
    datablock = MyItem;
};

MissionCleanup.add(%obj);

%obj.setCollisionTimeout(player that dropped it);
%obj.setVelocity(...);
%obj.setScopeAlways();




For positioning them, you can either define position and rotation when creating the object, or you can call ::setTransform(mat) on them afterwards.
« Last Edit: July 09, 2015, 04:03:22 AM by portify »

Why are you making items always scoped to clients like that (setScopedAlways())? It seems unnecessary to keep clients constantly updated about dropped items, especially ones that will probably disappear in a few seconds anyways (OP didn't mention having this but I'm leaning towards he will).

Why are you making items always scoped to clients like that (setScopedAlways())? It seems unnecessary to keep clients constantly updated about dropped items, especially ones that will probably disappear in a few seconds anyways (OP didn't mention having this but I'm leaning towards he will).

Items sometimes seem to have some issues with ghosting when spawned with velocity (appearing frozen in the air briefly rather than flying away). That doesn't tend to happen for serverCmdDropTool despite it not using setScopeAlways, though. No idea why. May just be a incidental thing on certain servers, but setScopeAlways always seems to prevent it when it does happen. Of course you can omit it. If anything, try it without it first. If you see some issues with items not updating for clients at times, try it.

Is there a way to give static shapes collision? Also raycasts go right through them.

Is there a way to give static shapes collision?
Yes, but I'm not sure how. You do it in the modeling program.

Is there a way to give static shapes collision?

You need a collision detail level with a size of -1. The game will complain if you don't use specifically named meshes (collisionX or colX) in it.

Also raycasts go right through them.

You need a LOSCol detail level.