Jump to content
Erwin23p

(Solved, new problem)TypeOf not working well?

Recommended Posts

Hello, I'm trying to do a script where just a certain class of vehicles can acces.

I have an Array with the classnames:

Spoiler

Supported_Vehicles_MID = ["C_Offroad_01_F","C_SUV_01_F","C_Offroad_02_unarmed_F"];

 

then, I have another array in which the vehicles on the map that correspond to that type of classname are added to this other array.

Well my problem is when the script adds the desired vehicles to the new array, they don't get in the array as the classname, but as the .p3d file and some random numbers.

Share this post


Link to post
Share on other sites

You need to add the classname of the objects to your array.

 

It sounds like you are adding a string of the object itself to array

 

{Supported_Vehicles_MID pushBackUnique typeof _x} forEach _allMyVehiclesOnTheMap

 

  • Like 1

Share this post


Link to post
Share on other sites

Can I use this with "vehicles"? I'm not sure but I think that word uses all the vehicles on the map.

Share this post


Link to post
Share on other sites

Well, I'm finishing some tweaking and I'm going to try right now I think that I was doing that wrong, I thought I could have more than one (for example) jeep in that array, but I can only have 1 classname per each vehicle, even if I have 1000 jeeps on the map. :face_palm:

 

The important thing, is that when adding the vehicle to the array, I have an _x that also run some functions, and my objectives is that this function works on all the desired vehicles on the map, I'm going to try and I tell you if now it works.

 

Thanks for the help, I've have not realized what was I doing wrong.

Share this post


Link to post
Share on other sites

Well, coming back to the first problem, I have that code that executes an .sqf to all the vehicles with these classnames now here I have that .sqf:

Spoiler

_veh = _this select 0;
_veh_type = (typeOf _veh);

	Supported_Vehicles_ALL = ["C_Offroad_01_F","C_SUV_01_F","C_Offroad_02_unarmed_F"];
	
if (_veh_type in Supported_Vehicles_ALL) then
{
	_veh setDammage 1;
};

 

Well, when all the codes finishes to work, any of the vehicles explodes...

Share this post


Link to post
Share on other sites
Spoiler

Just copy the full code in a spoiler. There is no error on these lines.

 

  • Like 1

Share this post


Link to post
Share on other sites

Would be helpful to know what you're actually trying to achieve with that script.

 

If you just want to destroy all vehicles on the map that match certain classnames then there are several options to do so. Like this one:

Supported_Vehicles_ALL = ["C_Offroad_01_F","C_SUV_01_F","C_Offroad_02_unarmed_F"];
{
	{
		_x setDamage 1;
	} count (allMissionObjects _x);
} count Supported_Vehicles_ALL;

This is probably a bit quicker than using typeOf.

 

  • Like 1

Share this post


Link to post
Share on other sites

Ok I think I solved the problem, now I've got all working.

Well I'm still learning so I'm trying to do scripts about everything for practice, and for a mission I'm working I wanted to create a simple garage script, when approaching the garage door you get an addaction to move inside, and when you're inside another to move outside. Really simple, but I wanted to create i with functions because I've never really knew how to use these, now I know. :)

garage.sqf

Spoiler

//////////////////////////////////////////////////////////////
//		ElcaGarage v0.1										//
//															//
//		USE:												//
//		_elcaGarage = execVM "Scripts\GarageInit.sqf";		//
//															//
//////////////////////////////////////////////////////////////

//	VARIABLES
_veh = _this select 0;
_veh_type = (typeOf _veh);


	Action_Priority = 20;
	
	Max_Speed = 10;
	
	Max_Alt = 3;
	
	//Usage of doors and animation
	//Doors = false:
	
	//Black screen during in or out of garage
	Black_Screen = false;
	
	Move_Points = [Door1, Door2, Parking1, Parking2];
	
	Supported_Vehicles_SMALL = ["C_Quadbike_01_F", "C_Scooter_Transport_01_F"];
	Supported_Vehicles_MID = ["C_Offroad_01_F", "C_SUV_01_F", "C_Offroad_02_unarmed_F"];
	Supported_Vehicles_BIG = ["C_Truck_02_transport_F"];

	Supported_Vehicles_ALL = Supported_Vehicles_SMALL + Supported_Vehicles_MID + Supported_Vehicles_BIG;
	
	
	Elca_move = 
	{
		_obj = _this select 0;
		_move_pos = _this select 1;
		
		if (Black_Screen) then {
		cutText ["","BLACK FADED",2];
		sleep 1;
		};
		if (_obj distance (_move_pos select 0) < 5) then
			{
				_move_pos = _move_pos select 2;
			} else {
			if (_obj distance (_move_pos select 1) < 5) then
				{
					_move_pos = _move_pos select 3;
				} else {
				if (_obj distance (_move_pos select 2) < 5) then
					{
						_move_pos = _move_pos select 0;
					} else { 
					if (_obj distance (_move_pos select 3) < 5) then
						{
							_move_pos = _move_pos select 1;
						}
							}
						}
					};
		_obj setPos (getPos _move_pos);
	};
	
