Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Is there a way to stop a player from placing a certain block?

Discussion in 'Modding API' started by Geneticus, Jan 9, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Geneticus Senior Engineer

    Meaning, Can I restrict a block(Mod or Vanilla) so that it cannot be placed by a particular player or faction but still show up in the g-menu and still be placed by others?


    I also need to account for projector blocks and shared welders.


    What I'm trying to figure out is a method to allow a Player to be able to build a Refinery If they have a completed Arc Furnace built.

    Likewise, prevent a Player from building the same Refinery until they meet the condition that they own a completed Arc Furnace themselves.

    I'm sure you can figure out where this would lead...

    Edit 3: Removed MultiPlayer references as that is a headache for a later time ;)
    Last edited by a moderator: Jan 10, 2015
  2. midspace Senior Engineer

    One thing to remember, is Mod Script run on the client.
    Any action the script takes, affects only that PC. It cannot affect other PC.

    You can change the visibility of items on the G menu like this:

    var cubeDef = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_SpaceBall), "SpaceBallLarge"));
    cubeDef.Public = true;
    Last edited by a moderator: Jan 10, 2015
  3. Geneticus Senior Engineer

    Oh that's perfect!

    For the moment I'm focusing on getting proof of concept up in SP.
    One other thing I'd like to be able to do is alter the world settings on the fly.
    Specifically the new ship speed values, but more importantly, convert a limited world to a procedural one(size, density, random seed vals.) from the client script.

    If I can get all of that working(big IF), then I'd start looking into passing data between client scripts and server. Ideally with an extender plugin, or hacky but doable: a protected data block that the server writes to and have the clients read the trigger instructions from there..

    The larger project would restructure Asteroid Materials, Ore, Ingot requirements for components, component requirements for blocks, add some custom blocks, and be able to see and incorporate other mods.

    Unfortunately, I may be reaching a bit too much as my C# experience is limited to ASP.net business applications. We'll see if I am biting off more than I can chew :)
  4. Geneticus Senior Engineer

    So, here is my pseudologic if anyone is interested...

    <div>        //Default to Tier 1 tech tree
                //set all non Tier 1 blocks to hidden
            // Get Player Info ID/Name
            // if block is created, disabled, or destroyed
                //check all grids where Player is Owner of a Block and collect list of Blocks owned
                    // For each Tier in Tiers
                        //For each block in Tier
                            //Check List of prerequisite block(s) is/are owned by player                    
                                //If Tier prereqs == true, set Tier block to public, else hide block.
                                    //if block was changed, message player that New Tier achieved in "X" or Tier lost because Y condifions are no longer met.
    I think a cleaner presentation would be to swap out the icon for a greyed out one and intercept the placement of the block either from being added to the toolbar, or even better from being placed by hand/welder to prevent cheating via projectors or preconfigured toolbars. This should, however, be enough to get PoC.
  5. midspace Senior Engineer

    You can also do:
    MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed = 2000;
    MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed = 2000;
    However, changing the speed will immediately affect the player, but not ships.
    It will only affect NEW ships built after you change the value.

    Also, I have no idea what changing this values whilst playing on a Server will do.
    Last edited by a moderator: Jan 10, 2015
  6. Geneticus Senior Engineer

    Yeah that's exactly the kind of headache I'm postponing by focusing on SP first.

    It looks like setting the public flag is not going to work in my design.

    Where I'm at right now:

    I have my organization for Tiers set up:
            public class CubeBlockProperties
                public string Tier { get; set; }
                public string SubTypeId { get; set; }
                public string preReq1 { get; set; }
                public string preReq2 { get; set; }
                public string preReq3 { get; set; }
                public string preReq4 { get; set; }
    private void Tier()
                var Tier1 = new List&lt;CubeBlockProperties>
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="LargeBlockArmorBlock",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="LargeBlockArmorSlope",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="LargeBlockArmorCorner",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="LargeBlockArmorCornerInv",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="SmallBlockArmorBlock",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="SmallBlockArmorSlope",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="SmallBlockArmorCorner",preReq1=null,preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier1", SubTypeId="SmallBlockArmorCornerInv",preReq1=null,preReq2=null,preReq3=null,preReq4=null}
                var Tier2 = new List&lt;CubeBlockProperties>
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="LargeHeavyBlockArmorBlock",preReq1="LargeBlockArmorBlock",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="LargeHeavyBlockArmorSlope",preReq1="LargeBlockArmorSlope",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="LargeHeavyBlockArmorCorner",preReq1="LargeBlockArmorCorner",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="LargeHeavyBlockArmorCornerInv",preReq1="LargeBlockArmorCornerInv",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="SmallHeavyBlockArmorBlock",preReq1="SmallBlockArmorBlock",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="SmallHeavyBlockArmorSlope",preReq1="SmallBlockArmorSlope",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="SmallHeavyBlockArmorCorner",preReq1="SmallBlockArmorCorner",preReq2=null,preReq3=null,preReq4=null},
                    new CubeBlockProperties() {Tier="Tier2", SubTypeId="SmallHeavyBlockArmorCornerInv",preReq1="SmallBlockArmorCornerInv",preReq2=null,preReq3=null,preReq4=null},
    I'll scan cubeblocks for any subtypeIds that are not in my list and throw them into Tier 4, so basically all mod blocks will have a prerequisite of 2 Tier 3 blocks with the same Type .

    Right now I'm looking at: Sandbox.ModAPI.IMyCubeBuilder.BlockCreationIsActivated (bool)

    I think it indicates if a character is in place block mode.

    I'm just not sure what event to look for to trap or how to get the info on the block in hand.

    Maybe look at the selected toolbar slot or maybe I can just look at the toolbar active slot changed event (if there is one and have to make sure I don't snag ship toolbars)

    The next step would be to compare the subTypeId of the intended block placement to the tier list and trigger Sandbox.ModAPI.IMyCubeBuilder.DeactivateBlockCreation() if the prerequisite has not been met. Then display a message indicating the missing blocks that unlock the one they wanted.

    Additionally to keep the player from being frustrated, I would have already iterated through all of the Vanilla blocks and swapped the icons of locked items for otherly colored ones. This is part of the reason hiding is not ideal, I want people to be able to see what blocks are possible now and in the future tiers.

    I'm also going to have to keep a hash of whether a player has placed a block type that has no ownership so I can Tier light and heavy Armor Blocks. Looping through ownable blocks should allow me to regress Tiers if a required block is damaged/destroyed/incomplete.
    Last edited by a moderator: Jan 10, 2015
  7. Geneticus Senior Engineer

    Haha! Just found your buildblocker script. I guess I was on the right track ;)
  8. Mortisfire Apprentice Engineer

    Getting an error from MyBuildblockerLogic. 'MyBuildBlockerLogic' does not implement inherited abstract member 'MyGameLogicComponent.GetObjectBuilder(bool)'. Has anyone kept this updated?
  9. Digi Senior Engineer

    You'll need to store the objectbuilder from Init() and return it in a GetObjectBuilder(bool copy) method, also try to obey the copy thing, do a clone if it's true and just return it if it's false.
  10. Mortisfire Apprentice Engineer

    Midspace actually helped me fix it yesterday. The original Pastebin code is now functional. Cheers : )
Thread Status:
This last post in this thread was made more than 31 days old.