[Tutorial] Transparent/Invisible Objects
#1

Transparent/Invisible Objects
Now supports almost every SA-MP Objects!

Introduction


Hello,
I think many of you've been searching for invisible object textures. I was also at the same situation but right now, I don't want any types of invisible texture name because right now, I've found an easy method to make objects invisible. This can also give rise to many new cool features like just spray paint systems because transparent texts can be now created.

I've searched around the forum and noticed that no one brought up this idea. I just discovered it right now and don't know if it could lead to any problems. But as far as I tested, it works fine.



Tutorial


This tutorial is simple. I'll be also explaining how to create Transparent Texts. But at first, let's get to the tutorial of Invisible Objects. On this tutorial, we'll be using the function SetObjectMaterial but the interesting thing is that we don't want any textures to do it.

Invisible Objects

Suppose that a filterscript is being created and I'm gonna use Filterscript related callbacks.

pawn Код:
#define FILTERSCRIPT

#include <a_samp> //Including a_samp, without this nothing related to the tutorial would work.

new
    myObject; //Declaring a variable to store the object ID we're creating, for setting it's textures.

public OnFilterScriptInit()
{
    //You can create any object you want, here, I'm gonna use object ID : 4238 as it's good for banners.
    CreateObject(4238,  -1488.81335, 665.62158, 23.60941, 0.0, 0.0, 0.0);
    //No, it's not over. Look below
    return 1;
}
As you can see, I've created the object on coordinates ( -1488.81335, 665.62158, 23.60941). This tutorial not using any textures to link up with this object to make it invisible. Other than that, alpha color codes are being used.

• SetObjectMaterial - Parameters:
objectid The ID of the object to change the texture of
materialindex The material index on the object to change
modelid The modelid on which the replacement texture is located. Use 0 for alpha. Use -1 to change the material color without altering the texture.
txdname The name of the txd file which contains the replacement texture (use "none" if not required)
texturename The name of the texture to use as the replacement (use "none" if not required)
materialcolor The object color to set, as an integer or hex in ARGB color format. Using 0 keeps the existing material color.
(Taken from SA-MP wiki)

As it says, we can keep modelid to 0 as we're using alpha. And mention the txdname and texture name to "none". materialcolor will be the place where we type our color code, here we're setting it to 0x00000000 (0).
MaterialIndex - This means the index ID of the material in a model. Sometimes, the model may have two different type of textures. It means that it got two slots of materialindex. You need to set every material index of that object to make it transparent then!

pawn Код:
#include <a_samp> //Including a_samp, without this nothing related to the tutorial would work.

new
    myObject; //Declaring a variable to store the object ID we're creating, for setting it's textures.

public OnFilterScriptInit()
{
    //You can create any object you want, here, I'm gonna use object ID : 4238 as it's good for banners.
    myObject = CreateObject(4238,  -1488.81335, 665.62158, 23.60941, 0.0, 0.0, 0.0);
    //I've already told above that some objects may have more than 1 material, so loop about 10 times and set the material as it differs on some objects.
    //NOTE : It doesn't crash as far as I've tested!
    for(new i; i< 10; i++) SetObjectMaterial(myObject, i, 0, "none", "none", 0x00000000);
    return 1;
}
And yes! You're done with creating invisible objects.

Transparent Texts

EDIT : HOLD ON, I just realized that you could do it much easily be setting the 'backcolor' parameter to 0 on 'SetObjectMaterialText'.

Old one :
Just like you did before, after setting the object's material, do the function SetObjectMaterialText and it will render as transparent logo.

pawn Код:
#include <a_samp> //Including a_samp, without this nothing related to the tutorial would work.

new
    myObject; //Declaring a variable to store the object ID we're creating, for setting it's textures.
public OnFilterScriptInit()
{
    //You can create any object you want, here, I'm gonna use object ID : 4238 as it's good for banners.
    myObject = CreateObject(4238,  -1488.81335, 665.62158, 23.60941, 0.0, 0.0, 0.0);
    for(new i; i< 10; i++)
    SetObjectMaterial(myObject, i, 0, "none", "none", 0x00000000);
    SetObjectMaterialText(myObject, "LORDZ"); //Check out the screens below to know well.
    return 1;
}

Quick Functions


I've created some functions to ease the work in creating transparent objects.
pawn Код:
stock CreateTransparentObject(modelid, Float:X, Float:Y, Float:Z, Float:rX=0.0, Float:rY=0.0, Float:rZ=0.0) {
    new obj_ID = CreateObject(modelid, X, Y, Z, rX, rY, rZ);
        for(new i; i< 10; i++)
        SetObjectMaterial(obj_ID, i, 0, "none", "none", 0x00000000);
    return obj_ID;
}

