SA-MP Forums Archive
[Tutorial] SetObjectMaterial Help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] SetObjectMaterial Help (/showthread.php?tid=331497)

Pages: 1 2


SetObjectMaterial Help - Drebin - 05.04.2012

Intro

With this thread I will try to help you on how to replace the texture on an object and make you understand how it works.
SetObjectMaterial has 6 parameters:

objectidThe ID of the object you want to change the texture of
materialindexThe index of the part of the object you want to change
modelidThe ID of the model which shoulders the texture
txdnameThe name of the .txd file in which the new texture is saved in
texturenameThe name of the new texture
materialcolorThe colour the texture should have
The best way to find the name and the directory of a texture is by using JernejL's Map Editor. I will build my tutorial on this program. I strongly recommend you to use it


Getting started

First of all you have to decide which texture you want to put onto the object and which object carries this texture. I decided to take the texture of object ID 19341, which is an egg object with stripes on it (added in 0.3d). We will now start to build up our function step by step.
Our first parameter is the objectid. You simply put the ID of the object you want to change here:
pawn Код:
new myobject;
myobject = CreateObject(8397, 2067.94, 1362.22, 19.90,   0.00, 0.00, 0.00);
SetObjectMaterial(myobject, ?, ?, ?, ?, ?);
Next is the materialindex. Now you need to open JernejL's Map Editor and create the object you want to change the texture of, in my situation it'd be the obelisk from LV (ID 8397). When you created the object, doubleclick it.
You now see a window with infos on the object ID. The important thing for now is the "Model textures" box.

This box shows all textures an object has. You now have to decide on which texture you want to change, I pick the first texture in the list, which would be the index 0. Now we add this to our function:
pawn Код:
SetObjectMaterial(myobject, 0, ?, ?, ?, ?);
If you want to change the second texture, your index would be 1. Some object only have one texture on them, which makes it pretty easy for you, because then the index is always 0.

Next is the modelid. This is simply the model ID of the object which has the texture you want to put on your new object on it, in my situation it's the ID of the egg (ID 19341). We complete:
pawn Код:
SetObjectMaterial(myobject, 0, 19341, ?, ?, ?);
Now we have to find the txdname. For this we use our map editor again. Create the object with the texture you want (NOT the object which you want to change the texture of, now you need the object which has the texture alredy on it) and doubleclick it.

Now look at the box beside "Texture". This is the file the texture you want is saved in, for me it is "egg_texts".
pawn Код:
SetObjectMaterial(myobject, 0, 19341, "egg_texts", ?, ?);
For the next step you simply have to look at the box below it, right beside "TXD textures". These are the different textures that are inside the texture file you just found out ("egg_texts" in this example). You now have to pick the name of the texture you want to put on your object. Which name the texture you want has can not be said, the only way to find out if you picked the right texture name is by trying it out. I pick texture "easter_egg01"
Our function now looks like this:
pawn Код:
SetObjectMaterial(myobject, 0, 19341, "egg_texts", "easter_egg01", ?);
The next and last parameter is the colour you want to paint the texture as, in a ABGR value (NOT RGBA). I pick 0 because "0" keeps the original colours of the texture.
pawn Код:
SetObjectMaterial(myobject, 0, 19341, "egg_texts", "easter_egg01", 0);
If you want to convert colours in RGBA format (used in SendClientMessage for example) to ABGR, you can use this function (made by Kar):
pawn Код:
stock ShiftRGBAToABGR(&color)
{
    new r, g, b, a;
    r = (color >>> 24);
    g = (color >>> 16 & 0xFF);
    b = (color >>> 8 & 0xFF);
    a = (color  & 0xFF);
    color = (a & 0xFF) | ((b & 0xFF) << 8) | ((g & 0xFF) << 16) | (r << 24);
    return color;
}
If you did nothing wrong, your object should now have a new texture. My obelisk (ID 8397) has now the texture of an egg (ID 19341)



I hope you now understand how this works. This tutorial isn't supposed to show you perfectly what to do, I made it so you know where to search for the parameters . And I hope you're not more confused than you were before

~Drebin


Re: SetObjectMaterial Help - steki. - 05.04.2012

Zamaroth's Map Editor


AW: Re: SetObjectMaterial Help - Drebin - 05.04.2012

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
Zamaroth's Map Editor
Where?


Re: SetObjectMaterial Help - CJoao - 05.04.2012

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
Zamaroth's Map Editor
Thx


Re: SetObjectMaterial Help - Luis- - 05.04.2012

What is wrong with this?
pawn Код:
CMD:test(playerid, params[])
{
    new myobject;
    myobject = CreateObject(8397, 3629, 2112.9375, -2384.6172, 18.8828, 0.25);
    SetObjectMaterial(myobject, 0, 19341, "egg_texts", "easter_egg01", 0xFFFFFFFF);
    return 1;
}
Nice tutorial by the way


AW: Re: SetObjectMaterial Help - Drebin - 05.04.2012

pawn Код:
CreateObject(8397, 3629, 2112.9375, -2384.6172, 18.8828, 0.25);
//            ID     ?       X           Y         Z       ?
Thats the flaw :P


