Jump to content
Vince_

Vehicle Respawn Module Variable Name???

Recommended Posts

Hello, I am using a teleport script that requires a specific variable name. When the vehicle respawns via the Vehicle Respawn module, it renames it something else so that the teleport script no longer works. I need a way for it to re-name the vehicle the same thing.

 

I have tried this in the expressions of the vehicle respawn module:

 (_this select 0) setVehicleVarName "MHQ1";
 

As well as 

(_this select 0) execVM 'vehicleMHQ1.sqf';

With a bunch of different codes I put in the sqf that I found on here and other websites that have all not worked for me. Most of what I found is pretty dated.

Anyone know how I can do this? 

 

Share this post


Link to post
Share on other sites

compiled function:

fnc_setVehicleName = {

	params ["_veh", "_name"];
	missionNamespace setVariable [_name, _veh, true];
	[_veh, _name] remoteExecCall ["setVehicleVarName", 0, _name];
};

vehicle respawn module expression:

if (isServer) then {

params [["_newVeh", objNull], ["_oldVeh", objNull],"_vehName"];

_vehName = vehicleVarName _newVeh;

[_newVeh, _vehName] call fnc_setVehicleName;

};

Share this post


Link to post
Share on other sites

 

compiled function:

fnc_setVehicleName = {

	params ["_veh", "_name"];
	missionNamespace setVariable [_name, _veh, true];
	[_veh, _name] remoteExecCall ["setVehicleVarName", 0, _name];
};

vehicle respawn module expression:

if (isServer) then {

params [["_newVeh", objNull], ["_oldVeh", objNull],"_vehName"];

_vehName = vehicleVarName _newVeh;

[_newVeh, _vehName] call fnc_setVehicleName;

};

Thank you for your response, davidoss.

Could you please give me an example? I am getting errors with the vehicle module expression. Sorry, I'm very noob at most of this  :P

Share this post


Link to post
Share on other sites

There are everything what you need. Maybe you do not knew how to compile function?

 

In init.sqf

[] call compile preprocessFileLineNumbers "functions.sqf";

Create a file inside mission root called functions.sqf.

In that file paste the function posted above.

 

Paste the vehicle respawn module expression code  inside the vehicle respawn  module expression field

Run your mission

Share this post


Link to post
Share on other sites

Ok, I did that. No errors, but still getting  <NULL -object> when trying to teleport to it. So I assume it is still not renaming it after it respawns  :unsure:

Share this post


Link to post
Share on other sites

Here are example mission works as it should.

 

I do not knew why its not working for you maybe you are using some mod

which interfere with name variables.

Share this post


Link to post
Share on other sites

It looks just like that. 

I'm using a simple teleport command that requires the name on the vehicle to retain itself. It acts upon an object that calls to a script that has: 

_unit = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_teleporTo = _this select 3;
 
if (alive _teleporTo) then
{
        _caller moveInCargo _teleporTo;
        player vehicleChat format ["You have been deployed at %1", _teleportTo];
} else {
        player groupChat format ["Unable to deploy to %1 at this time.", _teleporTo];
};

It works fine, but as soon as the vehicle is destroyed and respawns, I get "Unable to deploy at <NULL -object< at this time."

 

The only mods I use within the mission are IGI Load, ATM airdrop, and Outlaw Mag Repack. 

Share this post


Link to post
Share on other sites

It's:

this addAction["Teleport MHQ1", "teleportMHQ.sqf", MHQ1];this addAction["Teleport MHQ2", "teleportMHQ.sqf", MHQ2];

Share this post


Link to post
Share on other sites

Its all alright for me. We need to debug the vehicle to look what else are going on.

First of all check what name are the vehicle got after respawn. cursorObject or cursorTarget command in debug console while looking at

Share this post


Link to post
Share on other sites

That is very odd. It comes back with the correct name "MHQ1" after it respawns when I do:

