About Store Forum Documentation Contact
Donations:
178$/mo



Post Reply 
Detect which terrain material level underneath?
Author Message
Zervox Offline
Member

Post: #1
Detect which terrain material level underneath?
Is there a way to detect through the level like
Game::World.hmMaterial()

if(Game::World.terrainmatlevel(Players[0].pos()) == 1)
{
//Do something
}
if(Game::World.terrainmatlevel(Players[0].pos()) == 2)
{
//Do something
}

Just like the terrain editor can paint 13 different materials
08-11-2010 08:41 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Detect which terrain material level underneath?
what do you mean by "terrainmatlevel", what is that?
why not use hmMaterial() ?
Material has many members

you should use
Material::user_type
which can be set in material editor to custom user type.

world editor can paint not 13 materials, but up to 256 per area
08-11-2010 09:41 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #3
RE: Detect which terrain material level underneath?
256!? Neat!
oh, ok, just not really sure on how all this work ; )

Something like this is what I've tried earlier
Code:
if(Game::World.hmMaterial(Players[0].pos())) //check player pos on world material
{
if(Material::user_type = MUT_GRASS) // Check if player is on Grass textureMaterial
{
speed=1.7f;  //Increase player speed
}else if(
Material::user_type_name = MUT_MOUNTAINROCK) // Check if player is on mountain rock texture material
{
PPLAYStop(); //Stops player click on mouse button move function
}
returns
Code:
error C2597: illegal reference to non-static member 'EE::Material::user_type'
error C2597: illegal reference to non-static member 'EE::Material::user_type_name'
(This post was last modified: 08-11-2010 10:24 AM by Zervox.)
08-11-2010 10:20 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Detect which terrain material level underneath?
if(Material *m=hmMaterial())
{
m->user_type
}
08-11-2010 10:25 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #5
RE: Detect which terrain material level underneath?
Hmm, having a problem getting this to work though.
Code:
if(Material *m= Game::World.hmMaterial(Players[0].pos()))
{

    if(m->user_type = 24)
    {
        speed=1.7f;
    }
}
08-11-2010 10:55 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Detect which terrain material level underneath?
if(m->user_type == MUT_... )

== not = (use double =)
= is assignment
== is comparing
08-11-2010 12:09 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #7
RE: Detect which terrain material level underneath?
Still doesn't work. : S

Code:
if(Material *m= Game::World.hmMaterial(Players[0].pos()))
{
  // Code here wont run
if(m->user_type == MUT_EARTH)
{
  //  Code here wont run
}
}
(This post was last modified: 08-11-2010 01:26 PM by Zervox.)
08-11-2010 01:20 PM
Find all posts by this user Quote this message in a reply
sjaakiejj Offline
Member

Post: #8
RE: Detect which terrain material level underneath?
What happens if you do this?
Code:
Material *m = Game::World.hmMaterial(Players[0].pos());
//Could check if m is null, otherwise run
if(m->user_type == MUT_EARTH)
{
//code here
}

Otherwise, it may be the position which is incorrect. You could try setting a vector that you define yourself to see if it changes anything.

Perhaps you guessed these things yourself, I'm just giving my 5 cents here. Taking code apart into chunks is usually the way to find out why something doesn't work.
08-18-2010 08:24 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #9
RE: Detect which terrain material level underneath?
Material *m = Game::World.hmMaterial(Players[0].pos());

if this line is outside a if statement it crashes the exe.

Yeah, I've tried ripping that code in so many ways, but cant figure out why it doesnt/wont work :|
08-18-2010 08:50 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #10
RE: Detect which terrain material level underneath?
what do you mean it doesnt work?
it crashes or no effect?
does debugger enter the code block?
what's the value of m->user_type ?
08-18-2010 11:41 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #11
RE: Detect which terrain material level underneath?
This crashes
Code:
Material *m = Game::World.hmMaterial(Players[0].pos());
This does not but it doesnt run either
Code:
if(Material *m = Game::World.hmMaterial(Players[0].pos()))
{
//No code inside here will run
}

what code block? if you mean when it crashes, its when its without the if statement aka no code block properly.

how can I find the value if I cant retrieve the material info?
08-19-2010 08:20 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #12
RE: Detect which terrain material level underneath?
The reason it crashes without the if is because you're trying to access a null object since it's not finding any material. The point of putting it in the if statement is so it doesn't crash if it doesn't find one. That's also why no code is running inside the if statement.

I got this working in a few minutes just now so I can confirm that this function does indeed work. Take another look at the parameter for the hmMaterial function and you'll probably slam your head on your desk. smile

If you don't notice it, don't worry, I'll tell you...
08-19-2010 09:46 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #13
RE: Detect which terrain material level underneath?
Regarding the crash, I knew basically it was something around that. ^^ Just dont know how to formulate it.

Yeah, found out what it was. You clever little devil grin and yeah I facepalmed myself. pfft


Code:
if(Material *m= Game::World.hmMaterial(matrix().pos.xz()))

How could I totally forget Vec2 might use matrix location pfft

Thank you so much!
(This post was last modified: 08-19-2010 10:52 AM by Zervox.)
08-19-2010 10:42 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #14
RE: Detect which terrain material level underneath?
You're welcome grin
08-19-2010 07:39 PM
Find all posts by this user Quote this message in a reply
Post Reply