stock CreateTransparentLogo(logo[], Float:X, Float:Y, Float:Z, size=OBJECT_MATERIAL_SIZE_256x128, fontface[] = "Arial", fontsize=24, bold=1, fontcolor=0xFFFFFF, backcolor=0, textalignment=0) {
    new obj_ID = CreateObject(4238, X, Y, Z, 0.0, 0.0, 0.0);
    SetObjectMaterial(obj_ID, 0, 0, "none", "none", 0x00000000);
    SetObjectMaterialText(obj_ID, logo, 0, size, fontface, fontsize, bold, fontcolor, backcolor, textalignment);
    return obj_ID;
}
Here's a small test filterscript.
pawn Код:
#define FILTERSCRIPT

#include <a_samp>

new myOBJ;
stock CreateTransparentObject(modelid, Float:X, Float:Y, Float:Z, Float:rX=0.0, Float:rY=0.0, Float:rZ=0.0) {
    new obj_ID = CreateObject(modelid, X, Y, Z, rX, rY, rZ);
        for(new i; i< 10; i++)
    SetObjectMaterial(obj_ID, 0, 0, "none", "none", 0x00000000);
    return obj_ID;
}

stock CreateTransparentLogo(logo[], Float:X, Float:Y, Float:Z, size=OBJECT_MATERIAL_SIZE_256x128, fontface[] = "Arial", fontsize=24, bold=1, fontcolor=0xFFFFFF, backcolor=0, textalignment=0) {
    new obj_ID = CreateObject(4238, X, Y, Z, 0.0, 0.0, 0.0);
    SetObjectMaterial(obj_ID, 0, 0, "none", "none", 0x00000000);
    SetObjectMaterialText(obj_ID, logo, 0, size, fontface, fontsize, bold, fontcolor, backcolor, textalignment);
    return obj_ID;
}

public OnFilterScriptInit() {
    myOBJ = CreateObject(4238, -1488.81335, 665.62158, 23.60941,   0.00000, 0.00000, 258.30008);
    SetObjectMaterial(myOBJ, 0, -1, "none", "none", 0x00000000);
    SetObjectMaterialText(myOBJ, "LORDZ", 0, OBJECT_MATERIAL_SIZE_512x128,\
    "Arial", 40, 0, 0xFFFF8200, 0xFF000000, OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[]) {
    if(!strcmp(cmdtext, "/texture")) {
        DestroyObject(myOBJ);
        myOBJ = CreateObject(4238, -1488.81335, 665.62158, 23.60941,   0.00000, 0.00000, 258.30008);
        SetObjectMaterial(myOBJ, 0, 0, "none", "none", 0x00000000);
        return SetObjectMaterialText(myOBJ, "LORDZ", 0, OBJECT_MATERIAL_SIZE_512x128, "Arial", 40, 0, 0xFFFF8200, 0, OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
    }
    return 0;
}
Type "/texture" to make the logo transparent.


Pictures


- Non-Transparent logo "LORDZ".


- Transparent logo "LORDZ"


- The object's texture only goes transparent, yet the object still remains solid and I'm standing at an invisible object.



Conclusion


This was just a tutorial in relating to setting an object's texture to make it invisible or transparent. For setting the object's material, each materialindex slot has to be set with the texture you desire with. Or else it may not work on objects which got multiple textures. To do it in a quicker method as finding all the materialindex would take a lot of time, just run a loop about 10 or more and then use those slots to set the object's Material. AFAIK, it won't crash in case if the slots are not used by the object originally.

And to create transparent texts, just set the backcolor parameter on SetObjectMaterialText to 0.

NOTE : 1) This tutorial works well only for SA-MP's normal object streamer. I've faced some problems when I'm setting textures on Incognito's Streamer. So if anyone experiences such issues, depend the Streamer's creator.
2) Sometimes, the object could also go transparent in case if you're passing out an empty string on SetObjectMaterialText with the backcolor parameter set to 0 (Not sure about every objects). But that may not suit in case if you're planning of a system where player must not have any idea about the object or stuffs. SetObjectMaterialText will first display the object and then get it transparent.

And that's the end of the tutorial. Suggestions or feed backs are always welcome. Note that by changing fonts on SetObjectMaterialText, you can even create more systems like your own custom spray tags and much more which would look realistic.



Regards,
Lordzy.
Reply
#2

Awesome
Reply
#3

I don't see which such a complex function such as HexToInt is needed. Hex are numbers in it's hexadecimal format, while ints are numbers in their entire (Z) format; Both will work, and it's actually way easier to read and understand colors in their hex format, rather than their integer format.
Reply
#4