if (_veh_type in Supported_Vehicles_ALL) then
{
	_veh addAction [
	"<t color=""#7FFF00"">Enter left garage</t>",
	{
		[_this select 0, _this select 3] spawn Elca_move;
	},Move_Points,Action_Priority,true,true,"",
	"(_target distance Door1 < 5) && ((speed _target) <= Max_Speed) && (((getPos _target) select 2) <= Max_Alt)"
	];
	
	_veh addAction [
	"<t color=""#7FFF00"">Enter right garage</t>",
	{
		[_this select 0, _this select 3] spawn Elca_move;
	},Move_Points,Action_Priority,true,true,"",
	"(_target distance Door2 < 5) && ((speed _target) <= Max_Speed) && (((getPos _target) select 2) <= Max_Alt)"
	];
	
	_veh addAction [
	"<t color=""#FF0000"">Exit garage</t>",
	{
		[_this select 0,_this select 3] spawn Elca_move;
	},Move_Points,Action_Priority,true,true,"",
	"(_target distance Parking1 < 5) || (_target distance Parking2 < 5)"
	];
};

 

I still have to fix the conditions of the addactions, instead of "Door1", (Move_Points select 0).

Share this post


Link to post
Share on other sites

Hello again, I have a little problem with my garage script: 

Instead of using objects set in the editor for movement and condition references, the script creates two invisible landing pads (one for each door) and from there I use modelToWorld to get diferent positions. Well to get the correct positions relative to the garage object, I went to a empty virtual reallity map and put the object on 0,0,0 and from there I could know the relative position. I use this 

pad1 = "Land_HelipadEmpty_F" createVehicle (_obj modelToWorld [-6.65,-5.75,-2]);	// Left
pad2 = "Land_HelipadEmpty_F" createVehicle (_obj modelToWorld [1.3,-5.75,-2]);		// Right

in the visual reality map it gave me no error but when I moved to the actual mission I'm working on, the two points were not in the same position..

I used two arrows to see that position.

"Sign_Arrow_Blue_F" createVehicle (getPos pad1);
"Sign_Arrow_Blue_F" createVehicle (getPos pad2);

What could be creating this error? I also tried modelToWorldVisual.

 

GarageInit.sqf

Garage.sqf

Share this post


Link to post
Share on other sites

CreateVehicle: "Desired placement position. If the exact position is occupied, nearest empty position is used."

 

Try the alternative syntax with can_collide option.

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, pierremgi said:

CreateVehicle: "Desired placement position. If the exact position is occupied, nearest empty position is used."

 

Try the alternative syntax with can_collide option.

I don't think it's this, the arrows are just a tool I'm using to see where the invisible helipads are, in the script I don't have these.

The problem is the placement of the invisible helipads, I use these for the conditions in the addActions and movement points. 

Share this post


Link to post
Share on other sites

Up :(

I tried disabling collision, also tried creating landing pads at 0,0,0 of map, and then attaching them to the garage, not working neither.

 

GarageInit_2.sqf

Share this post


Link to post
Share on other sites

did u test the alternative syntax of createVehicle ? Do you have a picture of the result?

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

did u test the alternative syntax of createVehicle ? Do you have a picture of the result?

Oh I'm sorry, I looked for that and I thought it was this: 

pad1 disableCollisionWith _obj;

and after this command, then I moved the invisible pad to the garage. Now that you told me again, I've searched more and found the "can_collide" you're talking about, will try when I can and will post results.

 

Sorry again for misunderstanding.

Share this post


Link to post
Share on other sites
7 hours ago, pierremgi said:

did u test the alternative syntax of createVehicle ? Do you have a picture of the result?

THAANKS! Now I got it working, not only the landing pads needed this but also the arrows :face_palm:

I was so dumb to misunderstand that, I could've had it working last week, I'm so sorry for missing that but thanks a lot.

  • Like 1

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

×