OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Resources Beta Testing & Submission => Topic started by: hoz on 27 Aug 2009, 18:08:33

Title: MP Parameters Example (Accepted)
Post by: hoz on 27 Aug 2009, 18:08:33
I put together an example of how to setup the new feature provided by the latest beta patch  (http://www.arma2.com/beta-patch.php)that allows you to include more then 2 params options in the description.ext.

I've also included a short tutorial on the subject. If you feel I need to include anything else let me know!


Tutorial (http://www.ofpec.com/tutorials/index.php?action=view&id=212)
Example Mission (http://www.ofpec.com/ed_depot/index.php?action=details&id=641)

Basically the new addition is the params class within the description.ext.

Code: [Select]
class Params
{
        class DayTime
        {
//paramsArray[0]
                title = "Time Of Day";
                values[] = {0,16,8};
                texts[] = {"Dusk","Midday","Dawn"};
                default = 16;
        };
        class Revive
        {
// paramsArray[1]
                title = "Number of Revives:";
                values[] = {2000,1000,20,10,7,5};
                texts[] = {"No Revive","Infinite - Cadet","20 - Easy ","10 - Normal","7  - Hard","5  - Extreme"};
                default = 20;
        };
class Grass
        {
// paramsArray[2]
                title = "Grass Options";
                values[] = {0, 1, 2};
                texts[] = {"NoGrass", "Medium", "Normal"};
                default = 0;
        };
};
Title: Re: MP Parameters Example (Accepted)
Post by: i0n0s on 28 Aug 2009, 01:13:56
 :good: :clap:
Title: Re: MP Parameters Example (Accepted)
Post by: mikey on 28 Aug 2009, 01:33:50
I love it. About time BIS expanded the amount of parameters  :good:
Title: Re: MP Parameters Example (Accepted)
Post by: norrin on 28 Aug 2009, 03:34:55
Sounds great and this will be enormously useful in expanding the player's options in the lobby.  Thanks for sorting out our little problem mate. :)
Title: Re: MP Parameters Example (Accepted)
Post by: Dr Eyeball on 28 Aug 2009, 09:14:48
This is great news. BIS must have finally discovered the Arma 2 wish list.

Why isn't this feature mentioned in the beta change logs? (It's only in the readme, which most sites do not include in the announcements.)
Title: Re: MP Parameters Example (Accepted)
Post by: kju on 28 Aug 2009, 10:14:13
It is listed and explained at the end of the readme..  ::)
Title: Re: MP Parameters Example (Accepted)
Post by: fleepee on 29 Aug 2009, 10:21:49
It doesn't work in my mission or the example mission with my game patched in 1.03...
I've read: "Note: This only works with the latest beta build!"

What version does it need to work?
Title: Re: MP Parameters Example (Accepted)
Post by: kju on 29 Aug 2009, 11:04:00
http://www.arma2.com/beta-patch.php
Title: Re: MP Parameters Example (Accepted)
Post by: ferstaberinde on 07 Sep 2009, 10:05:14
Encountered a possible bug today, wondered if anyone else can vefrify before I report to BIS:

Steps to repeat (A):

1. Create a mission with at least 2 parameters using the new class-based method described by Hoz.

2. Ensure the default value of your first parameter is not 0 (zero).

3. Ensure that you do not set or define the old-school Param0/Param1 variables.

4. In a script, get the value of your first parameter using the command: (paramsArray select 2)

5. Test the mission on your LOCAL NON-DEDICATED server.

Expected behaviour: The script should return the selected value for your first parameter.

Actual behaviour: The script returns the value 0 for your first parameter, regardless of your  selection in the mission parameters screen.

++++

Steps to repeat (B):

1-4. As per (A) above.

5. Test the mission on your REMOTE DEDICATED server.

Expected behaviour: The script should return the selected value for your first parameter.

Actual behaviour: As per expected behaviour.

++++

So it works on dedicated server, but not on a non-dedicated server. Anyone else encounter this?

Note: I am using v1.03.58972
Title: Re: MP Parameters Example (Accepted)
Post by: mikey on 07 Sep 2009, 13:41:10
Ok, tested this, and in SP and in MP host mode paramsArray is always of size x - 2 (because they're missing param1 and param2). In dedicated mode param1 and param2 are put in the beginning of the paramsArray, causing all the index values to shift by 2.

I can't really see this as desirable behaviour (even by BIS standards), so it's probably a bug.


Btw fer, I don't get a 0 value like you do, but since you only use 2 parameters (paramsArray[0] and paramsArray[1], because in SP and MP host mode param1 and param2 are not included), you are actually grabbing an out of bounds value.
Title: Re: MP Parameters Example (Accepted)
Post by: ferstaberinde on 07 Sep 2009, 15:19:38
Alright, nice to know I'm not going mad. I'll drop BIS a note ...
Title: Re: MP Parameters Example (Accepted)
Post by: mikey on 15 Sep 2009, 17:30:18
Seems like that worked fer, since it works normally now in 1.04 :good:

Btw, to sum it up for people what changed from the beta to the stable release of 1.04:

In the beta the game put param1 and param2 in the start of the paramsArray when on a dedicated server, and not on a MP hosted machine. This caused the array indices to shift by 2.
Now in the 1.04 dedi param1 and param2 are not put in front anymore, and it works perfectly.

Could you update the example mission hoz?

Title: Re: MP Parameters Example (Accepted)
Post by: hoz on 15 Sep 2009, 21:00:37
I did thanks.
Title: Re: MP Parameters Example (Accepted)
Post by: Shuko on 19 Sep 2009, 19:27:44
Is there a way to get the class name? In your example, "DayTime" or "Revive".
Title: Re: MP Parameters Example (Accepted)
Post by: hoz on 22 Sep 2009, 02:32:05
Not sure what you mean 'get the class name'. I suppose it could be gotten with the config commands. Maybe explain a bit further about what you want to do.
Title: Re: MP Parameters Example (Accepted)
Post by: Shuko on 22 Sep 2009, 11:55:40
Well, the idea is that you wouldn't need to worry about remember which element a certain parameter is in the paramsarray. Example:

Code: [Select]
class Params
{
  class Hour {
    title = "Hour";
    values[] = {0,2,4,6,8,10,12,14,16,18,20,22};
    texts[] = {"0000","0200","0400","0600","0800","1000","1200","1400","1600","1800","2000","2200"};
    default = 6;
  };
  class Rain {
    title = "Rain";
    values[] = {0,1,2,3};
    texts[] = {"None","Light","Moderate","Heavy"};
    default = 0;
  };
  class Fog {
    title = "Fog";
    values[] = {0,1,2,3};
    texts[] = {"None","Light","Moderate","Heavy"};
    default = 0;
  };
  class Viewdistance {
    title = "Viewdistance";
    values[] = {0,1,1000,1500,2000,2500,3000,3500,4000,5000,6000};
    texts[] = {"Dynamic","User defined","1000", "1500", "2000", "2500", "3000","3500","4000","5000","6000"};
    default = 0;
  };
  class Targets {
    title = "Targets";
    values[] = {4,6,8,10,0};
    texts[] = {"4","6","8","10","Random 4-10"};
    default = 6;
  };
  class AISkill {
    title = "Difficulty: AI Skill";
    values[] = {1,3,5,7};
    texts[] = {"Easy","Normal","Moderate","Hard"};
    default = 3;
  };
  class AIAmount {
    title = "Difficulty: Amount of AI";
    values[] = {1,2,3,4};
    texts[] = {"Few","Normal","Moderate","Many"};
    default = 2;
  };
  class AA {
    title = "Difficulty: AA (ZU-23)";
    values[] = {0,1,2,3};
    texts[] = {"None","Few","Moderate","Many"};
    default = 1;
  };
  class Planes {
    title = "Planes available";
    values[] = {0,1,2};
    texts[] = {"F35B","AV-8B Harrier","Both"};
    default = 2;
  };
  class ObjectiveDistance {
    title = "Objective distance";
    values[] = {0,1,2};
    texts[] = {"Close","Medium","Any"};
    default = 2;
  };
};

Instead of having to edit the processParams.sqf for each mission, you would automatically get the vars created for each parameter (in this example elements 3-9) by going through all the class names in desc.ext.


Code: [Select]
skiptime (((paramsArray select 0) - daytime + 24) % 24);

switch (paramsArray select 1) do {
  case 0: { 0 setOvercast 0; 0 setRain 0; };
  case 1: { 0 setOvercast 0.8; 0 setRain 0.3; };
  case 2: { 0 setOvercast 0.9; 0 setRain 0.6; };
  case 3: { 0 setOvercast 1; 0 setRain 1; };
};

switch (paramsArray select 2) do {
  case 0: { 0 setFog 0; };
  case 1: { 0 setFog 0.3; };
  case 2: { 0 setFog 0.6; };
  case 3: { 0 setFog 1; };
};

SHK_PARAMS_ViewDistance = paramsArray select 3;
SHK_PARAMS_Targets = paramsArray select 4;
SHK_PARAMS_AISkill = paramsArray select 5;
SHK_PARAMS_AIAmount = paramsArray select 6;
SHK_PARAMS_AA = paramsArray select 7;
SHK_PARAMS_Planes = paramsArray select 8;
SHK_PARAMS_ObjectiveDistance = paramsArray select 9;


Called from init.sqf:
Code: [Select]
execvm "processParams.sqf" spawn {
  waituntil {scriptdone _this};
  if (isserver) then {
  } else {
  };
};
Title: Re: MP Parameters Example (Accepted)
Post by: mikey on 22 Sep 2009, 14:05:32
I was thinking of something similar, but different. What I was thinking about is to store code in the param class, and in your setMissionConditions.sqf file you just loop through every param, get the value and the code that's in the class, and then execute the code with the value as an argument.

I haven't really explored this at all due to lack of time, but if it can be made like this we never ever again have to use pre-defined indices in the paramsArray ever again.
Title: Re: MP Parameters Example (Accepted)
Post by: Shuko on 24 Sep 2009, 20:42:35
Stolen from mikey's thread, with minor modification. Answer to my question:

Code: [Select]
for [{_i = 0},{_i < count(paramsArray)},{_i = _i + 1}] do {
call compile format ["PARAMS_%1 = %2",(configName ((missionConfigFile >> "Params") select _i)),(paramsArray select _i)];
};
Title: Re: MP Parameters Example (Accepted)
Post by: MRO204 on 28 Sep 2009, 21:45:21
back in the day we could use this in a vehilces condition field. How does it work now with the new system??

param1==1

param2==1 && param1==1
etc
Title: Re: MP Parameters Example (Accepted)
Post by: mikey on 28 Sep 2009, 23:30:33
(paramsArray select 0) == 1
Title: Re: MP Parameters Example (Accepted)
Post by: kju on 07 Dec 2009, 12:10:21
Hoz can you please fix the demo mission.

http://www.ofpec.com/tutorials/index.php?action=view&id=212
says paramsArray[2] is the first item in the new class params
This is correct from I understand.

The demo mission instead has:
Code: [Select]
class Params
{
        class DayTime
        {
                //paramsArray[0]
                title = "Time Of Day";

Even more the init.sqf seems wrong to me:

skiptime (paramsArray select 2);
[(paramsArray select 2), "false"] execvm "Grass_Changer\grass_changer.sqf";

vs the class params:
http://pastebin.jonasscholz.de/309

skiptime is 2, yet grass should select 4.

Cheers.
Title: Re: MP Parameters Example (Accepted)
Post by: hoz on 07 Dec 2009, 15:41:52
Done and thanks!
Title: Re: MP Parameters Example (Accepted)
Post by: kju on 08 Dec 2009, 14:41:06
Cheers.  :good: