Jump to content
Sign in to follow this  
JacobJ

Some problems with removing the addactions for everyone

Recommended Posts

Hey all

I have a problem with removing the addactions that I place in objects on all clients. It works very well for the one that exec the addaction, but all others still have the same option alltho the crate is already loaded into that vehicle.

Here is the code I have:

In the init of my hummer:

hum3load = hum3 addaction ["Load ammobox to hummer", "attach_ammoboxhum3.sqf"];

In the attach_ammoboxhum3.sqf:

// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {

hum3 removeAction hum3load;
hint "Nothing to load!";

} else {
// Since the box is still in one piece, make sure it's within 15m of the MHQ and the MHQ isn't on.
if (hum3 distance mhq1_ammobox < 16 and !isEngineOn hum3) then 
{

	deletemarker "dropmark";		

	// Attach the box to the MHQ roof.
	mhq1_ammobox attachTo [hum3,[0,-1.5,-0.5]];

	removeW = execVM "removeActionW.sqf";
	waitUntil {scriptDone removeW};


	// Change the action on the MHQ to unload the box now.
	hum3unload = hum3 addaction ["Unload ammobox from hummer", "detach_ammoboxhum3.sqf"];


} else {
	// If the box isn't within 15m or the engine is running, tell them they have to try again.
	hint "You must be within 15m of the ammo box, with your engine off, to load it!";
};
};

In the detach_ammoboxhum3.sqf

// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {

hum3 removeAction hum3load;
hint "Nothing to unload!";

} else {
// Since it's alive, make sure the engine is off on the MHQ.
if (!isEngineon hum3) then {

	// Detach it, and move it 10m behind the MHQ, on the ground.
	detach mhq1_ammobox;
	_worldPos = hum3 modelToWorld [0,-5,0];
	mhq1_ammobox setPos [_worldPos select 0, _worldPos select 1, 0];

	hum3 removeAction hum3unload;

	addactionW = execVM "addActionW.sqf";
	waitUntil {scriptDone addactionW};

} else {
	// If the engine was running, warn the user.
	hint "You can't unload while your engine is running!";
};
};

In the addActionW.sqf:

// Addactions again to WEST


	// Add the action to load it again boat.
	heli1load = heli1 addaction ["Load ammobox to heli", "attach_ammoboxheli1.sqf"];

	// Add the action to load it again boat.
	heli2load = heli2 addaction ["Load ammobox to heli", "attach_ammoboxheli2.sqf"];

	// Add the action to load it again boat.
	heli3load = heli3 addaction ["Load ammobox to heli", "attach_ammoboxheli3.sqf"];

	// Add the action to load it again boat.
	heli4load = heli4 addaction ["Load ammobox to heli", "attach_ammoboxheli4.sqf"];

	// Add the action to load it again boat.
	her1load = her1 addaction ["Load ammobox to hercules", "attach_ammoboxher1.sqf"];

	// Add the action to load it again boat.
	hum1load = hum1 addaction ["Load ammobox to hummer", "attach_ammoboxhum1.sqf"];

	// Add the action to load it again boat.
	hum2load = hum2 addaction ["Load ammobox to hummer", "attach_ammoboxhum2.sqf"];

	// Add the action to load it again boat.
	hum3load = hum3 addaction ["Load ammobox to hummer", "attach_ammoboxhum3.sqf"];

	// Add the action to load it again boat.
	truck1load = truck1 addaction ["Load ammobox to truck", "attach_ammoboxtruck1.sqf"];

In the removeactionW.sqf

// Remove actions on WEST

	heli1 removeAction heli1load;
	heli2 removeAction heli2load;
	heli3 removeAction heli3load;
	heli4 removeAction heli4load;
	Her1 removeAction her1load;		
	hum1 removeAction hum1load;
	hum2 removeAction hum2load;
	hum3 removeAction hum3load;
	truck1 removeAction truck1load;

Why will the actions not disapear on all clients? Isnt that strange, now I havn't made anything _local.

/Jacob

---------- Post added at 11:40 ---------- Previous post was at 11:24 ----------

Would a ForEach command like this work:

{heli1 removeaction heli1load} forEach allUnits;

Would try, but I have heard it is not so good with so many forEach commands in a mission.

Share this post


Link to post
Share on other sites
// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.

that line imediatly stood out :)

