Jump to content
Sign in to follow this  
Matosh

setObjectTexture with script

Recommended Posts

I'm trying to put the new texture to the vehicle via script, but I keep getting a script error.

if (typeOf _veh == "LAV25") then {
_veh setVehicleI>
 Error position: <_veh == "LAV25") then {
_veh setVehicleI>
 Error Undefined variable in expression: _veh

if (typeOf _veh == "LAV25") then {
   _veh setVehicleInit "this setObjectTexture [0, ""lav_des_1.paa""]";
   _veh setVehicleInit "this setObjectTexture [1, ""lav_des_2.paa""]";
   processInitCommands;
};

Share this post


Link to post
Share on other sites

from init.sqf ( execVM "lav25des.sqf"; )

Share this post


Link to post
Share on other sites

Yeah but...You need to pass a param to the script...For example:

[name_vehicle] execVM "lav25des.sqf";

and change the script:

_veh = _this select 0;
if (typeOf _veh == "LAV25") then {
   _veh setVehicleInit "this setObjectTexture [0, ""lav_des_1.paa""]";
   _veh setVehicleInit "this setObjectTexture [1, ""lav_des_2.paa""]";
   processInitCommands;
};  

Share this post


Link to post
Share on other sites

[name_vehicle] Do I have to put vehicle classname or ?

Share this post


Link to post
Share on other sites

String comparisons are very expensive and should be avoided whenever possible.

So, instead of

if (typeOf _veh == "LAV25") then {[/Code]

use:

[code]if (_veh isKindOf "LAV25") then {[/Code]

Share this post


Link to post
Share on other sites

But I need the script to put a texture on a vehicle, that will spawn after the player completes the mission.

Share this post


Link to post
Share on other sites

When you spawn a vehicle using createvehicle... the vehicle is returned by createVehicle.

So...

[b][i]_veh[/i][/b] = createVehicle ["LAV25", position player, [], 0, "NONE"] ;

Then call the script "lav25des.sqf" with the returned vehicle...

nul = [[b][i]_veh[/i][/b]] execVM "lav25des.sqf";

lav25des.sqf:-

_veh = _this select 0;

if (_veh isKindOf "LAV25") then {
   _veh setVehicleInit "this setObjectTexture [0, ""lav_des_1.paa""]";
   _veh setVehicleInit "this setObjectTexture [1, ""lav_des_2.paa""]";
   processInitCommands;
};

Edited by twirly
Clarity

Share this post


Link to post
Share on other sites

Sorry i just have a quick question about that, for my personal knowledge.

What's the use of the setVehicleInit in there? Why not simply go with something like

_veh setObjectTexture [1, ""lav_des_2.paa""];

Only idea i have is this would be for some locality issues, but i don't really see the point here.

Share this post


Link to post
Share on other sites

I haven't tested the code.... and have no idea if those lines work or not. I have never used "setObjectTexture". I was simply showing how to get a handle to a spawned object....and then call another script with it. So... you are probably quite right and that part may still need sorting out.

Share this post


Link to post
Share on other sites

Ah alright. Cause i actually use this command sometimes (for stupid adversarial missions, mostly, painting things in blue or red). So i was wondering if the use of setinitvehicle was intentional, in order to achieve another hidden goal.

Cause i know this command is local to the caller in an MP environment.

Share this post


Link to post
Share on other sites
When you spawn a vehicle using createvehicle... the vehicle is returned by createVehicle.

So...

[b][i]_veh[/i][/b] = createVehicle ["LAV25", position player, [], 0, "NONE"] ;

Then call the script "lav25des.sqf" with the returned vehicle...

nul = [[b][i]_veh[/i][/b]] execVM "lav25des.sqf";

lav25des.sqf:-

_veh = _this select 0;

if (_veh isKindOf "LAV25") then {
   _veh setVehicleInit "this setObjectTexture [0, ""lav_des_1.paa""]";
   _veh setVehicleInit "this setObjectTexture [1, ""lav_des_2.paa""]";
   processInitCommands;
};

So for example: player completes a mission, as reward he gets LAV-25, the moment when the vehicle is created script should put custom texture. Will this happen with your code, in your last message?

Share this post


Link to post
Share on other sites

Well, yeah, it should probably happen. You need to know when and how you're gonna call the script though.

So if you're thinking about adding this to a custom mission you're making, shouldn't be much harder than that (except, probably don't create the LAV on the player position. Don't even use player if you're in a multiplayer environment).

If you're thinking about adding it to domination, though,as i suspect, you'd better go to the appropriated thread to ask how to do that.

Edited by BlackMamb

Share this post


Link to post
Share on other sites

If you want the texture just on one vehicle, then as twirly has guided you, you must run the setObjectTexture EVERY time you spawn a the LAV25, in the code immediately after spawning it.

Share this post


Link to post
Share on other sites
Well, yeah, it should probably happen. You need to know when and how you're gonna call the script though.

So if you're thinking about adding this to a custom mission you're making, shouldn't be much harder than that (except, probably don't create the LAV on the player position. Don't even use player if you're in a multiplayer environment).

If you're thinking about adding it to domination, though,as i suspect, you'd better go to the appropriated thread to ask how to do that.

Yes im doing it for domination, but that doesnt mean i have to go to domination thread. I created this thread for script help.

Gnat;2172880']If you want the texture just on one vehicle' date=' then as twirly has guided you, you must run the setObjectTexture EVERY time you spawn a the LAV25, in the code immediately after spawning it.[/quote']

