SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 02/02/2014, 04:53 AM   #1
Lordzy
High-roller
 
Lordzy's Avatar
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,703
Reputation: 1176
Default Transparent/Invisible Objects

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 Code:
#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 Code:
#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 Code:
#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 Code:
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 Code:
#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.
__________________
Currently inactive - I don't play at any SA-MP servers nor work on anything in PAWN for now. The projects that I've done so far in PAWN, which requires updates will be taking some time.

Last edited by Lordzy; 01/05/2016 at 05:30 AM. Reason: Updated the tutorial with almost supporting every objects
Lordzy is offline   Reply With Quote
Old 02/02/2014, 04:55 AM   #2
Odedara
Big Clucker
 
Odedara's Avatar
 
Join Date: Feb 2013
Location: Earth
Posts: 88
Reputation: 5
Default Re: Transparent/Invisible Objects

Awesome
Odedara is offline   Reply With Quote
Old 02/02/2014, 06:12 AM   #3
CuervO
High-roller
 
CuervO's Avatar
 
Join Date: Oct 2008
Posts: 1,164
Reputation: 200
Default Re: Transparent/Invisible Objects

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.
__________________
[IMG]http://************/pdpu4qe[/IMG]    - Team Fortress 2 [Gamemode] [SQL] [Whirlpool] [Streamer] [Sscanf] [ZCMD]
[IMG]http://************/pdpu4qe[/IMG] - Live map object editor [Filterscript] [DINI] [Streamer] [Sscanf] [ZCMD]
[img]http://************/pdpu4qe[/img] [img]http://************/nfxrrrz[/img] - Inventory & Object System [Filterscript] [SQL] [Streamer] [Sscanf] [ZCMD]

- RenderMessage(toAll) [Snippet]
CuervO is offline   Reply With Quote
Old 02/02/2014, 06:16 AM   #4
Lordzy
High-roller
 
Lordzy's Avatar
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,703
Reputation: 1176
Default Re: Transparent/Invisible Objects

Quote:
Originally Posted by CuervO View Post
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.
__________________
Currently inactive - I don't play at any SA-MP servers nor work on anything in PAWN for now. The projects that I've done so far in PAWN, which requires updates will be taking some time.
Lordzy is offline   Reply With Quote
Old 02/02/2014, 07:06 AM   #5
CuervO
High-roller
 
CuervO's Avatar
 
Join Date: Oct 2008
Posts: 1,164
Reputation: 200
Default Re: Transparent/Invisible Objects

Quote:
Originally Posted by Lordz™ View Post
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)
__________________
[IMG]http://************/pdpu4qe[/IMG]    - Team Fortress 2 [Gamemode] [SQL] [Whirlpool] [Streamer] [Sscanf] [ZCMD]
[IMG]http://************/pdpu4qe[/IMG] - Live map object editor [Filterscript] [DINI] [Streamer] [Sscanf] [ZCMD]
[img]http://************/pdpu4qe[/img] [img]http://************/nfxrrrz[/img] - Inventory & Object System [Filterscript] [SQL] [Streamer] [Sscanf] [ZCMD]

- RenderMessage(toAll) [Snippet]
CuervO is offline   Reply With Quote
Old 02/02/2014, 07:11 AM   #6
DaniceMcHarley
High-roller
 
DaniceMcHarley's Avatar
 
Join Date: Feb 2012
Location: www.finalnights-rp.com
Posts: 1,741
Reputation: 95
Default Re: Transparent/Invisible Objects

This is useful, job well done!
DaniceMcHarley is online now   Reply With Quote
Old 02/02/2014, 09:17 AM   #7
Kyle
High-roller
 
Kyle's Avatar
 
Join Date: Mar 2009
Location: United Kingdom
Posts: 2,263
Reputation: 330
Default Re: Transparent/Invisible Objects

Nice, but it would be nice if the 'black' was walk through.
__________________
Kyle is offline   Reply With Quote
Old 02/02/2014, 11:11 AM   #8
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,378
Reputation: 569
Default Re: Transparent/Invisible Objects

That is quite good explained tutorial. I was unsure about the transparency codes with material object but this will be easy for me now.
__________________
iZN is offline   Reply With Quote
Old 03/02/2014, 03:03 AM   #9
Lordzy
High-roller
 
Lordzy's Avatar
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,703
Reputation: 1176
Default Re: Transparent/Invisible Objects

Quote:
Originally Posted by CuervO View Post
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 View Post
This is useful, job well done!
Thanks.

Quote:
Originally Posted by KyleSmith View Post
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 View Post
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.
__________________
Currently inactive - I don't play at any SA-MP servers nor work on anything in PAWN for now. The projects that I've done so far in PAWN, which requires updates will be taking some time.
Lordzy is offline   Reply With Quote
Old 03/02/2014, 12:51 PM   #10
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,847
Reputation: 1312
Default Re: Transparent/Invisible Objects

What about objects with multiple materials ? You need to set transparency to them all just not the first material!
Pottus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transparent Objects 0.3e gigz Scripting Help 11 28/06/2012 01:59 PM
Transparent Objects r0v3r Help Archive 6 12/06/2011 01:23 PM
Created Objects are transparent or Invisible paulj Help Archive 3 10/05/2011 08:23 PM
Transparent objects LeNy Help Archive 13 22/12/2010 03:21 PM
Sa-mp 0.3b transparent objects SilverSink Help Archive 12 21/08/2010 09:12 PM


All times are GMT. The time now is 12:41 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.