but foreach loop should work ok yes, make sure you run it on all clients.

meaning if its in a script wich starts with if (!isServer) exitWith {}; or if (isServer) then {

do this at the part you want to delete the actions:

[] spawn {
  {heli1 removeaction heli1load} forEach allUnits;
};

that will make sure its run on all clients.

as long as you dont do 100 loops each second youll be fine :)

Edited by Demonized

Share this post


Link to post
Share on other sites

hehe cool, didnt know that and I have def not 100 loops each second!!

So all the scripts I want to be public/run on all clients, should start with if (!isServer) then { ??

Can you explain the [] spawn { line? What does it do?

---------- Post added at 12:23 ---------- Previous post was at 11:53 ----------

Now I have tried to do the thing you suggested, but now it will not load the ammobox into the heli1 (thats the one I have tried on):

In the attach_ammoboxheli1.sqf:

if (!isServer) then {

// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {

	removeW = execVM "removeActionW.sqf";
	waitUntil {scriptDone removeW};

hint "Nothing to load!";

} else {
// Since the box is still in one piece, make sure it's within 15m of the MHQ and the MHQ isn't on.
if (heli1 distance mhq1_ammobox < 16 and (!isEngineOn heli1) and (((getPosATL heli1) select 2) < 1)) then {

	deletemarker "dropmark";		

	// Attach the box to the MHQ roof.
	mhq1_ammobox attachTo [heli1,[0,-0.2,0.4]];

	removeW = execVM "removeActionW.sqf";
	waitUntil {scriptDone removeW};



// Change the action on the MHQ to unload the box now.

[] spawn {
	{heli1unload = heli1 addaction ["Unload ammobox from heli", "detach_ammoboxheli1.sqf"]} forEach allunits;

	{dropbox1 = heli1 addaction ["Drop ammobox", "dropsupplyheli1.sqf"]} forEach allUnits;
};

} else {
	// If the box isn't within 15m or the engine is running, tell them they have to try again.
	hint "You must be on the ground, with your engine off, and within 15m of the ammo box to load it!";
};
};
};

Have I done something wrong with the command?

Share this post


Link to post
Share on other sites

spawn "creates" a new script and run it without pausing the current script.

spawn is basically the same as execVM if that helps.

also it beheaves like a script so if you have a script wich is

if (isServer) then {
  <code will only be run on server not on clients>;
  [_unitname] spawn {
     _unit = _this select 0;
     // here script will pause inside the spawn.
     waitUntil {!alive _unit};
     <code will be run on all clients>;
  };
  // here the script continues regardless of what the spawn does and only on server.
};

Locality is not my strongest side in editing so hopefully some of the forums gurus can direct you to a better answer, also dont forget to use the search button on forums ;)

Edited by Demonized

Share this post


Link to post
Share on other sites

Okay, but I can't see where I have done anything wrong in the attach_ammoboxheli1.sqf.

It still wont load the crate into the heli. Do I have to remove the ! infront of isServer? Would that work?

Share this post


Link to post
Share on other sites

yeah try that and test, cant say anything more accurate sorry.

I mainly work with AI related stuff and that is mainly on server so i rarely need to care about locality.

Share this post


Link to post
Share on other sites

okay thank you so far then. I at least have something to work with and now I have a little bit more knowledge of what the isServer is for.

If anyone else has some inputs to this problem, then please come with them.

Share this post