Re: SetObjectMaterial Help - Luis- - 05.04.2012

Would I just be able to change the colour of the object? For example, can I change the sphinx to red instead of having a texture on it.


Re: SetObjectMaterial Help - Kar - 05.04.2012

Quote:
Originally Posted by -Luis
Посмотреть сообщение
Would I just be able to change the colour of the object? For example, can I change the sphinx to red instead of having a texture on it.
Yes, find the objectid of the sphinx, goto JernejL's map editor, add it, double click on it and use the sphinx's textures.


or I think using "none", "none" should work.


AW: SetObjectMaterial Help - Drebin - 05.04.2012

Try a transparent texture (alpha) and set the color in SetObjectMaterial to red.
https://sampwiki.blast.hk/wiki/SetObjectMaterial


Re: SetObjectMaterial Help - Luis- - 05.04.2012

Here's my code,
pawn Code:
SetObjectMaterial(myobject, 0, 0, "none", "none", COLOR_RED);
It's not working, so I presume you can't do it.


AW: SetObjectMaterial Help - Drebin - 05.04.2012

But you can still place a red texture on it :P


Re: SetObjectMaterial Help - Kar - 05.04.2012

Quote:
Originally Posted by -Luis
View Post
Here's my code,
pawn Code:
SetObjectMaterial(myobject, 0, 0, "none", "none", COLOR_RED);
It's not working, so I presume you can't do it.
Your using 0 for your model id.


Re: SetObjectMaterial Help - Psymetrix - 05.04.2012

I recommend using TXD Workshop to view the textures if your not quite sure which one you want to change.

Kar, Perhaps you could add a little explanation on how to find what texture your looking for using TXD Workshop? It has definitely helped me.




Re: SetObjectMaterial Help - Libra_PL - 05.04.2012

Very good tutorial, helped me a lot. But the only bad thing, if I change an object's texture, it's always very dark. The code I'm using is:

pawn Code:
for(new i = 0; i < 25; i++)
{
    SetObjectMaterial(Platform[i],0,19400,"all_walls","desgreengrass",0xFFFFFFFF);
}
It replaces an object ID 3095 floor (that platform from Area 51, which was opening to fly away with a jetpack) to grass, it looks good at night, but if it's day, it's very dark or in some weather IDs (for example 0 and 1) it's completely black. Is there any chance to make it look like normal (like a picture of texture in TXD workshop)? I was trying to change the materialindex, transparency did nothing, if I change a color (for example from white to green), the texture disappears.


AW: SetObjectMaterial Help - C0dy09 - 05.04.2012

Hi, Iґve found out that if you open samp.ide in your gta folder, that

19317, bassguitar01, bassguitar01, 100, 0
modelid , txdname ,texturename

so this is working with materialindex = 0

but if there is something with

19323, lsmall_shop01, lsmall_shops, 200, 0

it doesnґt work. All objects in this file that arenґt have a "100" doenґt work.
How can i slove this?


AW: SetObjectMaterial Help - Drebin - 05.04.2012

Have you tried different materialindexes?


AW: SetObjectMaterial Help - C0dy09 - 05.04.2012

yes 0-2 and 200

//edit: but doesnґt work


Re: SetObjectMaterial Help - Kar - 05.04.2012

Please, you guys are mixing up colours.

use this function to convert colours to the object material format.

pawn Code:
stock ShiftRGBAToABGR(&color)
{
    new r, g, b, a;
    r = (color >>> 24);
    g = (color >>> 16 & 0xFF);
    b = (color >>> 8 & 0xFF);
    a = (color & 0xFF);
    color = (a & 0xFF) | ((b & 0xFF) << 8) | ((g & 0xFF) << 16) | (r << 24);
    return color;
}



Re: SetObjectMaterial Help - Gireada - 07.04.2012

Original object that you deleted?


Re: SetObjectMaterial Help - Dude_Lebowski - 12.06.2012

pawn Code:
public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp(cmdtext,"/mycommand",true))
    {
    new myobject;
    myobject = CreateObject(777, 1490.29, 2595.46, 10.06, 0.00, 0.00, 0.00); // treee
    SetObjectMaterial(myobject, 0, 19128, "dancefloors", "dancefloor1", 0);
    return 1;
    }
    return 0;
}
and i get 1 error and 1 warrning

SOMEONE HELP PLEASE !


C:\Documents and Settings\Admin\Desktop\samp 0.3e\filterscripts\tree.pwn(1 : error 017: undefined symbol "SetObjectMaterial"
C:\Documents and Settings\Admin\Desktop\samp 0.3e\filterscripts\tree.pwn(17) : warning 204: symbol is assigned a value that is never used: "myobject"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.

when i #define SetObjectMaterial i get 2 warrnings


C:\Documents and Settings\Admin\Desktop\samp 0.3e\filterscripts\tree.pwn(1 : warning 215: expression has no effect
C:\Documents and Settings\Admin\Desktop\samp 0.3e\filterscripts\tree.pwn(17) : warning 204: symbol is assigned a value that is never used: "myobject"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


2 Warnings.