SetObjectMaterial help!
#3

Quote:
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...2.55723215
#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(modmidxtmodtxdname[], txtrname[], matcolor 0//Syntax: ChangeObjectMaterial(object model id, material index, target object model, txd name, texture name, optional: material color)
{
    for(new 
i=0MAX_CREATED_OBJECTSi++) //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],midxtmod,txdnametxtrnamematcolor); //Changes the object material with the parameters passed to the function
          
}
    }
}
//Now, to create objects just do
j_CreateDynamicObject(objectIDxPosyPoszPos,   rotXrotYrotZ); // 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 idmaterial indextarget object modeltxd nametexture nameoptionalmaterial 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
First of all thank you, but when I compile I get these errors
Код:
error 017: undefined symbol "ObjectModel"
error 017: undefined symbol "Object"
P.S. I have changed your "SetDynamicObjectMaterial" in "SetObjectMaterial".
Reply


Messages In This Thread
SetObjectMaterial help! - by FreddiewJO - 20.07.2015, 13:29
Re: SetObjectMaterial help! - by Jstylezzz - 20.07.2015, 14:05
Re: SetObjectMaterial help! - by FreddiewJO - 20.07.2015, 18:27
Re: SetObjectMaterial help! - by Jstylezzz - 21.07.2015, 11:14
Re: SetObjectMaterial help! - by FreddiewJO - 21.07.2015, 12:29
Re: SetObjectMaterial help! - by Glenn332 - 21.07.2015, 12:39
Re: SetObjectMaterial help! - by FreddiewJO - 21.07.2015, 12:47
Re: SetObjectMaterial help! - by Glenn332 - 21.07.2015, 12:50
Re: SetObjectMaterial help! - by FreddiewJO - 21.07.2015, 13:01
Re: SetObjectMaterial help! - by Jstylezzz - 21.07.2015, 13:44

Forum Jump:


Users browsing this thread: 1 Guest(s)