Link to post
Share on other sites
So all the scripts I want to be public/run on all clients, should start with if (!isServer) then { ??

if (isServer) then { code.... only on server.

if (!isServer) then { code.... on all clients/players but not on server.

if (!isServer) exitWith {}; this does nothing for clients as they exit script here, but server will pass it to do its code.

there is also isDedicated and some others not sure about all the names.

etc...

Share this post


Link to post
Share on other sites

Is it correct, that running a script on the server and dealing with global/_local isnt the same thing?

I tried to remove the ! and it worked, I could load the box into the heli, but I got a lot of "Unload ammobox from heli". It was like it used the forEach command to put in a "Unload ammobox from heli" to each unit in the whole map.

Share this post


Link to post
Share on other sites

global means anyone can reach it or acess it by using the global name from anywhere, _local is only acessible from within its own script wherever that is run.

---------- Post added at 01:07 PM ---------- Previous post was at 01:04 PM ----------

I tried to remove the ! and it worked, I could load the box into the heli, but I got a lot of "Unload ammobox from heli". It was like it used the forEach command to put in a "Unload ammobox from heli" to each unit in the whole map.

how many players was on when you tested? if any was there exactly same amount of extra unload actions?

then it was probably a locality issue, else its a script error of some kind somewhere, not error but wrong code or something.

Share this post


Link to post
Share on other sites

no other player was on, but my best guess is that there was as many actions as there where playable units in the game.

Share this post


Link to post
Share on other sites

Scripts executed via addAction run locally for whoever executed the action. Since addAction is a local command, the action is only removed for whoever executes the action. The script doesn't run for anyone else, so no one else has the action removed.

One workaround I use for this is to have the script executed by the addAction simply set a variable to true and make it public with publicVariable - nothing else. A trigger waits for that variable and then executes the 'real' script.

This ensures the effects of the action are completely global.

Now, since some of the commands executed in the 'real' script will have global implications (e.g. createVehicle or whatever), then it's best to just put those commands behind an isServer check.

Share this post


Link to post
Share on other sites

Okay that I didnt know. Thank you very much for this info.

So i make a addaction, this calls a script only containing this for example:

publicVariable "jumbo";

Then I create an trigger/emptydetector, and in the conditions field I put jumbo. In the on Act I put: [] execVM "realscript.sqf";

And the realscript must start with If (isServer) then {

Have I understood you right?

Do I still have to use the spawn command together with the forEach allUnits, or can I just use the codes I originally had, because the realscript now is a server script?

Share this post


Link to post
Share on other sites

You have to define Jumbo first.

init.sqf

jumbo = false;

myscriptstarter.sqf

jumbo = true;
publicVariable "jumbo";

You have the trigger portion right.

Share this post


Link to post
Share on other sites

Okay nice. Could I do the publicVariable part in the init.sqf and if not, can you explain why? Just to learn a bit more. But thank you very much, ill try this out and see if it works. Ill report back how it went.

Share this post


Link to post
Share on other sites

No you would not put the

publicVariable "jumbo";

in the init.sqf

all publicVariable does is sends the variable out to all the other clients/server.

So you want to use this command when you define or redefine a variable on a client and you want to do the same on all the other clients/server.

You define it in the init.sqf so that every client knows that the variable is there. in this case you can use (false). Then when a player uses the addaction to run the start script, The Variable is chenged to (true) and then sent to all the other clents/server with the publicVariable command.

Then your trigger condition is waiting for that variable to become true, the trigger fires and You can execute the code you want from the server. Just make sure you limit it with

if (!isServer) exitWith {};

That way it only runs on the server.

Edited by Riouken

Share this post


Link to post
Share on other sites

Do I just paste the:

if (!isServer) then exitWith {};

In the top of the realscript.sqf or how do I do it? Must my code be within the {}?

Share this post


Link to post
Share on other sites
Do I just paste the:

if (!isServer) exitWith {};

In the top of the realscript.sqf or how do I do it? Must my code be within the {}?

Yes just put it at the top of "realscript.sqf".

And no you do not need anything in the {}.

That will stop the script from running anything past that line on every client.

Edited by Riouken

Share this post


Link to post
Share on other sites

Okay, ive found a problem. There must not be a "then" before the exitWith. BUt else it seems to work, but I am waiting for my testing mate to come online and try it out with me. Ill report back if it works.

Share this post


Link to post
Share on other sites
Okay, ive found a problem. There must not be a "then" before the exitWith. BUt else it seems to work, but I am waiting for my testing mate to come online and try it out with me. Ill report back if it works.

Yep, sorry it should not have the "then" in there. I have fixed it in the other posts.

Share this post


Link to post
Share on other sites

Okay this doesnt work as suppossed to and I suspect my scripts are the problem.

Here is how my setup is:

1. I have a empty trigger, condition: hum1jumbo Act: nul = [] execVM "attach_ammoboxhum1";

2. I have a hummer, which has this is the init line:

this addAction ["Load box to hummer1", "load.sqf"];

3. In my load.sqf I have this:

hum1jumbo = true;
publicVariable "hum1jumbo";

4. In my attach_ammoboxhum1 I have this:

if (!isServer) exitWith {};

// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {

hum1 removeAction hum1load;
hint "Nothing to load!";

} else {
// Since the box is still in one piece, make sure it's within 15m of the MHQ and the MHQ isn't on.
if (hum1 distance mhq1_ammobox < 16 and !isEngineOn hum1) then 
{

	deletemarker "dropmark";		

	// Attach the box to the MHQ roof.
	mhq1_ammobox attachTo [hum1,[0,-1.5,-0.5]];

	removeW = execVM "removeActionW.sqf";
	waitUntil {scriptDone removeW};

	// Change the action on the MHQ to unload the box now.
	hum1unload = hum1 addaction ["Unload ammobox from hummer", "detach_ammoboxhum1.sqf"];


} else {
	// If the box isn't within 15m or the engine is running, tell them they have to try again.
	hint "You must be within 15m of the ammo box, with your engine off, to load it!";
};
};

5. In my detach_ammoboxhum1 I have this:

if (!isServer) exitWith {};
// If for some reason the ammo box is destroyed, don't try to load it and remove actions to load or unload.
if (!alive mhq1_ammobox) then {

hum1 removeAction hum1unload;
hint "Nothing to unload!";

} else {
// Since it's alive, make sure the engine is off on the MHQ.
if (!isEngineon hum1) then {

	// Detach it, and move it 10m behind the MHQ, on the ground.
	detach mhq1_ammobox;
	_worldPos = hum1 modelToWorld [0,-5,0];
	mhq1_ammobox setPos [_worldPos select 0, _worldPos select 1, 0];

	hum1 removeAction hum1unload;

	addactionW = execVM "addActionW.sqf";
	waitUntil {scriptDone addactionW};

} else {
	// If the engine was running, warn the user.
	hint "You can't unload while your engine is running!";
};
};

The first player that runs the load.sqf can use it like supposed. The one that tries afterwards can't. He gets the "Load ammobox to hummer1" but it won't do anything. When the ammobox is loaded to the hummer by the first guy the menu "Load ammobox to hummer1" doesnt desapear by the second guy, only by the first guy.

What could be wrong with my scripts? I just can't see it...

Share this post


Link to post
Share on other sites

Would I have to make hum1jumbo = false; in the end of attach_ammoboxhum1.sqf to make other units able to use the command?

Share this post


Link to post
Share on other sites

I am still lost with this. Can anyone help me please? It's the last thing that needs to be sorted before the mission is ready for testing.

Share this post


Link to post
Share on other sites
I am still lost with this. Can anyone help me please? It's the last thing that needs to be sorted before the mission is ready for testing.

Yes you need to place this at the end of attach_ammoboxhum1.sqf

hum1jumbo = false;
publicVariable "hum1jumbo";

As to why the addAction is not removing for all players,

Post addActionW.sqf so that we can take a look at it, I suspect your problem is in there.

Share this post


Link to post
Share on other sites

Okay, I will try to put that in there. Do I have to make the trigger that waits for the hum1jumbo to become true, to a repeatable trigger?

Here is the addActionW.sqf:

if (!isServer) exitWith {};
// Addactions again to WEST


	// Add the action to load it again boat.
	heli1load = heli1 addaction ["Load ammobox to heli", "attach_ammoboxheli1.sqf"];

	// Add the action to load it again boat.
	heli2load = heli2 addaction ["Load ammobox to heli", "attach_ammoboxheli2.sqf"];

	// Add the action to load it again boat.
	heli3load = heli3 addaction ["Load ammobox to heli", "attach_ammoboxheli3.sqf"];

	// Add the action to load it again boat.
	heli4load = heli4 addaction ["Load ammobox to heli", "attach_ammoboxheli4.sqf"];

	// Add the action to load it again boat.
	her1load = her1 addaction ["Load ammobox to hercules", "attach_ammoboxher1.sqf"];

	// Add the action to load it again boat.
	hum1load = hum1 addaction ["Load ammobox to hummer", "attach_ammoboxhum1.sqf"];

	// Add the action to load it again boat.
	hum2load = hum2 addaction ["Load ammobox to hummer", "attach_ammoboxhum2.sqf"];

	// Add the action to load it again boat.
	hum3load = hum3 addaction ["Load ammobox to hummer", "attach_ammoboxhum3.sqf"];

	// Add the action to load it again boat.
	truck1load = truck1 addaction ["Load ammobox to truck", "attach_ammoboxtruck1.sqf"];

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  

×