Actually i was thinking to do on 2 more vehicles.

_veh = createVehicle ["LAV25", whateverposition, [], 0, "NONE"];

This code should create a vehicle on whateverposition and script should put the textures on it, right? But another script will handle creating the vehicle (forgot to mention it on my previous message) so i need a script that will check for the designated vehicle and if vehicle is present, script should put textures on it or with addaction, player enters a vehicle > scroll down and select "Paint Vehicle", script is executed and puts texutes on it.

Im beginner in this so here is an example, its probably not correct but it should give you idea.

As i mentioned above that im doing this on domination, im going to post some domination thing here but i just wanted to show example how can script be executed and still im gonna need help with this script. I was thinking like this

i_client.sqf

GVAR(action_menus_vehicle) = [
    [["LAV25"],"Put desert camo", "scripts\lav25des.sqf", -1000]
];

lav25des.sqf

_veh = _this select 0;
_caller = _this select 1;
_id = _this select 2;

_veh setVehicleInit "this setObjectTexture [0, ""pics\lav_des_1.paa""]";
_veh setVehicleInit "this setObjectTexture [1, ""pics\lav_des_2.paa""]";
processInitCommands;
_veh removeaction _id;

Edited by matosinec

Share this post


Link to post
Share on other sites

No, i believe you misunderstood me. I was not saying you should have asked that texture question in the domination thread, but that you should go ask there, unless you know that already of course, where exactly to call that script.

Sorry if i came out offensive.

Share this post


Link to post
Share on other sites

No problem, yeah i believe i misunderstood you. I already searched for it but no luck also if i ask there im not sure will someone reply so...

Share this post


Link to post
Share on other sites

_veh = _this select 0;
_caller = _this select 1;
_id = _this select 2;

_veh setVehicleInit "this setObjectTexture [0, ""pics\lav_des_1.paa""]";
_veh setVehicleInit "this setObjectTexture [1, ""pics\lav_des_2.paa""]";
processInitCommands;
_veh removeaction _id;

This actually works, but i got one question. When player is in vehicle and puts new textures will another player see it ?

Share this post


Link to post
Share on other sites
setVehicleInit ... processInitCommands

My understanding (from BIKI) is thats exactly what those 2 commands are to ensure, all clients get the same info, but I'm no expert in the area.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×