02.02.2014, 03:53
(
Последний раз редактировалось Lordzy; 01.05.2016 в 04:30.
Причина: Updated the tutorial with almost supporting every objects
)
Transparent/Invisible Objects
Now supports almost every SA-MP 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;
}
• SetObjectMaterial - Parameters:
objectid The ID of the object to change the texture of(Taken from SA-MP wiki)
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.
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;
}
• 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;
}
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;
}
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.