Author Topic: Setting a "material" to a brick and calling the properties from the material  (Read 1220 times)

Ok, I'm working on a gamemode that's like Salvage Mod meets Honor Mining. It's called Bellkel, don't ask why.
However, I'm not very good at scripting, so could someone tell me what I should do here?

I currently have a scriptgroup for the material data like Unlimited Mining uses, but Bellkel doesn't use one datablock for salvageable materials, and I want a way to call the material's properties after setting the material to the brick. I'm not sure how to do this.

Here's what I got, with just a sample of the scriptgroup:

Code: [Select]
if ( !isObject(BellkelData) )
  {
   new SimSet(BellkelData)
      {

//new ScriptObject(Material)
//{
// fakename = "
// value =
// hp =
// mass =
// variable = "
//}
//new ScriptObject(Material)
//{
// fakename = "
// value =
// hp =
// mass =
// variable = "
// name = "
// toolminlevel = "
//}
new ScriptObject(Material)
{
fakename = "Stone";
value = 1;
hp = 1;
mass = 4;
variable = "Stone";
}
new ScriptObject(Material)
{
fakename = "Wood";
value = 1;
hp = 1;
mass = 1;
variable = "Wood";
}
new ScriptObject(Material)
{
fakename = "Cloth";
value = 1;
hp = 1;
mass = 1;
variable = "Cloth";
}
new ScriptObject(Material)
{
fakename = "Coal";
value = 3;
hp = 3;
mass = 3;
variable = "Coal";
}
new ScriptObject(Material)
{
fakename = "Glass";
value = 1;
hp = 1;
mass = 2;
variable = "Glass";
}
new ScriptObject(Material)
{
fakename = "Bone";
value = 1;
hp = 1;
mass = 1;
variable = "Bone";
}
new ScriptObject(Material)
{
fakename = "Darkwood";
value = 2;
hp = 2;
mass = 1;
variable = "Darkwood";
}
new ScriptObject(Material)
{
fakename = "Steel";
value = 11;
hp = 11;
mass = 3;
variable = "Steel";
}
}
}

And then

