Jump to content
blasturbator

running a function in an addAction added by remoteExec to an obejct spawned by a script

Recommended Posts

Hi all,

 

Been a long while since i last posted on these forums. I'm having a problem converting an old script that uses BIS_fnc_MP to use the newer remoteExec. For the most part i've understood how the process works and previous things i've done have worked just fine, but in this example the script is adding an addAction that calls a function and for some reason it just won't work:

 

The original is this (which does work but not with JIP clients, which i thought was the purpose of BIS_fnc_MP but whatever, that is why i want to update it):

 

[[_case,"<t color='#FF0000'>Gather INTEL</t>"],"addActionMP",true,true] spawn BIS_fnc_MP;

 

(addActionMP is the name of the function, i didn't name it 😂, the function itself works fine though, it just seems to be my implementation of remoteExec that isn't working)

From this i glean that we have a call to BIS_fnc_MP with the syntax as follows:

 

params = [_case,"<t color='#FF0000'>Gather INTEL</t>"]

functionName = "addActionMP"

target = true (execute on each machine)

isPersistent = true (will be called now and for every JIP client) (but it doesn't...)

isCall = default (false)

 

This is what i have "updated" it to which i thought would work and i can't figure out why it doesn't:

 

[_case, ["<t color='#FF0000'>Gather INTEL</t>",addActionMP]] remoteExec ["addAction", 0, true];

The syntax for this remoteExec i have written, as i understand it is this:

 

remoteExec:

params = [_case, ["<t color='#FF0000'>Gather INTEL</t>","addActionMP"]]

functionName = addAction

targets = 0 (execute globally)

JIP = true

 

in which the addAction params are (breakdown of the params for the remoteExec):

object = _case

title = "<t color='#FF0000'>Gather INTEL</t>"

script = addActionMP

 

So what happens is this succesfully adds the addAction, but it doesn't call the function "addActionMP" when activated. Basically i can't figure out why this won't execute the function "addActionMP" called by the addAction. I assume i've made a rookie mistake somewhere and would be grateful for some pointers.

 

 

 

Share this post


Link to post
Share on other sites

Use remoteExec (even if it's not the main problem here)

You remote exec the addAction for each client, (probably from server where you create _case ) ,  it's fine .

Now, when you addAction, the code runs locally. Depending on what you wrote in your addActionMP function, the code can fail. For example if you are using some commands like setVelocity which must be applied where the object is local... for example on server. So, you need (probably) to remoteExec this code where _crate is local.

I can't say more without your code.

  • Like 1

Share this post


Link to post
Share on other sites

Pierre; thank you for replying,

 

The addActionMP function does a bunch of stuff and i suppose anything in there could be the reason it isn't working with remoteExec. It works with the old BIS_fnc_MP command except the addAction isn't added to JIP clients and i figured updating the old script to use remoteExec would fix that, a deeper rabbit hole than i thought initially...

 

Is it likely to be something within the function even though it works using BIS_fnc_MP? are remoteExec and BIS_fnc_MP that different? I'm not really versed in the actual differences between the commands, all i know is that in this use case they're both meant to add an addAction and they're both meant to facilitate JIP clients.

 

It's late now and i can't do any testing, but i'll look at moving the remoteExec into the same .sqf as the function as you've suggested and see how it goes. Failing that, i'll be back with the rest of the code 😁

Share this post


Link to post
Share on other sites

@Schatten Thank you for the suggestion, but the function has to run from an addAction; "addActionMP" doesn't add an addAction, it's just a weird name the original script writer gave the function. Passing those params through remoteExecCall to addActionMP wouldn't really do anything at all.

 

For clarity, addActionMP is this:

addActionMP={
private["_object","_screenMsg"];
_object=_this select 0;
_screenMsg=_this select 1;
if(isNull _object)exitWith{};
_object addAction[_screenMsg,"call newIntel"];};

and that calls newIntel which is this:

newIntel={
private["_intelItems","_intel","_used","_ID","_cases","_case","_cache"];
_intelItems=["Land_Laptop_unfolded_F","SatPhone","Land_Suitcase_F","EvMoscow","EvMap","Land_PortableLongRangeRadio_F","Land_MobilePhone_old_F","Land_HandyCam_F","CUP_radio_b"];
_intel=_this select 0;
_used=_this select 1;
_ID=_this select 2;
_cases=nearestObjects[getPosATL player,_intelItems,3];
if(count _cases==0)exitWith{};
_intel removeAction _ID;
_case=_cases select 0;
if isNull _case exitWith{};
deleteVehicle _case;player groupChat "I have obtained the intel";//call addIMkr;call iHint;
_cache=cache;
if(isNil "_cache")exitWith{hint "Intel suggests this place is clean.  Better check elsewhere.";};
[nil,"iHint",true,false]spawn BIS_fnc_MP;
[_cache,"addIMkr",false,false]spawn BIS_fnc_MP;};

which calls iHint and addIMkr which respectively are:

iHint={
hint parseText format["<t align='left' color='#e5b348' size='1.2'><t shadow='1'shadowColor='#000000'>INSURGENCY</t></t>
<img color='#ffffff' image='core\modules\cacheScript\Images\img_line_ca.paa' align='left' size='0.79' />
<t color='#eaeaea'>New intel acquired.  Check map for clue markers within the vicinity of a cache.</t>
<img color='#ffffff' image='core\modules\cacheScript\Images\img_line_ca.paa' align='left' size='0.79' />"]};
addIMkr={
private["_i","_sign","_randX","_sign2","_randY","_radius","_cache","_pos","_range","_intelRadius"];
_cache=cache;
_intelRadius=1200;
_i=0;
while{(getMarkerPos format["%1intel%2",_cache,_i]select 0)!=0}do{_i=_i+1;};
_sign=1;
if(random 100>50)then{_sign=-1;};
_sign2=1;
if(random 100>50)then{_sign2=-1;};
_radius=_intelRadius-_i*(random 50);
if(_radius<50)then{_radius=50;};
_randX=(random _radius);
_randY=(random _radius);
_pos=[(getPosATL _cache select 0)+_sign*_randX,(getPosATL _cache select 1)+_sign2*_randY];
_imkr=createMarker[format["%1intel%2",_cache,_i],_pos];
_imkr setMarkerType"hd_unknown";
_range=round sqrt(_randX^2+_randY^2);
_range=_range-(_range%50);
_imkr setMarkerText format["%1 m",_range];
_imkr setMarkerColor"ColorRed";
_imkr setMarkerSize[0.5,0.5];
iMkrs pushBack _imkr;};

As i've mentioned above, this series of functions does work just fine when called by the BIS_fnc_MP command. The only problem is that it isn't adding the addAction to JIP clients and i wanted to change it to remoteExec to see if that would fix it.

 

Sadly, Cyberpunk 2077 just came out so i'm not really going to have much time to address this in the near future. I'm sure everyone will understand 😁

Share this post


Link to post
Share on other sites
53 minutes ago, blasturbator said:

the function has to run from an addAction

You are wrong -- according to the code you provided addActionMP contains addAction, so an action is added by addActionMP, not vice versa. So, my solution should work.

Share this post


Link to post
Share on other sites

No. You must work on the fact the inner code of the addAction runs locally, so on the PC of the player who called it (the _caller as said in BIKI).

 

Then, it's wrong to remoteExec all the stuff (this code), because this code can have multiple and various commands with their own behavior for arguments and effects arguments_local.gif  arguments_global.gif   effects_local.gif  effects_global.gif Exec_Server.gif  . So, some commands (if any) like setObjectTextureGlobal or setOwner can't be remoteExec everywhere, and on server only for the last one. But you would like a global hint... so to be remoteExec everywhere. Same for some variables which can be global(local) or public...

 

You must pay attention, command after command, function after function, what you can and what you want, where to remoteExec.

And definitely abandon BIS_fnc_MP.

 

Share this post


Link to post
Share on other sites
On 12/10/2020 at 2:18 PM, Schatten said:

addActionMP contains addAction

 

Well about that, i'm not sure why it does, it's a bit of an enigma and frankly i just don't understand that line. What happens in game, when this script is run with the old code (using BIS_fnc_MP), is that addAction within "addActionMP" doesn't actually add an addAction in a normal sense, it somehow just runs immediately and calls newIntel then the object actually deletes itself once newIntel is called so the player never gets the chance to see the addAction the function adds. Maybe this is the part which doesn't work with remoteExec and is causing the script to fail... if its only purpose is to call newIntel then I don't see why it can't just be:

call newIntel;

?

 

I just want to reiterate from my first post that I didn't write this script it's an old script from years ago i'm just trying to fix it. I'm well aware that BIS_fnc_MP is outdated and that is why i'm making these posts to begin with... No need to repeatedly tell me to stop using it when it's quite obviously my intent to not use it.

Share this post


Link to post
Share on other sites
1 hour ago, blasturbator said:

addAction within "addActionMP" doesn't actually add an addAction in a normal sense, it somehow just runs immediately and calls newIntel

No, it does. Then player can activate this action and

1 hour ago, blasturbator said:

the object actually deletes itself once newIntel is called

I see that in the code you provided.

 

I have only one question: did you try my solution?

Share this post


Link to post
Share on other sites

Yes i tried it and no it didn't work because the code isn't doing what you think it is.

 

On 12/10/2020 at 2:18 PM, Schatten said:

 addActionMP contains addAction, so an action is added by addActionMP, not vice versa. So, my solution should work.

 

It doesn't add a usable addAction. It runs automatically, as i have described prior to this. I am aware that it shouldn't do that; but it does. Knowing that it does that however did let me know in advance that your solution wasn't going to work and lo it did not.

 

On 12/13/2020 at 9:05 PM, Schatten said:

No, it does. Then player can activate this action and

 

 

The fact you are still writing things like this tells me you are not reading my whole posts and are still stuck on the idea that the script is actually behaving in a normal way despite my statements to the contrary. If it was behaving normally, i wouldn't need to ask for help. There is a reason I refer to it as "an enigma". Anyway, it is clear that it is not just me that doesn't understand the problem and to be honest i don't want to deal with it anymore. I have spent too much time trying to fix someone else's broken script already. At this point it is no longer worth the time investment when i could just use a different script.

 

On that note; thread closed. I'm probably just going to write a new script from the ground up because something in this one is obviously broken and leaving it in there even if i found a workaround is a bad idea. I don't know if this is an engine bug or just because the script is years out of date and there have been major updates to the game since; but it is clearly not behaving like it should and working around that and pretending it's fine is not the right way to fix this problem. I don't know who wrote this script originally but it has been in the hands of several others since and it has become so bastardised in format and scripting style that it's horrible to work with; seriously you should see the rest of it, a mess of over-nested shite, bugger all commentation and poor formatting practice in general. It's best for everyone that this junk just goes back into the recesses of the internet and hopefully is not used by anyone again.

Share this post


Link to post
Share on other sites
26 minutes ago, blasturbator said:

 I'm probably just going to write a new script from the ground up because something in this one is obviously broken and leaving it in there even if i found a workaround is a bad idea.

 

Don't forget my remarks. You will never succeed in MP script if you're not paying attention to locality (where runs the script, where are the objects of the script), and command arguments/effects.

 

TEST: You are able to script in MP if you succeed in this simple test (running and passing in  hosted + one client):

- spawn a vehicle (usually on server), so not edited.

- add an action (addAction) on it (you have to remote exec the addAction to make it visible by all players. The process is described in BIKI page for addAction)

- the code for addAction must give a "push" on vehicle (like pushing a rubber boat from shore to water). Use setVelocity for the push. If not applied correctly (on the PC where the boat is) the code will not work (no effect), on client PC. So it seems the addAction is broken. Did you remoteExec this command on local PC for boat?

Then, play with other commands like hint, playSound3D, but also hideObject, hideObjectGlobal, setObjectTexture, setObjectTextureGlobal...

If you can do what you want, in any case, from all PCs with all these commands, you can script for MP (hosted at least)...

 

https://community.bistudio.com/wiki/Multiplayer_Scripting

 

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×