Jump to content
Sign in to follow this  
eagledude4

Vehicle Arrays

Recommended Posts

I'm having an issue converting a map object reference to a variable for use in an array.

_Vcl = _classname createVehicle getpos _logic;
_Name = _Vcl;
_ServerVcls_Count = server getVariable "ServerVcls_Count";
_Count = {_x == _classname} count _ServerVcls_Count;

_Var = format ["%1_%2", _classname, _Count + 1];

_Vcl setVehicleVarName _Var;

_ServerVcls = server getVariable "ServerVcls";
_ServerVcls = _ServerVcls + [_Vcl];
server setVariable ["ServerVcls", _ServerVcls, true];

When i return "server getVariable "ServerVcls"", I get:

[21d2a040# 165684: offroad.p3d REMOTE]

I understand this to be the map editor reference.

I thought of using vehicleVarName or name _vcl, but they both return strings, but I need to save an object/namespace, or else I get this error:

Error getvariable: Type String, expected Namespace,Object,Group,Team member,Task,Location
File Server\Functions\Vehicles\FNC_Save.sqf, line 3
Error in expression <ect 0;
["Vehicles", _vcl, "Owner", _vcl getVariable "Owner"] call iniDB_write;
[>
 Error position: <getVariable "Owner"] call iniDB_write;
[>

How do I achieve this result:

[c_offroad]

?

Edited by eagledude4

Share this post


Link to post
Share on other sites

_Var = format ["%1", _vehicle]; //returns your result. [21d2a040# 165684: offroad.p3d REMOTE]

_Var = format ["%1", name _vehicle]; //returns the name.

_Var = typeOf _vehicle; //returns classname

Share this post


Link to post
Share on other sites

I edited my post while you were replying, sorry.

I thought of using vehicleVarName or name _vcl, but they both return strings, but I need to save an object/namespace, or else I get this error:

Error getvariable: Type String, expected Namespace,Object,Group,Team member,Task,Location
File Server\Functions\Vehicles\FNC_Save.sqf, line 3
Error in expression <ect 0;
["Vehicles", _vcl, "Owner", _vcl getVariable "Owner"] call iniDB_write;
[>
 Error position: <getVariable "Owner"] call iniDB_write;
[>

How do I achieve this result:

[c_offroad]

?

Edited by eagledude4

Share this post


Link to post
Share on other sites

Well for one:

_ServerVcls_Count = server getVariable "ServerVcls_Count";

What is the "server" variable?

As far as I understand you want to keep a synced list on all clients containing a list of vehicles. This piece of code achieves the same.

_Vcl = _classname createVehicle getpos _logic;

_Count = {_x == _classname} count _ServerVcls;
_VclName = format ["%1_%2", _classname, _Count + 1];
ServerVcls set [count ServerVcls, _VclName];
publicVariable "ServerVcls";

Share this post


Link to post
Share on other sites

I'm actually writing the array to a persistent database.

//Vehicles
_ServerVcls = server getVariable "ServerVcls";
if (!isNil("_ServerVcls")) then {
	{
		if (count _ServerVcls > 0) then {
			[_x] spawn FNC_VehicleSave;
		};
	} forEach _ServerVcls;
};

FNC_VehicleSave:

FNC_VehicleSave = {
_vcl = _this select 0;
["Vehicles", _vcl, "Owner", _vcl getVariable "Owner"] call iniDB_write;
["Vehicles", _vcl, "Position", getPosASLW _vcl] call iniDB_write;
["Vehicles", _vcl, "Direction", direction _vcl] call iniDB_write;
["Vehicles", _vcl, "Damage", damage _vcl] call iniDB_write;
["Vehicles", _vcl, "Weapons", getWeaponCargo _vcl] call iniDB_write;
["Vehicles", _vcl, "Magazines", getMagazineCargo _vcl] call iniDB_write;
["Vehicles", _vcl, "Inventory", _vcl getVariable "Inventory"] call iniDB_write;

_ServerVcls = server getVariable "ServerVcls";
["Variables", "Vehicles", "ServerVcls", _ServerVcls] call iniDB_write;

_ServerVcls_Count = server getVariable "ServerVcls_Count";
["Variables", "Vehicles", "ServerVcls_Count", _ServerVcls_Count] call iniDB_write;
};

I need to have the object names in the array, so I can't use the workaround you suggested.

Edited by eagledude4

Share this post


Link to post
Share on other sites

Maybe something like this? It keeps a record of vehicles classnames and their count.

_Vcl = _classname createVehicle getpos _logic;
_ServerVcls= server getVariable "ServerVcls";

for [{_i=0},{_i<=count _ServerVcls},{_i=_i+1}] do
{
_TempServerVehicle = (_ServerVcls select _i);
if(_TempServerVehicle select 0 == _classname) then
{
	_ServerVehicleId = _i;
	_ServerVehicle = _TempServerVehicle;
};
};

if(isNil _ServerVehicleId) then
{
_ServerVehicle = [_classname, 0];
_ServerVehicleId =  count _ServerVcls;
}
else
{
_ServerVehicle set [1, (_ServerVehicle select 1) + 1];
};

_ServerVcls set [_ServerVehicleId, _ServerVehicle];
server setVariable ["ServerVcls", _ServerVcls, true];

I now see you edited your post. Let me re-read everything cause my above solution isn't the thing you need apparently.

Maybe you need to explain what you are trying to achieve. If your simply trying to save all vehicles to your INI you can just loop trough the variable "vehicles".

::

{_x call FNC_VehicleSave} forEach vehicles;

Edited by mindstorm

Share this post


Link to post
Share on other sites

Problem resolved.

Edited by eagledude4

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  

×