Code: [Select]
package BellkelConvert
{
function fxDTSbrick::onplant(%brick)
{
Parent::onPlant(%brick);
%brick.loadSalvageness();
echo("Brick planted, loading salvageness");
}
function fxDTSbrick::onLoadPlant(%brick)
{
Parent::onLoadPlant(%brick);
%brick.loadSalvageness();
%brick.materialname
echo("Brick loaded, loading salvageness");
}
function fxDTSbrick::loadSalvageness(%brick)
{
%color = %brick.getColorID();
echo("Got color ID: " @ %color);
%colorFX = %brick.getColorFxID();
echo("Got color FX ID: " @ %colorFX);
%shapeFX = %brick.getShapeFxID();
echo("Got shape FX ID: " @ %shapeFX);

//Datablock override

%mainresult = %brick.exceptionvaluecheck();
if(%mainresult !$= "NothingSpecial" && %mainresult !$= "Barrel")
{
        //do something different
    }
else if (%mainresult $= "Barrel")
{

}
    else if(%mainresult $="NothingSpecial")
    {
        %brick.material = %brick.colorCheck(%color, %colorFX, %shapeFX);
}

}
//Funct: Searches to see if there's a special result for the datablock in question
//Sends: "NothingSpecial" or a material
function fxDTSbrick::exceptionValueCheck(%brick)
{
%Datablock = %brick.getDataBlock();
switch$(%datablock)
{
case "brickTreasureChestData":
%lock = mFloor(getRandom(1, 50));
if (%lock >= 48)
{
return "LockedChest";
}
else
{
return "TreasureChest";
}
case "brick1x1MugData":
%result = "Ceramics";
case "brick2x2fPlateData":
%result = "Ceramics";
case "brick1x2fKeyboardData":
%result = "WetElectronics";
case "brick1x2fKnifeNForkData":
%result = "Silver";
case "brick2x3x2Computer1Data":
%result = "WetElectronics";
case "brick2x3x2Computer2Data":
%result = "WetElectronics";
case "brick2x3x2Computer3Data":
%result = "WetElectronics";
case "brick2x4x7FlatscreenData":
%result = "WetElectronics";
case "brick4x4x15FridgeData":
%result = "WetElectronics";
case "brick4x4x9OvenData":
%result = "WetElectronics";
case "brickTeledoorData":
%result = "Nope";
case "brick1x1x5AntennaData":
%result = "WetElectronics";
case "brickBarrelData":
%result = "Barrel";
case "brickBarrel2Data":
%result = "Barrel";
case "brick2x2FBookHorizData":
%result = "WetBooks";
case "brick1x2BookVertData":
%result = "WetBooks";
case "brick2x2BookDiagData":
%result = "WetBooks";
case "brick2x2BookDiagLData":
%result = "WetBooks";
case "brickCheckpointData":
%result = "Nope";
case "brick2x2x5PresentData":
%result = "Gift";
case "brick2x2x5PresentTwoData":
%result = "Gift";
case "brick2x2x5PresentThreeData":
%result = "Gift";
case "brickClockData":
%result = "Electronics";
case "mugEmptyData":
%result = "Ceramics";
case "mugFullData":
%result = "Ceramics";
case "brick2x2PictureFrameData":
%result = "Picture";
case "brick3x4x5VendingMachineData":
%result = "WetElectronics";
case "brick1x1CupData":
%result = "Ceramics";
case "brickPumpkinBaseData":
%result = "MessyFood";
case "brickPumpkinFaceData":
%result = "MessyFood";
case "brickPumpkinScaredData":
%result = "MessyFood";
case "brickPumpkinAsciiData":
%result = "MessyFood";
case "brick2x2x5BarrelData":
%result = "Barrel";
case "brick3x3x2CrabData":
%result = "Crabs";
case "brick2x2FBookHorizPrData":
%result = "WetBooks";
case "brick1x2BookVertPrData":
%result = "WetBooks";
case "brick2x2BookDiagPrData":
%result = "WetBooks";
case "brick2x2BookDiagLPrData":
%result = "WetBooks";
case "brick2x2x5BarrelData":
%result = "Barrel";
default:
%result = "NothingSpecial";
}
return %result;
}

function fxDTSbrick::colorcheck(%brick, %color, %colorFX, %shapeFX)
{
    if (%shapefx == 2)
    {
        return "Nope";
    }
    else if (%shapefx == 1)
    {
        if ((%colorfx == 0 || %colorfx == 3));
        {
            if ((%color == 17 || (%color >= 27 && %color <= 35)|| %color == 44))
            {
                return "Liquids";
            }
            else
            {       
                return "Cloth";
            }
        }
        else if ((%colorfx == 2 && %color == 41));
        {
            return "Evanadium";
        }
        else
        {
            return "Nope";
        }
    }   //That was almost too easy. I probably screwed it up somewhere.
    else if (%shapefx == 0)
    {
        if (%colorfx == 0)
        {
            if ((%color >= 4 && %color <= 7))   //Are these double ()s really needed? Idk.
            {
                return "Stone";
            }
            else if ((%color == 3 || %color == 20 || %color == 48))
            {
                return "Wood";
            }
            else if ((%color == 16))
            {
                return "Coal";
            }
            else if ((%color == 17 || (%color >= 27 && %color <= 35) || %color == 44))
            {
                return "Glass";
            }
            else
            {
                return "Nope";
            }
        }
        else if (%colorfx == 1)
        {
            if ((%color == 6))
            {
                return "Steel";
            }
            else if ((%color == 28))
            {
                %bug = mFloor(getRandom(1, 50));
                if (%bug >= 49)
                {
                    return "Amberbug";
                }
                else
                {
                    return "Amber";
                }
            }
            else
            {
                return "Nope";
            }
        }
        else if ((%colorfx == 2))
        {
            if ((%color == 5))
            {
                return "Quicksilver";
            }
    else
{
return "Nope";
}
        }
        else if ((%colorfx == 3))
        {
            if ((%color == 15))
            {
                return "Lightstone";
            }

            else
            {
                return "Nope";
            }
        }
        else
        {
            return "Nope";
        }
    }
    else
    {
        return "Nope";
    }
}


You get the idea. There's more materials than that.

Anyways, how do I call the given properties of the material specified?

Well first off give all the materials unique names, instead of naming them all Material.
fakename and variable fields look redundant, only need one, and if you name the materials right both would be unneeded
then you would set the material with %brick.material = MaterialName
and you could access the materials properties with %brick.material.hp or whatever field you need
for example
Code: [Select]
new ScriptObject(StoneMaterial)
{
value = 1;
hp = 1;
mass = 4;
}
%brick.material = StoneMaterial;
%hp = %brick.material.hp;

Though TBH I'd probably just use global variable arrays for something like this

Also your ::colorcheck function is very messy and your return values of "NothingSpecial" and "Nope" irritate me
« Last Edit: August 18, 2012, 05:47:34 PM by Headcrab Zombie »

Well first off give all the materials unique names, instead of naming them all Material.
fakename and variable fields look redundant, only need one, and if you name the materials right both would be unneeded
then you would set the material with %brick.material = MaterialName
and you could access the materials properties with %brick.material.hp or whatever field you need
for example
Code: [Select]
new ScriptObject(StoneMaterial)
{
value = 1;
hp = 1;
mass = 4;
}
%brick.material = StoneMaterial;
%hp = %brick.material.hp;
Also your ::colorcheck function is very messy and your return values of "NothingSpecial" and "Nope" irritate me
k, thanks for the tip. I was using Redguy's as a reference and, well, that's why it looks like that.
The fakename is so that I can display one name when salvaging it and a different, "real" name when it's actually done. So people who salvage "amber with a bug in it" won't know until they salvage it that it has a bug in it.

Thanks!

The fakename is so that I can display one name when salvaging it and a different, "real" name when it's actually done. So people who salvage "amber with a bug in it" won't know until they salvage it that it has a bug in it.
Thanks!
Oh, I get it, though I would suggest 'realname' instead of 'variable', as the name 'variable' doesn't describe itself at all

Oh, I get it, though I would suggest 'realname' instead of 'variable', as the name 'variable' doesn't describe itself at all
That was originally the player variable that was added upon salvaging it (it is sorta like honormining in that respect). There is actually a "name" field on Amber with a Bug in it, I had another thing that I didn't post here that set the material's "name" to the same thing as it's "fakename" if it had no "name" field. Kinda ridiculous though, why I did it that way is beyond me.

EDIT: Yes, that makes the "value" field pointless, it'll only be there until I do the variable selling system because I needed some way to remember what values I picked.
« Last Edit: August 18, 2012, 06:42:10 PM by YourBuddyBill »

I'm actually with honor in developing honormining/rmo, I can give you some tips tommorow if you'd like.

I'm actually with honor in developing honormining/rmo, I can give you some tips tommorow if you'd like.
Right, thanks! I'm having trouble with the variable carrying/selling as well.

Edit: Just so you guys know, the reason the color function is so messy is because there's actually at least fifty different materials, and I needed a way to categorize them in the function to simplify things. Makes it easier for me looking back in to add something. Evanadium is the only thing to have a color FX and a shape FX lol.

Also, some datablocks have materials assigned to them regardless of color. The Barrels can be a number of things, random chances for:
Red Spice, Blue Spice, Yellow Spice, Green Spice, Orange Spice, Pink Spice, Purple Spice, Brown Spice, White Spice, Grey Spice, Black Spice, Barrel of Gasoline, Barrel of Oil, or Barrel of Monkeys
« Last Edit: August 18, 2012, 06:54:40 PM by YourBuddyBill »

Right, thanks! I'm having trouble with the variable carrying/selling as well.
Always happy to help :)