Jump to content
Sign in to follow this  
Richmuel UK

Making a local script activate globally.

Recommended Posts

I'm having endless trouble at the moment getting my mission functional for MP. It works fine in SP which I now know is because you are the 'player'. But online every person is a different variable.

My script still functions in multiplayer but every single team member has to activate it themselves individually. I need it to be once for all. I'll explain what I'm trying to achieve:

In my mission you have to search through some bags and a briefcase to find a 'file.' Upon finding the file I create new objectives and markers. I do this using a addAction command and create marker script. It functions in the multiplayer .

In the init line of the object i have:

_genAct = CaseX_1 addAction ["Search Case", "intel1.sqs"]

this activates intel1.sqs

_intel = _this select 0

_caller = _this select 1

_id = _this select 2

_intel exec "markers.sqs"

hint "You found a map.\nBriefing Updated."

// Secondary Objective

tskObj4 = player createSimpleTask["Secondary: Investigate Camp"];

tskObj4 setSimpleTaskDescription["The map from those bags shows another NAPA camp <marker name=OP2'>here.</marker> We should search it for more intel.", "Investigate Camp", "Investigate Camp];

// Secondary Objective

tskObj4_1 = player createSimpleTask["Secondary: Clear Checkpoints"];

tskObj4_1 setSimpleTaskDescription["The map from those bags pinpoints the location of 2 NAPA checkpoints <marker name=CP1'>here</marker> and <marker name='CP2'>here.</marker> We must secure them.", "Clear Checkpoints", "Clear Checkpoints];

intel1 = true

_intel removeAction _id

Which activates marker.sqs

_markerstr = createMarker["CP1",[832.33,13989.72,1.53]];

_markerstr setMarkerShape "ICON";

"CP1" setMarkerType "HD_Destroy";

"CP1" setMarkerColor "ColorGreen";

"CP1" setmarkerdir 45;

"CP1" setMarkerText "Checkpoint"

_markerstr = createMarker["CP2",[796.09,13672.65,1.68]];

_markerstr setMarkerShape "ICON";

"CP2" setMarkerType "HD_Destroy";

"CP2" setMarkerColor "ColorGreen";

"CP2" setmarkerdir 45;

"CP2" setMarkerText "Checkpoint"

_markerstr = createMarker["OP2",[259.32,13790]];

_markerstr setMarkerShape "ICON";

"OP2" setMarkerType "Faction_GUE";

"OP2" setMarkerText "NAPA Camp"

intel1=true fires off a trigger which completes the objective.

Basically that allows the player to search a breifcase and 'find' the files creating new objectives and markers to act upon it. But as I said this is a local event. How do I make this activate for everyone? Do I have to use publicvariables? I don't have a clue how to use these, where to put them and how to make them activate all this.

The marker script is the only script which activates for everyone. Also my breifing is only appearing for the first person to enter named player. Everyone else does not get the origional briefing. Some one showed me to a script which makes a hint show as a global hint but I couldn't work out how to use it to fire scripts and objectives off.

This was my first attempt at a map so I may be missing something obvious but no matter how hard i search i could not find exactly what i'm looking for or if i did it went over my head. If someone could kindly take the time and walk me through would be much appreciated. Or perhaps i'm doing this the wrong way. Thanks.

Edited by Richmuel

Share this post


Link to post
Share on other sites

Question about marker, how you get the grid coords...or what ever you got in this line of code

_markerstr = createMarker["CP1",[832.33,13989.72,1.53]];

?

Share this post


Link to post
Share on other sites

Why not simply use the briefing system and have all clients execute the new briefing.sqf. That way you simply leave blank markers where you'll want them in the editor and reference them in the Tasks and players will get waypoints/map marks via that system.

Share this post


Link to post
Share on other sites

@Carpaazi, I placed a man where I wanted the marker then used 'camera.sqs' to lock onto his position, pressed left mouse button then alt+tabbed into notepad and pressed paste. You then find the co-ordinates there.

@Kylania: Do you mean have the objectives and map markers hidden and just reveal them once say a player activates the bag by meeting a condition? Any idea how I'd do this? How do I get all clients to execute something? This is the bit I'm struggling with. Telling something to be executed by ALL clients rather than by just the one who pressed it

Or still if anyone else knows a way to solve it.

Share this post


Link to post
Share on other sites

You can use this to create a task driven "waypoint" marker in game/on map via the briefing system. This will put the orange objective marker on the map. If you want different icons, than you'd have to make it a bit more complicated. hehe

tskTaskNameHere1 setSimpleTaskDestination (getMarkerPos "markerNameHere");

The whole code would be:

tskTaskNameHere1 = player createSimpleTask ["Next Task"];
tskTaskNameHere1 setSimpleTaskDescription ["This is your next task, do it!", "Next Task", "Next Task"];
tskTaskNameHere1 setSimpleTaskDestination (getMarkerPos "markerNameHere");
player setCurrentTask tskTaskNameHere1;
[objNull, ObjNull, tskTaskNameHere1, "ASSIGNED"] execVM "CA\Modules\MP\data\scriptCommands\taskHint.sqf";

Then have each client run that. As for actually getting each client to run it, not entirely sure. :|

Edit: Yes, it is basically the same, just avoids having to create/move markers on the fly.

Edited by kylania

Share this post


Link to post
Share on other sites

Is that not effectively what I have already done in the intel1 script? I think what I need is for someone to explain publicvariables or whatever and how to execute local scripts globally.

Share this post


Link to post
Share on other sites

Inside addAction script: intelFound=true; publicvariable "intelFound";

init.sqf: execvm "intelfound.sqf"

intelfound.sqf: waituntil {intelFound}

Inside intelfound.sqf you can do whatever you like, tasks, markers etc, locally.

Share this post


Link to post
Share on other sites

Oo thankyou. That sounds like it. Where abouts would I add it in the addaction script:

_genAct = CaseX_1 addAction ["Search Case", "intel1.sqs"]

In the brackets or before or after?

Share this post


Link to post
Share on other sites

I would use addPublicVariableEventHandler, that way you can cater for JIP.

Ok, I have'nt done much MP stuff in Arma2, but you could try this:

Init.sqf:

//Assuming you don't have to setup tasks on a dedicated server?
If isServer Then
       {
       RIC_CURRENT_TASK=1 ; PublicVariable "RIC_CURRENT_TASK";
       }
       Else
       {
       "RIC_CURRENT_TASK" addPublicVariableEventHandler {[_this select 1] ExecVM "TaskChanged.sqf"};
       };

TaskChanged.sqf:

_TaskID=_This Select 0;

Switch (_TaskID) Do
       {
       Case 1 :        {//Do Your first objective here};

       Case 2 :        {
                       hint "Map found!\nBriefing Updated.";

                       // Secondary Objective
                       tskObj4 = player createSimpleTask["Secondary: Investigate Camp"];
                       tskObj4 setSimpleTaskDescription["The map from those bags shows another NAPA camp <marker name='OP2'>here.</marker> We should search it for more intel.", "Investigate Camp", "Investigate Camp"];

                       // Secondary Objective
                       tskObj4_1 = player createSimpleTask["Secondary: Clear Checkpoints"];
                       tskObj4_1 setSimpleTaskDescription["The map from those bags pinpoints the location of 2 NAPA checkpoints <marker name='CP1'>here</marker> and <marker name='CP2'>here.</marker> We must secure them.", "Clear Checkpoints", "Clear Checkpoints"];
                       };

       Case 3 :        {//Another objective here};
       };

Your user action intel1.sqf:

_intel = _this select 0;
_caller = _this select 1;
_id = _this select 2;

RIC_CURRENT_TASK=2;
Publicvariable "RIC_CURRENT_TASK";

_intel execVM "markers.sqf";
intel1 = true;
_intel removeAction _id;

Markers would be:

Markers.sqf:

_markerstr = createMarker["CP1",[832.33,13989.72,1.53]];
_markerstr setMarkerShape "ICON";
"CP1" setMarkerType "HD_Destroy";
"CP1" setMarkerColor "ColorGreen";
"CP1" setmarkerdir 45";
"CP1" setMarkerText "Checkpoint";

_markerstr = createMarker["CP2",[796.09,13672.65,1.68]];
_markerstr setMarkerShape "ICON";
"CP2" setMarkerType "HD_Destroy";
"CP2" setMarkerColor "ColorGreen";
"CP2" setmarkerdir 45";
"CP2" setMarkerText "Checkpoint";

_markerstr = createMarker["OP2",[259.32,13790]];
_markerstr setMarkerShape "ICON";
"OP2" setMarkerType "Faction_GUE";
"OP2" setMarkerText "NAPA Camp";

Haven't tested the above scripts, but I hope you get the idea.

Edited by UNN

Share this post


Link to post
Share on other sites

Still can't get it to work :( *pulls hair out*

Wish there was a simple *Execute Globally* command :D If anyone finds a way to get this working you will have my eternal greatfulness :D

My problem is I don't understand what I'm doing with publicvariables ect. Hardest part is having to be on a multiplayer server to test it.

Using my origional script everyone sees the markers its just not the new objectives or messages. I could really use an example mission that uses these scripts.

Using the above I can't even get the action to dissapear let alone the rest of it to work.

Edited by Richmuel

Share this post


Link to post
Share on other sites
Wish there was a simple *Execute Globally* command

There are, your markers for example. But some commands are local, so you have to take that into account.

Using my origional script everyone sees the markers its just not the new objectives or messages. I could really use an example mission that uses these scripts.

Using the above I can't even get the action to dissapear let alone the rest of it to work.

I didn't realize you were working with sqs. The above example was intended to be in sqf. If you check Arma2.rpt you will find a load of script errors. I've edited the example, so it might be worth you trying it again. But you will have to use the exact filenames, with the sqf extension.

Share this post


Link to post
Share on other sites

ah ok, thanks. Do feel like I'm getting closer. You help is much appreciated ;)

Share this post


Link to post
Share on other sites

Thanks for your help but I think this is beyond me unless I can see a working example mission. Will see if I can acheive my aim some simpler way :/ At the moment it gets as far as creating the first marker minus the text, nothing else fires off.

When testing it does it need to be on a dedicated server or will it work in the editor or on a hosted game?

I've now got myself royally confused from what I do with addaction right the way through. :( For now I'll just forget about the searching bags things, put in some simple triggers and hope for the best. Hopefully someone will come up with a similar mission which I can learn from later.

Thanks for putting up with me this far though :)

Share this post


Link to post
Share on other sites

all the code examples above do the right thing. in general terms, what's happening is as follows: -

public variables can be used like this. you prepare a variable the same on every client. When one player does the required action, he changes his copy of the publicised variable and then uses the publicvariable command to broadcast that to all other players.

because all the players are running a script which is waiting for the special variable to change, they receive the updated variable and all of them execute the required script on their own computer.

if you need to use that variable again, at the end of each client's script the variable is reset to it's original value and the wait begins again.

Share this post


Link to post
Share on other sites

Depbo my mission here and check it out. Their should be some stuff that can help.

For the markers I put them in the editor, set all the settings, make it "Empty", then the triggers or scripts set them to the marker I want. Here is a good site for a list of marker types.

Share this post


Link to post
Share on other sites
Inside addAction script: intelFound=true; publicvariable "intelFound";

init.sqf: execvm "intelfound.sqf"

intelfound.sqf: waituntil {intelFound}

Inside intelfound.sqf you can do whatever you like, tasks, markers etc, locally.

I've been using this method however, my arma.rpt fills up with simular to the following:

Error in expression <mission.utes\intelfound.sqf"
waituntil {intelfound};>
 Error position: <intelfound};>

Any ideas?

Share this post


Link to post
Share on other sites
Thanks for your help but I think this is beyond me unless I can see a working example mission.

Don't try and do to much in one go. Also try and get used to debugging your code. You will achieve far more that way, than waiting for someone to provide you with an ideal solution.

For example create a simple mission with an object, call it Object01. Then create an init.sqf with the following:

Init.sqf:

Object01 AddAction ["Activate","ActivateScript.sqf"];

"ACTIVATION_STATUS" addPublicVariableEventHandler {Hint (_this select 1)};

For ActivateScript.sqf use this:

ACTIVATION_STATUS="Someone has activated the user action!";

PublicVariable "ACTIVATION_STATUS";

If you can get that working ok, then you move onto the next step. Let us know how you get on.

Edited by UNN

Share this post


Link to post
Share on other sites
I've been using this method however, my arma.rpt fills up with simular to the following:

Error in expression <mission.utes\intelfound.sqf"
waituntil {intelfound};>
 Error position: <intelfound};>

Any ideas?

Whats the exact error? Undefined var? If so, make it false in init.sqf

Anyway, heres an example with some Richmuels stuff in it:

http://derfel.org/arma2/demo_pubvar.utes/

Share this post


Link to post
Share on other sites

Ah! I can't thankyou enough everyone. Finally got it working I think.

Basically what all you wrote was correct however I was getting confused about where to put the different scripts and what script was what and how they related to the addaction and each other.

Putting up with my lack of knowledge was very much appreciated. I understand the basic scripting it was just transfering it over into multiplayer but now I've got this underwraps I should be away.

Once again, thankyou so much :D

Edit: Unbelievably I worked out why when I tried methods posted at first it didn't work. I was wanting a marker to setdirection at 45 degrees. I now realise i forgot to add a ; afterwards which killed the rest of the script. Typical :D

Edited by Richmuel

Share this post


Link to post
Share on other sites
Whats the exact error? Undefined var? If so, make it false in init.sqf

Yep that's right, cheers for that!

Share this post


Link to post
Share on other sites
Inside addAction script: intelFound=true; publicvariable "intelFound";

init.sqf: execvm "intelfound.sqf"

intelfound.sqf: waituntil {intelFound}

Inside intelfound.sqf you can do whatever you like, tasks, markers etc, locally.

I've just tested this method out in MP, but the intel script - hints, tasks etc, not including the marker creation, only shows for the person who picks it up.

Share this post


Link to post
Share on other sites

UNNs code is sound however the dirty hack you want is something like:

_global="HeliPad" createVehicle ([0,0,0]);

_global setInitCommand "hint ""seen on everymachine"";deleteVehicle this;";

processInitCommands;

sleep 2;

However I recommend getting UNNs code to work, while he says "I haven't done much Arma2 scripting...", I suspect he's being truthful and modest at the same time. He knows what he's doing. :D

Share this post


Link to post
Share on other sites
UNNs code is sound however the dirty hack you want is something like:

_global="HeliPad" createVehicle ([0,0,0]);

_global setInitCommand "hint ""seen on everymachine"";deleteVehicle this;";

processInitCommands;

sleep 2;

However I recommend getting UNNs code to work, while he says "I haven't done much Arma2 scripting...", I suspect he's being truthful and modest at the same time. He knows what he's doing. :D

AAhhh you got it before me!! :p The code I use is

        [] spawn {
           _cone = createVehicle  ["RoadCone",[0,0,0], [], 0, "FLY"];
           _cone setVehicleInit "hint 'I want everyone in MP to see this'";
           processInitCommands;
           deleteVehicle _cone;
        };

Share this post


Link to post
Share on other sites
I've just tested this method out in MP, but the intel script - hints, tasks etc, not including the marker creation, only shows for the person who picks it up.

Works fine. As I said, the demo mission I posted was posted with a Richmuels requests:

The marker script is the only script which activates for everyone. Also my breifing is only appearing for the first person to enter named player. Everyone else does not get the origional briefing. Some one showed me to a script which makes a hint show as a global hint but I couldn't work out how to use it to fire scripts and objectives off.

To show task etc for everyone, just cut-paste them from the pickup.sqf to intel.sqf

You can do whatever you want; pickup for local stuff and intel.sqf for everyone.

Share this post


Link to post
Share on other sites
Works fine. As I said, the demo mission I posted was posted with a Richmuels requests:

Well it doesn't work, so I'll have a look into that demo mission.

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  

×