OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: icarus_uk on 21 Feb 2004, 03:06:21

Title: OnMapClick and making it public
Post by: icarus_uk on 21 Feb 2004, 03:06:21
I have a script that relies on a map click.

I know that map clicks are client side only, and have to then be made public to everyone else and the server, the question is how I do this.

OnMapClick parses the variable _pos to another script, where it is made into a public variable.

But how do I make all the server, and the other clients know that the click has happened, and this needs to run the relative script using the variable _pos ?
Title: Re:OnMapClick and making it public
Post by: Chris Death on 23 Feb 2004, 14:05:36
What about this one:


a = 0
b = 0
clicked = false

onMapSingleClick {a = (_pos select 0); b = (_pos select 1); clicked = true"publicVariable _x" forEach [a,b,clicked]}

@clicked

onMapSingleClick {}
_pos = [a,b]


And voilla - you have transferred the position array _pos to
every participiant in the network, and all were waiting for
the click to be clicked wherever  ;)

~S~ CD
Title: Re:OnMapClick and making it public
Post by: icarus_uk on 24 Feb 2004, 16:31:21
Ok, part of my brain dribbled out of the side of my head because of that.

My current mapclick script looks like this;


hint "select map location"

onMapSingleClick {[_pos] exec "radio_arty.sqs"}

exit


Now where do I add in your lines of code?
Title: Re:OnMapClick and making it public
Post by: Chris Death on 24 Feb 2004, 16:48:01
Code: [Select]
a = 0
b = 0
clicked = false

onMapSingleClick {a = (_pos select 0); b = (_pos select 1); clicked = true"publicVariable _x" forEach [a,b,clicked]}

@clicked

onMapSingleClick {}
_pos = [a,b]

[_pos] exec "radio_arty.sqs"

or instead of the last two lines you could also say:

[a,b] exec "radio_arty.sqs"

The difference would then be:

using [_pos] exec "blabla"

would look in radio_arty.sqs like:

_whatevernameyouchoose = _this select 0

result is a 2d array

using [a,b] exec "blabla"

would look in radio_arty.sqs like:

_posa = _this select 0
_posb = _this select 1

result is:

a seperate x/y coordinate splitted into two numeric variables

~S~ CD
Title: Re:OnMapClick and making it public
Post by: icarus_uk on 24 Feb 2004, 17:36:47
Quality.  Ive not tested it in mplayer yet, but its still working in the editor.  Which is a good sign :)
Title: Re:OnMapClick and making it public
Post by: Chris Death on 24 Feb 2004, 18:16:56
Just noticed a syntax typo:  :-[

Code: [Select]
onMapSingleClick {a = (_pos select 0); b = (_pos select 1); clicked = true"publicVariable _x" forEach [a,b,clicked]}

between: clicked = true

and: "publicVariable .....

i was missing a semicolon.

correct line is:

Code: [Select]
onMapSingleClick {a = (_pos select 0); b = (_pos select 1); clicked = true; "publicVariable _x" forEach [a,b,clicked]}

Just in case you haven't already noticed my typo by yourself

~S~ CD
Title: Re:OnMapClick and making it public
Post by: icarus_uk on 24 Feb 2004, 19:42:35
Hehe yes I did.

I also had to move the

"publicVariable _x" forEach [a,b,clicked]

outside of the map click {}'s as it didnt work. Publicvariable needs to have the varaible in "quotes",  and

"publicVariable "_x"" forEach [a,b,clicked]

Wasnt working.  So I now just do them all seperately one after the other, not as a foreach.

Title: Re:OnMapClick and making it public
Post by: Chris Death on 24 Feb 2004, 21:58:46
Nah icarus, i don't think so

publicVariable might not been working upon the missing
semicolon.

It's always allowed to use one pair of quotation marks "",
and it's allowed to use endless (not sure if really endless),
{} brackets.

Maybe you could also try to leave out the quotation marks and
replace it by those brackets:

Code: [Select]
onMapSingleClick {a = (_pos select 0); b = (_pos select 1); clicked = true; {publicVariable _x} forEach [a,b,clicked]}

But still i say this one should work too:

Code: [Select]
onMapSingleClick {a = (_pos select 0); b = (_pos select 1); clicked = true; "publicVariable _x" forEach [a,b,clicked]}

~S~ CD
Title: Re:OnMapClick and making it public
Post by: icarus_uk on 25 Feb 2004, 00:19:41
I already tried and it gave me errors.

The {brackets} however do work.