Quote:
Originally Posted by CuervO
Посмотреть сообщение
I don't see which such a complex function such as HexToInt is needed. Hex are numbers in it's hexadecimal format, while ints are numbers in their entire (Z) format; Both will work, and it's actually way easier to read and understand colors in their hex format, rather than their integer format.
My apologies, at first I misread SA-MP wiki while I was fetching for an idea to make object textured to transparent. That's why I've converted Alpha codes to integers to get it performed. I'm still finding to create accurate methods on which transparency would get performed on every objects.
Reply
#5

Quote:
Originally Posted by Lordz™
Посмотреть сообщение
My apologies, at first I misread SA-MP wiki while I was fetching for an idea to make object textured to transparent. That's why I've converted Alpha codes to integers to get it performed. I'm still finding to create accurate methods on which transparency would get performed on every objects.
Well... Since it's ARGB, 0x00RRGGBB will do the trick to make the alpha 00 and transparent. In these cases the alpha is moved from the last two to the first two. 0x00000000 will give a complete transparency too. If it's transparent then no colors will be displayed... (0x00000000 = dec 0)
Reply
#6

This is useful, job well done!
Reply
#7

Nice, but it would be nice if the 'black' was walk through.
Reply
#8

That is quite good explained tutorial. I was unsure about the transparency codes with material object but this will be easy for me now.
Reply
#9

Quote:
Originally Posted by CuervO
Посмотреть сообщение
Well... Since it's ARGB, 0x00RRGGBB will do the trick to make the alpha 00 and transparent. In these cases the alpha is moved from the last two to the first two. 0x00000000 will give a complete transparency too. If it's transparent then no colors will be displayed... (0x00000000 = dec 0)
Haven't tried that, but I may, later.

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
This is useful, job well done!
Thanks.

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
Nice, but it would be nice if the 'black' was walk through.
Thanks, but what did you mean by 'black'?

Quote:
Originally Posted by iZN
Посмотреть сообщение
That is quite good explained tutorial. I was unsure about the transparency codes with material object but this will be easy for me now.
Thanks, I'm glad that it helps you.
Reply
#10

What about objects with multiple materials ? You need to set transparency to them all just not the first material!
Reply
#11

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
What about objects with multiple materials ? You need to set transparency to them all just not the first material!
If you've read the topic well, I've told at the very beginning that it supports 4238 model only for now. I'll be updating the tutorial soon enough.

EDIT:
About objects with multiple materials, I did a loop through material index IDs and it seems like Streamer confused me always. It works even if the slots don't exist on normal objects, but on Streamer ones, it seems like it creates some problems.

I've updated the tutorial, thanks for your post.


OT:
Tutorial updated, now it supports almost every objects.
Reply
#12

Thanks, you just saved me.
Reply
#13

Quote:
Originally Posted by Lordz™
Посмотреть сообщение
Haven't tried that, but I may, later.



Thanks.



Thanks, but what did you mean by 'black'?



Thanks, I'm glad that it helps you.
The stuff that turned invisible, I wish that was walk through, instead of 'invisible' solid.
Reply
#14

Useful, good job Lordz
Reply
#15

Quote:
Originally Posted by Rube
Посмотреть сообщение
Thanks, you just saved me.
You're welcome, I'm glad that it helped you.
Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
The stuff that turned invisible, I wish that was walk through, instead of 'invisible' solid.
Oh well, it doesn't get the object to be just a texture.

Quote:
Originally Posted by LeGGGeNNdA
Посмотреть сообщение
Useful, good job Lordz
Thanks.
Reply
#16

Nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice mods of graphics!
And nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice nice tutorial , excellent work!
Reply
#17

Awesome Good-Job Lordz
Reply
#18

I realize this reply comes a bit late, but nevertheless: HexToInt is completely useless here. Hexadecimal numbers are, in fact, integers! The only time you'd use this function (or sscanf's equivalent "x" specifier) is when you'd need to convert a string representation from an input source, such as a command parameter or dialog inputtext.
Reply
#19

This is useful in any kind of server. I will use it too. Thanks
Reply
#20

Quote:
Originally Posted by Vince
Посмотреть сообщение
I realize this reply comes a bit late, but nevertheless: HexToInt is completely useless here. Hexadecimal numbers are, in fact, integers! The only time you'd use this function (or sscanf's equivalent "x" specifier) is when you'd need to convert a string representation from an input source, such as a command parameter or dialog inputtext.
It was actually used because the ARGB color was being used to get it transparent and I've also told it on the replies here. I wrote this tutorial the moment I discovered an easier method to get object transparent as such a method was wanted by many of the users here as well as me before.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)