Home   Help Search Login Register  

Author Topic: addPublicVariableEventHandler questions...  (Read 5249 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
addPublicVariableEventHandler questions...
« on: 02 Jul 2009, 16:54:59 »
Dear friends,

In my mission I only want the camera intro to be shown the first time when the server starts the mission. JIP players should not get the intro at all, only players who attend the initial start.

I'm starting to suspect that only the "addPublicVariableEventHandler" command can save me from additional woes. I looked it up in the comref:

Code: [Select]
"mypublicVar" addPublicVariableEventHandler {hint ((_this select 0) + " has been modified to: " + str (_this select 1))}
Great !!! I still don't know how to use it and my questions are these:

- Where do I add this eventhandler in my case, on all computers or just the server ?

- If on all... let's say I have skipintro = false in init.sqf which is set to true by the server after the intro is done. When a new player JIPs his/hers init.sqf will reset the variable to false again ?

- If only on the server, will the eventhandler fire quick enough for a player (during the briefing section) to make the new players machine skip the intro when the mission starts?

- Is anyone patient and kind enough to describe how and where to initiate this command and also what the actual EH script would look like ? You could even use "skipintro" as a variable example if you can't come up with anything better :whistle:

PLEEEEEASE  :weeping:

Laggy
« Last Edit: 02 Jul 2009, 16:56:52 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline i0n0s

  • Moderator
  • *****
Re: addPublicVariableEventHandler questions...
« Reply #1 on: 02 Jul 2009, 18:52:45 »
addPublicVariableEventHandler only raise if a variable has been modified with setVariable, but not if it is a JIP or not.
The solution for your problem is "player".

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addPublicVariableEventHandler questions...
« Reply #2 on: 02 Jul 2009, 19:06:27 »
In init.sqf (at time == 0, so not after and sleeps or waitUntils in the init.sqf) (not earlier, not later), then
Code: [Select]
if ((not isDedicated) and (isNull player)) then { ...I am a JIPPEE... };
So what you want is:
Code: [Select]
if ((not isNull player) and (not skipintro)) then { ...play intro... };
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: addPublicVariableEventHandler questions...
« Reply #3 on: 02 Jul 2009, 19:55:57 »
Code: [Select]
if ((not isNull player) and (not skipintro)) then { ...play intro... };
But how am I sure that the players machine has recognized "skipintro"?
And do JIPEEEs get the PVd values automatically when joining?

I thought the server had to broadcast any "in mission" variable changes to every JIPEEE individually when they join the session.

What if I exec the intro script from a trigger instead... condition: showintro. PVd true or false from the server.
« Last Edit: 02 Jul 2009, 20:00:49 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addPublicVariableEventHandler questions...
« Reply #4 on: 03 Jul 2009, 01:03:07 »
PV values are synced to all players, including those that JIP. The easiest way to wait for all values to be synced is to use:
Code: [Select]
_isJIP = ((not isDedicated) and (isNull player));
// PV values might or might not have been synced by now.
waitUntil { not isNull player };
// All PV values will definitely have been synced by now.
if ((not _isJIP) and (not skipintro)) then { ...play intro... };
What I would ask, however, is why skipintro is synced from the server anyway? Surely it is a value derived from param1/param2 value so that the client will have it automatically without having to sync?
Code: [Select]
skipIntro = (param2 == 0); // Where the options are "skip intro" => 0, "show intro" => 1
if ((not isNull player) and (not skipintro)) then { ...play intro... };
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: addPublicVariableEventHandler questions...
« Reply #5 on: 03 Jul 2009, 01:46:58 »
Can't get the parameters to work in ArmA2  :weeping:
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addPublicVariableEventHandler questions...
« Reply #6 on: 03 Jul 2009, 13:10:39 »
Oh, I haven't tried to use them, so no idea why params are not working for you. I'd advise you to look at how they are handled for one of the BIS MP missions and see if you can find out what has changed.

Still, params do work in A2 (BIS uses them) and they are the solution to your problem. Just because you didn't get them working doesn't mean another method is the correct one.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: addPublicVariableEventHandler questions...
« Reply #7 on: 03 Jul 2009, 14:54:45 »
Finally got parameters working... Thanks  :D

I have this solution to make it work in SP/HOST/DEDI. "skipintro" is PVd by server, false in beginning of servers init.sqf and true at the end of film.sqs when the intro is over.

Last bit of common init.sqf
Code: [Select]
if (! (isMultiplayer)) then {[] exec "film.sqs"};

waitUntil { ! (isNil "skipintro") };

if ((param1 == 0) AND ! (skipintro)) then {[] exec "film.sqs"};

Would this work?
Thanks for your patience...
« Last Edit: 03 Jul 2009, 15:12:06 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addPublicVariableEventHandler questions...
« Reply #8 on: 03 Jul 2009, 16:14:50 »
No, because PVs are updated for everyone, JIP or not. Thus, the value being true doesn't mean anything.
Code: [Select]
// AT TOP OF INIT.SQF:
private "_showIntro";

if (isMultiplayer) then
{
   // Multiplayer get choice, but never see it if JIP.
   _showIntro = (param1 == 1) and (not isDedicated) and (not isNull player);
}
else
{
   // Single player people like intros.
   _showIntro = true;
};

// AT BOTTOM OF INIT.SQF

if (_showIntro) then { [] exec "film.sqs" };
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: addPublicVariableEventHandler questions...
« Reply #9 on: 03 Jul 2009, 18:03:25 »
Hi and thanks Spooner,

However when it comes to JIP I'm as you know not the sharpest knife in the box.

Quote
No, because PVs are updated for everyone, JIP or not. Thus, the value being true doesn't mean anything.

Sorry for being really dense here, but will my example not work when I have in everyones init.sqf
Code: [Select]
if (isServer) then {skipintro = false; publicVariable "skipintro"};
and in end of film.sqs which is also run on all machines
Code: [Select]
if (isServer) then {skipintro=true; publicVariable "skipintro"};
If skipintro is PVd true by the server from the moment the intro ends, how can the JIPEEE not recognize isNil "skipintro" when PVs are updated by everyone? The JIPEEE doesn't read the variable through the init.sqf, only the server reads it and broadcasts the variable to the JIPEEE. Right?

Also in your example I don't understand how the JIPEEEs will not see the intro. As soon as the JIP player is not Null, he'll get the same deal as any other player.

OR: Is the "isMultiplayer" command something that's not true for JIPEEEs?

Like I said, sorry for being so dense, but I just really want to understand this stuff. making a good mission JIP friendly is a real hazzle for me.


Thanks again,

Laggy
« Last Edit: 03 Jul 2009, 18:10:21 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addPublicVariableEventHandler questions...
« Reply #10 on: 03 Jul 2009, 20:46:45 »
Quote
Also in your example I don't understand how the JIPEEEs will not see the intro. As soon as the JIP player is not Null, he'll get the same deal as any other player.
At the start of init.sqf player is null only on dedi or JIP (not on SP, MP host or MP client who doesn't JIP). This is when the value is actually being tested (time == 0), not at whatever time the player object gets created for jipees, which is guaranteed to be when (time > 0).

Your system will sort of work, but is unnecessarily using a broadcast at a time when people are still connecting (always avoid broadcasts when they are not actually needed!). Also, if the intro is 60 seconds long, then anyone who JIPs in at 59s will see the full intro.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: addPublicVariableEventHandler questions...
« Reply #11 on: 04 Jul 2009, 02:04:45 »
Quote
At the start of init.sqf player is null only on dedi or JIP

Thank you very much Spooner  :good: This is the most vital info so far regarding JIPEEEs.

You managed to sharpen my knife a little  :P

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: addPublicVariableEventHandler questions...
« Reply #12 on: 14 Jul 2009, 19:53:40 »
In init.sqf (at time == 0, so not after and sleeps or waitUntils in the init.sqf) (not earlier, not later), then

if ((not isDedicated) and (isNull player)) then { ...I am a JIPPEE... };

Very good advice. Thanks Spooner. But one thing remains unclear. How do I make certain that time == 0 when I do the if-then statement? Is it enough if I run the code at the very top of init.sqf, or did I miss part of your explanation?

Edit: cleared away messy quote paragraph
« Last Edit: 14 Jul 2009, 22:28:08 by nominesine »
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addPublicVariableEventHandler questions...
« Reply #13 on: 16 Jul 2009, 14:01:38 »
Well, if the code is at the top of init.sqf, then it is, of course, run at time==0. Time will be 0 until you get to a waitUntil or sleep command, both of which will increase time (well, strictly, waitUntil only may increase time, depending on what it contains, but easier to say that it does than fully explain that). Also, calling a function that delays time with either of those commands will increase the value of time.

If you are unsure about the time at a particular point, put a check just above your code. It will throw up an error if time has advanced (that is, if the briefing has completed and the timer has begun).
Code: [Select]
assert (time == 0)
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: addPublicVariableEventHandler questions...
« Reply #14 on: 16 Jul 2009, 14:37:45 »
Okay, thanks again. And please don't throw a fit over my next question but would the same rule apply if a similar statement was used in *cough* init.sqs?

Or are such outdated scripting techniques too slow in these modern JIP-days?

EDIT: corrected misprinted init.sqm to init.sqs to avoid confusion with the mission core file.
« Last Edit: 17 Jul 2009, 14:58:21 by nominesine »
OFPEC | Intel Depot
RETARDED Ooops... Retired!