Originally Posted by Jstylezzz
I wrote a little stock function for this a while ago, I placed some comments in the code as well, so that people would be able to understand it.
I normally don't give out pre-made code because people might not learn anything from it, but since this code has a lot of explanation, and is quite advanced to explain step by step, here you go.
PHP код:
//Change object material function snippets -- By Jstylezzz (http://forum.sa-mp.com/member.php?u=1401...1.49346267 #define MAX_CREATED_OBJECTS 4 //Amount of objects in total, add one extra for the NULL, CHANGE TO AMOUNT OF OBJECTS OF PROJECT (put this after your includes, and BEFORE the variable declarations)
new Object[MAX_CREATED_OBJECTS]; //Will hold the actual object
new ObjectModel[MAX_CREATED_OBJECTS]; //Holds the object's model
new ObjectCount; //Keeps track of the number objects created and will be used to assign new object ID's
stock j_CreateDynamicObject(mod,Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz) //Custom function for creating objects
{
Object[ObjectCount] = CreateDynamicObject(mod,x,y,z,rx,ry,rz); //Creates the object with the parameters passed to the stock function
ObjectModel[ObjectCount] = mod; //Assigns the object's model to the object slot, so it can be accessed later on
printf("Created object: %d in object slot: %d", ObjectModel[ObjectCount], Object[ObjectCount]); //For debug, can be removed if you want. This prints the object ID and the object slot in the console
ObjectCount++; //Increases the object count so that the empty object slot comes up for the next time this function is used
}
stock ChangeObjectMaterial(mod, midx, tmod, txdname[], txtrname[], matcolor = 0) //Syntax: ChangeObjectMaterial(object model id, material index, target object model, txd name, texture name, optional: material color)
{
for(new i=0; i < MAX_CREATED_OBJECTS; i++) //Loop through the created objects
{
if(ObjectModel[i] == mod)//Checks if the object ID in the current slot is the same as the model we want to replace
{
SetDynamicObjectMaterial(Object[i],midx, tmod,txdname, txtrname, matcolor); //Changes the object material with the parameters passed to the function
}
}
}
//Now, to create objects just do
j_CreateDynamicObject(objectID, xPos, yPos, zPos, rotX, rotY, rotZ); // The standard CreateDynamicObject function, exactly the same. Only difference is the 'j_' in front of it, so that our custom function is used instead of the normal streamer function, which does not use our custom object slots and all that stuff.
//Now, to change the object material of all objects with a specific object ID
ChangeObjectMaterial(object model id, material index, target object model, txd name, texture name, optional: material color);
I hope it's explained enough. If you need any help please let me know. It should work, I haven't tested it recently though.
Oh yeah, also be sure to have streamer included, otherwise this will not work. If you don't want to use streamer there's an easy workaround which I can also help you with
Good luck, and let me know!
-- I also uploaded this on Pastebin, since viewing it here might be a little small and unclear..
EDIT: I realize this might be quite advanced, maybe a little too advanced for you (guessing you're a beginner scripter). Don't worry about not understanding the code, if you try and don't blindly copy/paste the code, you'll understand soon enough. Only thing I can't say enough, is don't blindly copy/paste
|