hint str cursorObject;

but after respawn, I am no longer able to teleport to it.

Share this post


Link to post
Share on other sites

Maybe its caused by :

Before respawn the MHQ1 variable are related to object :

48284100# 4: mrap_01_unarmed_f.p3d

Its being passed into addaction like this:

this addAction["Teleport MHQ1", "teleportMHQ.sqf",48284100# 4: mrap_01_unarmed_f.p3d];

After respawn the passed object are no longer exist.

Share this post


Link to post
Share on other sites

When I do this in debug:

hint str [getModelInfo cursorObject, typeOf cursorObject];

It gives me this for both before and after respawn: 

[["heli_transport_03_f_p3d","a3\air_f_heli\heli_transport_03\heli_transport_03_f_p3d",true],"B_Heli_Transport_03_F"]

Share this post


Link to post
Share on other sites

That gives me:

Error alive: Type text, expected object

When trying to use the teleport

Share this post


Link to post
Share on other sites

Yes. Tried to pass string and change it to object inside script, but obviously using text you get text not object.

It was a nonsense  but we have correct diagnose need to find solution.

 

Well i have one:

 

just after vehicle respawn  you need to remove action from  object holding it and re-add. 

It will update the passed variable with current object.

There must be better solution for that.

 

I will write you how to do it in MP compatible way.

Share this post


Link to post
Share on other sites

Name the guy with actions >chief< and try this:

fnc_setVehicleName = {

    params ["_veh", "_name"];
    missionNamespace setVariable [_name, _veh, true];
    [_veh, _name] remoteExecCall ["setVehicleVarName", 0, _name];
    
    if (_name == "MHQ1" || _name == "MHQ2") then {
    
        chief remoteExec ["removeAllActions", 0, chief];
        [chief, ["Teleport MHQ1","teleportMHQ.sqf", MHQ1]] remoteExec ["addAction", 0, chief];
        [chief, ["Teleport MHQ2","teleportMHQ.sqf", MHQ2]] remoteExec ["addAction", 0, chief];
        
    };
};

params ["_unit", "_caller", "_id", "_teleporTo"];
 
if (alive _teleporTo) then
{
        _caller moveInCargo _teleporTo;
        (vehicle _caller) vehicleChat format ["You have been deployed at %1", _teleporTo];
} else {
        _caller groupChat format ["Unable to deploy to %1 at this time.", _teleporTo];
};

Share this post


Link to post
Share on other sites

 

Name the guy with actions >chief< and try this:

fnc_setVehicleName = {

    params ["_veh", "_name"];
    missionNamespace setVariable [_name, _veh, true];
    [_veh, _name] remoteExecCall ["setVehicleVarName", 0, _name];
    
    if (_name == "MHQ1" || _name == "MHQ2") then {
    
        chief remoteExec ["removeAllActions", 0, chief];
        [chief, ["Teleport MHQ1","teleportMHQ.sqf", MHQ1]] remoteExec ["addAction", 0, chief];
        [chief, ["Teleport MHQ2","teleportMHQ.sqf", MHQ2]] remoteExec ["addAction", 0, chief];
        
    };
};

Wow. It worked....Holy shit, thanks so much, davidoss. 

Share this post


Link to post
Share on other sites

No problem i was interested too why that are not working  out of the box.

 

Correct your teleportMHQ.sqf script too example above

 

@edit: typo, syntax

Share this post


Link to post
Share on other sites

No need to add and remove actions all the time. Just change the way you send the vehicle name to the teleport script.

Instead of..

this addAction["Teleport MHQ1", "teleportMHQ.sqf", MHQ1];
Which as Davidoss concluded that this will hardcode the reference into the action.

Instead pass it as a string and then in the teleport script use the string to get the current missionNamespace reference..

this addAction["Teleport MHQ1", "teleportMHQ.sqf", "MHQ1"];


//teleportMHQ.sqf
params[ "_target", "_caller", "_id", "_args" ];

_teleportTo = missionNamespace getVariable [ _args, objNull ];

if ( !isNull _teleportTo && { alive _teleportTo } ) then {
	_caller moveInCargo _teleportTo;
	_caller vehicleChat format ["You have been deployed at %1", _teleportTo];
} else {
	_caller groupChat format ["Unable to deploy to %1 at this time.", _teleportTo];
};


//respawn module
if ( isServer ) then {
	
	params[ "_newVeh", "_oldVeh" ];

	_name = vehicleVarName _oldVeh;
	_newVeh setVehicleVarName _name;
	missionNamespace setVariable [ _name, _newVeh, true ];
};

Share this post


Link to post
Share on other sites

As usually nice and clean. Thanks Larrow.

Damn getVariable, how i could forgot that?

 

 

The vehicle chat isn't showing up need to change to vehicle _caller.

Looks like the _caller isn't _caller anymore after moved in cargo.

Its the same problem with refreshing variable.

params[ "_target", "_caller", "_id", "_args" ];

_teleportTo = missionNamespace getVariable [ _args, objNull ];

if ( !isNull _teleportTo && { alive _teleportTo } ) then {
    _caller moveInCargo _teleportTo;
    (vehicle _caller) vehicleChat format ["You have been deployed at %1", _args];
} else {
    _caller groupChat format ["Unable to deploy to %1 at this time.", _args];
};

Share this post


Link to post
Share on other sites

Yeah, I was getting strange issues where after 2-3 respawns later, the Teleport to MHQ would duplicate in the list and it would break. It seems to be working fine now after Larrow's fixes. Only issue is the vehicle chat, as you mentioned davidoss.

Share this post


Link to post
Share on other sites

Its just a timing issue, add a wait in between movein and vehicle chat to make sure the player has finished being moved.

this addAction["Teleport MHQ1", "teleportMHQ.sqf", "MHQ1"];


//teleportMHQ.sqf
params[ "_target", "_caller", "_id", "_args" ];

_teleportTo = missionNamespace getVariable [ _args, objNull ];

if ( !isNull _teleportTo && { alive _teleportTo } ) then {
	_caller moveInCargo _teleportTo;
	waitUntil{ vehicle _caller isEqualTo _teleportTo };
	vehicle _caller vehicleChat format ["You have been deployed at %1", _teleportTo];
} else {
	_caller groupChat format ["Unable to deploy to %1 at this time.", _teleportTo];
};


//respawn module
if ( isServer ) then {
	
	params[ "_newVeh", "_oldVeh" ];

	_name = vehicleVarName _oldVeh;
	_newVeh setVehicleVarName _name;
	missionNamespace setVariable [ _name, _newVeh, true ];
};

Share this post


Link to post
Share on other sites
On 8/22/2016 at 8:35 AM, Larrow said:

Its just a timing issue, add a wait in between movein and vehicle chat to make sure the player has finished being moved.

 


this addAction["Teleport MHQ1", "teleportMHQ.sqf", "MHQ1"];


//teleportMHQ.sqf
params[ "_target", "_caller", "_id", "_args" ];

_teleportTo = missionNamespace getVariable [ _args, objNull ];

if ( !isNull _teleportTo && { alive _teleportTo } ) then {
	_caller moveInCargo _teleportTo;
	waitUntil{ vehicle _caller isEqualTo _teleportTo };
	vehicle _caller vehicleChat format ["You have been deployed at %1", _teleportTo];
} else {
	_caller groupChat format ["Unable to deploy to %1 at this time.", _teleportTo];
};


//respawn module
if ( isServer ) then {
	
	params[ "_newVeh", "_oldVeh" ];

	_name = vehicleVarName _oldVeh;
	_newVeh setVehicleVarName _name;
	missionNamespace setVariable [ _name, _newVeh, true ];
};

Than you!

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

×