Jump to content

Recommended Posts

Hiya,

I'm working on something where I want an addaction to be added to a vehicle, but i'm having trouble with the locality.

_ScanArea = 25;
_yeet1 = nearestObjects[SPAWNTARGETOBJECT,["Air", "landVehicle"],_ScanArea] select 0;

        _SpawnerPos = (getposASL SPAWNTARGETOBJECT);
        _VehicleType = "VEHICLECLASSNAME" createVehicle _SpawnerPos;
        _VehicleType addAction ["Title Here","Scripts\Test.sqf",[],1,false,true,"","_this distance _target < 5"];

When I test this out in Singleplayer or in local MP, the action does get added to the vehicle, but when I try it out on a dedicated server, the action won't be added to the vehicle.

I'm hoping someone can help me out with this and explain it a little bit, so I can improve my MP Scripting skills! 🙂

Thanks in advance

Share this post


Link to post
Share on other sites
_ScanArea = 25;
_yeet1 = nearestObjects[SPAWNTARGETOBJECT,["Air", "landVehicle"],_ScanArea] select 0;

        _SpawnerPos = (getposASL SPAWNTARGETOBJECT);
        _VehicleType = "VEHICLECLASSNAME" createVehicle _SpawnerPos;
        _VehicleType addAction ["Title Here","Scripts\Test.sqf",[],1,false,true,"","_this distance _target < 5"];

How are you executing the code?

Share this post


Link to post
Share on other sites

I execute the script with player execVM

Share this post


Link to post
Share on other sites

Some more info needed: Where are you executing the code from? Debug Console (Local, Server, Global)? init.sqf?

Share this post


Link to post
Share on other sites

Addaction has a .sqf attached to it, which activates the .sqf with the vehicle spawn script listed above (with player execVM)

Lemme know if you need more info or if this is enough

Share this post


Link to post
Share on other sites

yeah i know that but how are you executing the code from above as in: are you writing " player execVM "yourscript.sqf" " in the debug console and then pressing Local Exec? Or something else?

Share this post


Link to post
Share on other sites
9 hours ago, KutPax said:

Hiya,

I'm working on something where I want an addaction to be added to a vehicle, but i'm having trouble with the locality.

_ScanArea = 25;
_yeet1 = nearestObjects[SPAWNTARGETOBJECT,["Air", "landVehicle"],_ScanArea] select 0;

        _SpawnerPos = (getposASL SPAWNTARGETOBJECT);
        _VehicleType = "VEHICLECLASSNAME" createVehicle _SpawnerPos;
        _VehicleType addAction ["Title Here","Scripts\Test.sqf",[],1,false,true,"","_this distance _target < 5"];

When I test this out in Singleplayer or in local MP, the action does get added to the vehicle, but when I try it out on a dedicated server, the action won't be added to the vehicle.

I'm hoping someone can help me out with this and explain it a little bit, so I can improve my MP Scripting skills! 🙂

Thanks in advance

 

When you write an addAction inside an init field of an edited object, all clients (players) can run the code when they start, so, the addAction menu is fine.

 

When you spawn an object, you spawn it locally (usually on server) and  createVehicle broadcast this object.

Spoiler

Note: Spawning everywhere has no sense, you'll just multiply this object * nbr of players, a common mistake when people discover multiplayer scripting.

So, as your object is spawned locally, then your variables are, and your code for addAction menu is also local. You need to remoteExec it everywhere. (you can refine the code for dedicated or hosted server but the following works anyway):

let's say your _vehicleType is the object spawned by createVehicle (I duno if that works)

[_VehicleType, ["Title Here","Scripts\Test.sqf",[],1,false,true,"","_this distance _target < 5"] ] remoteExec ["addAction",0,_vehicleType];

Spoiler

Note: _this distance _target is outdated. You have now a parameter for the active distance: radius - See BIKI.

 

After this point, your inner code (code called by a player), is made of test.sqf  . That means the code will run on a client PC, somewhere, and that must be consistent with multiplayer rules and your aim. I suggest you read one of my last post. Especially the 3rd point.

Edited by pierremgi
Edited for JIP remote execution as far as the vehicle is alive

Share this post


Link to post
Share on other sites

I'll give that a go, thanks!

(Can't test it until tomorrow, I'll let you know!)

Share this post


Link to post
Share on other sites

Edited above for JIP dedicated server and life time of the vehicle.

Share this post


Link to post
Share on other sites

(The following question is something different than the addaction question)

I'm trying to make the following for remoteexeccall (correct me if i'm wrong here)

 _nearestVeh = nearestObject [SpawnerObjectName, "Air"];

        _Vehicle1 = "CrateNameHere" createVehicle _Pos2;
        [_Vehicle1, _nearestVeh] call ace_cargo_fnc_loadItem;


I've tried the following (Doesn't work):

        [[_Vehicle1, _nearestVeh]] remoteExecCall [ace_cargo_fnc_loadItem];

Any idea what I'm doing wrong here?

Share this post


Link to post
Share on other sites

ACE.... joker! And it seems to me you didn't read me, following the links.

Potential errors: ace_cargo_fnc_loadItem is not a string. remoteExecCall is not accurate, _vehicle1 is a "crateNameHere"???? not a working class, _nearestVeh is not defined...

Share this post


Link to post
Share on other sites

I'll write the full code here (slightly different than the above):
 

if ( _ctrl2 lbText ( lbCurSel _ctrl2 ) isEqualTo "Large Equipment Crate" ) exitwith 
{
    _nearestAirVeh = nearestObject [BoxLoaderSkeet1, "Air"];

    if (isNull _nearestAirVeh) then {
        hint "No Helicopter near the Box Loader.";
    }
    else
    {
        [_nearestAirVeh, 2000] call ace_cargo_fnc_setSpace;
        _nearestAirVeh allowDamage true;
        _BoxSpawnerPos2 = (getposASL BoxLoaderSkeet2);
        _HeliMovePos1 = (getposASL BoxLoaderSkeet1);
        _nearestAirVeh setPosASL _HeliMovePos1;
        sleep 0.1;
        _BoxLoaderVehicle1 = "Snake_Crates_Large_Equipment" createVehicle _BoxSpawnerPos2;
        _BoxLoaderVehicle1 setPosASL _BoxSpawnerPos2;
        [_BoxLoaderVehicle1, _nearestAirVeh] call ace_cargo_fnc_loadItem;
        hint format ["%1 Added to Aircraft", _ctrl2 lbText ( lbCurSel _ctrl2 )];
        _nearestAirVeh allowDamage true;
    };
};



Basically:

It spawns an object (In this case a crate) on _BoxSpawnerPos2 (Which is an invisible object which supplies the script with a position)
Then it teleports the helicopter on _HeliMovePos1 to ensure that the helicopter is close enough for the box to be loaded in with the ace function
And now this is where it calls the ace_cargo_fnc_loadItem function, only this does not work in a Dedicated Server, which led me to believe I had to remoteExecCall it.

I haven't had the chance to attentively read your tutorial which you've linked me to, but I''ll be sure to do that tomorrow when I'm done with work.

Thanks in advance!

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

×