Jump to content
cobra4v320

Setting up Multiplaryer options using Class Params

Recommended Posts

How to setup Multiplayer options using new class Params:

description.ext

class Params {

class TimeofDay {
	title = "Time of Day";
	values[] = {0, 1, 2, 3, 4, 5, 6, 7};
	texts[] = {"Early Morning", "Morning", "Noon", "Afternoon", "Evening", "Dusk", "Night", "Midnight"};
	default = 3;
	code = "TimeofDay = %1";
};

 	class Weather {
  		title = "Weather Conditions";
   		values[] = {0,1,2,3,4};
   		texts[] = {"Clear", "Overcast", "Light Fog", "Heavy Fog", "Storm"};
   		default = 0;
	code = "Weather = %1";
};

class Environment {
	title = "Enable Environment";
	values[] = {0, 1};
	texts[] = {"False", "True"};
	default = 1;
	code = "Environment = %1";
};

class Visibility {
	title = "Visibility Range";
	values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
	texts[] = {"2000m", "2500m", "3000m", "3500m", "4000m", "4500m", "5000m", "5500m", "6000m", "6500m", "7000m", "7500m", "8000m","8500m","9000m","9500m","10000m"};
	default = 2;
	code = "Visibility = %1";
};

class Grass {
	title = "Grass Resolution";
	values[] = {0, 1, 2, 3, 4};
	texts[] = {"No Grass", "Small Grass", "Medium Grass", "Large Grass", "Max Grass"};
	default = 2;
	code = "Grass = %1";
};

};

init.sqf

// for MP server parameters.
processParamsArray = [] execVM "ParamsArray.sqf";
[] execVM "setMissionConditions.sqf";

ParamsArray.sqf

for [ { _i = 0 }, { _i < count(paramsArray) }, { _i = _i + 1 } ] do
{
_paramName =(configName ((missionConfigFile >> "Params") select _i));
_paramValue = (paramsArray select _i);
_paramCode = ( getText (missionConfigFile >> "Params" >> _paramName >> "code"));
_code = format[_paramCode, _paramValue];
call compile _code;
};

setMissionConditions.sqf

// DECLARE VARIABLES AND FUNCTIONS
private ["_timeOfDay","_weather","_environment","_visibility","_grass","_MissionOvercast","_MissionFog","_MissionRain"];

// WAIT FOR PARAMSARRAY TO BE PROCESSED
waitUntil {scriptDone processParamsArray};

// Conditions are set in the parameters screen (during mission set-up).
_timeOfDay = TimeOfDay;
_weather = weather;
_environment = Environment;
_visibility = Visibility;
_grass = Grass;

// SETS THE TIME OF DAY
switch (_timeOfDay) do {

case 0: {setDate [2014, 5, 11, 4, 50]}; 	// Early Morning
case 1: {setDate [2014, 5, 11, 5, 50]}; 	// Morning
case 2: {setDate [2014, 5, 11, 9, 00]}; 	// Noon
case 3: {setDate [2014, 5, 11, 12, 0]}; 	// Afternoon
case 4: {setDate [2014, 5, 11, 15, 00]};	// Evening
case 5: {setDate [2014, 5, 11, 17, 50]};	// Dusk
case 6: {setDate [2014, 5, 11, 18, 50]};	// Night
case 7: {setDate [2014, 5, 11, 0, 0]};		// Midnight
};

// SETS THE WEATHER CONDITIONS
switch (_weather) do {

case 0: {_MissionOvercast = 00.00; _MissionFog = 00.00; _MissionRain = 00.00}; 	 // Clear
case 1: {_MissionOvercast = 00.60; _MissionFog = 00.10; _MissionRain = 00.30}; 	 // Overcast
case 2: {_MissionOvercast = 00.60; _MissionFog = 00.8125; _MissionRain = 00.10}; // Light Fog
case 3: {_MissionOvercast = 00.60; _MissionFog = 00.96; _MissionRain = 00.20}; 	 // Heavy Fog
case 4: {_MissionOvercast = 01.00; _MissionFog = 00.50; _MissionRain = 01.00}; 	 // Storm
};

0 setOvercast _MissionOvercast;
0 setFog _MissionFog;
0 setRain _MissionRain;

// SETS WHETHER OR NOT THE AMBIENT LIFE AND SOUND IS ACTIVE
switch (_environment) do {

case 0: {enableEnvironment false}; 	// ambient life and sounds off
case 1: {enableEnvironment true}; 	// ambient life and sounds on
};

// SETS THE IN-GAME VIEW DISTANCE
switch (_visibility) do {

case 0: {setViewDistance 2000};
case 1: {setViewDistance 2500};
case 2: {setViewDistance 3000};
case 3: {setViewDistance 3500};
case 4: {setViewDistance 4000};
case 5: {setViewDistance 4500};
case 6: {setViewDistance 5000};
case 7: {setViewDistance 5500};
case 8: {setViewDistance 6000};
case 9: {setViewDistance 6500};
case 10: {setViewDistance 7000};
case 11: {setViewDistance 7500};
case 12: {setViewDistance 8000};
case 13: {setViewDistance 8500};
case 14: {setViewDistance 9000};
case 15: {setViewDistance 9500};
case 16: {setViewDistance 10000};
};

// SETS THE RESOLUTION OF THE GRASS
switch (_grass) do {

case 0: {setTerrainGrid 50}; // no grass
case 1: {setTerrainGrid 25}; // little grass
case 2: {setTerrainGrid 12.5}; // medium grass
case 3: {setTerrainGrid 6.25}; // large grass
case 4: {setTerrainGrid 3.125}; // maximum grass
};

Edited by cobra4v320

Share this post


Link to post
Share on other sites

I found that you can shorten some of the init.sqf lines to these:

init.sqf

setViewDistance (paramsArray select 0); [color="SeaGreen"]this works[/color]

setTerrainGrid (paramsArray select 1); [color="SeaGreen"]this works[/color]

enableEnvironment (paramsarray select 2); [color="Red"]this does not work[/color]

skiptime (paramsArray select 3); [color="Red"]this does not work[/color]

description.ext

class Params	
{	

class View	
{	
title="View Distance";
values[]={1000,2000,3000,4000,5000,6000,7000,8000,9000,10000};
texts[]={"1000m","2000m","3000m","4000m","5000m","6000m","7000m","8000m","9000m","10000m"};
default = 3000;
};	


class Grass	
{	
title="Grass";
values[]={50,25,12.5,6.25,3.125};
texts[]={"No Grass", "Default MP", "Default SP", "More", "Max"};
default = 12.25;
};	


class Environment	
{	
     	title="Enable Environment";
values[]={true,false};
texts[]={"True","False"};
default = true;
};	


class Missiontime	
{	
     	title="Time Of Day";
values[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
texts[]={"00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"};
default=5;
};	

       };	

Share this post


Link to post
Share on other sites

The first two elements of the paramsArray are param1 and param2, so in your init example you'd want to have:

setViewDistance (paramsArray select 2); //this works

setTerrainGrid (paramsArray select 3); //this works

enableEnvironment (paramsarray select 4); //this should work now

skiptime (paramsArray select 5); //this should work now

Share this post


Link to post
Share on other sites

@kylania

That is correct however if you are using the new Class Params, param1 and param2 should be called by paramsArray 0 and paramsArray 1.

When I use your method none of them work anymore.

It looks like I will be using this for a while until I can figure it out.

viewparam = (paramsArray select 0);
if (viewparam == 0) then {setViewDistance 1000};
if (viewparam == 1) then {setViewDistance 2000};
if (viewparam == 2) then {setViewDistance 3000};
if (viewparam == 3) then {setViewDistance 4000};
if (viewparam == 4) then {setViewDistance 5000};
if (viewparam == 5) then {setViewDistance 6000};
if (viewparam == 6) then {setViewDistance 7000};
if (viewparam == 7) then {setViewDistance 8000};
if (viewparam == 8) then {setViewDistance 9000};
if (viewparam == 9) then {setViewDistance 10000};

grassparam = (paramsArray select 1);
if (grassparam == 0) then {setTerrainGrid 50};
if (grassparam == 1) then {setTerrainGrid 25};
if (grassparam == 2) then {setTerrainGrid 12.5};
if (grassparam == 3) then {setTerrainGrid 6.25};
if (grassparam == 4) then {setTerrainGrid 3.125};

environment = (paramsarray select 2);
if (environment == 0) then {enableEnvironment true};
if (environment == 1) then {enableEnvironment false};

timeparam = (paramsArray select 3);
if (timeparam == 0) then {skiptime 0};
if (timeparam == 1) then {skiptime 1};
if (timeparam == 2) then {skiptime 2};
if (timeparam == 3) then {skiptime 3};
if (timeparam == 4) then {skiptime 4};
if (timeparam == 5) then {skiptime 5};
if (timeparam == 6) then {skiptime 6};
if (timeparam == 7) then {skiptime 7};
if (timeparam == 8) then {skiptime 8};
if (timeparam == 9) then {skiptime 9};
if (timeparam == 10) then {skiptime 10};
if (timeparam == 11) then {skiptime 11};
if (timeparam == 12) then {skiptime 12};
if (timeparam == 13) then {skiptime 13};
if (timeparam == 14) then {skiptime 14};
if (timeparam == 15) then {skiptime 15};
if (timeparam == 16) then {skiptime 16};
if (timeparam == 17) then {skiptime 17};
if (timeparam == 18) then {skiptime 18};
if (timeparam == 19) then {skiptime 19};
if (timeparam == 20) then {skiptime 20};
if (timeparam == 21) then {skiptime 21};
if (timeparam == 22) then {skiptime 22};
if (timeparam == 23) then {skiptime 23};

Edited by cobra4v320

Share this post


Link to post
Share on other sites

There's already a perfect tutorial here. And if you look at the bottom you can see where the problems lie with this new system, which will probably be fixed by BIS in a future beta batch.

Share this post


Link to post
Share on other sites

Thanks Mike84 for the reply, I have already read that tutorial and tried the mission. The parameters in that mission do not work. The parameters I posted at the top and the init.sqf file I posted all work 100%. I was just looking for a way to consolidate the scripting down to something simpler.

Share this post


Link to post
Share on other sites
Thanks Mike84 for the reply, I have already read that tutorial and tried the mission. The parameters in that mission do not work. The parameters I posted at the top and the init.sqf file I posted all work 100%. I was just looking for a way to consolidate the scripting down to something simpler.

So you tested your script on a mphost and on a dedicated server? Reason I ask is because the example mission on ofpec only worked on a dedicated server because there is a bug in the new params system.

Share this post


Link to post
Share on other sites

First off im terribly sorry to dig up such an old treath!!

I was working on multiplayer parameters for my mission and experienced the same problems as described above. The problem of non working MPparameters still exists.

Has a solution been found by now for this little problem? I'm very new to mission scripting and really need your help on this one!

init.sqf:

viewparam = (paramsArray select 0);

if (viewparam == 0) then {setViewDistance 1000};

if (viewparam == 1) then {setViewDistance 2000};

if (viewparam == 2) then {setViewDistance 3000};

if (viewparam == 3) then {setViewDistance 4000};

if (viewparam == 4) then {setViewDistance 5000};

if (viewparam == 5) then {setViewDistance 6000};

if (viewparam == 6) then {setViewDistance 7000};

if (viewparam == 7) then {setViewDistance 8000};

if (viewparam == 8) then {setViewDistance 9000};

if (viewparam == 9) then {setViewDistance 10000};

grassparam = (paramsArray select 1);

if (grassparam == 0) then {setTerrainGrid 50};

if (grassparam == 1) then {setTerrainGrid 25};

if (grassparam == 2) then {setTerrainGrid 12.5};

if (grassparam == 3) then {setTerrainGrid 6.25};

if (grassparam == 4) then {setTerrainGrid 3.125};

environment = (paramsarray select 2);

if (environment == 0) then {enableEnvironment true};

if (environment == 1) then {enableEnvironment false};

timeparam = (paramsArray select 3);

if (timeparam == 0) then {skiptime 0};

if (timeparam == 1) then {skiptime 1};

if (timeparam == 2) then {skiptime 2};

if (timeparam == 3) then {skiptime 3};

if (timeparam == 4) then {skiptime 4};

if (timeparam == 5) then {skiptime 5};

if (timeparam == 6) then {skiptime 6};

if (timeparam == 7) then {skiptime 7};

if (timeparam == 8) then {skiptime 8};

if (timeparam == 9) then {skiptime 9};

if (timeparam == 10) then {skiptime 10};

if (timeparam == 11) then {skiptime 11};

if (timeparam == 12) then {skiptime 12};

if (timeparam == 13) then {skiptime 13};

if (timeparam == 14) then {skiptime 14};

if (timeparam == 15) then {skiptime 15};

if (timeparam == 16) then {skiptime 16};

if (timeparam == 17) then {skiptime 17};

if (timeparam == 18) then {skiptime 18};

if (timeparam == 19) then {skiptime 19};

if (timeparam == 20) then {skiptime 20};

if (timeparam == 21) then {skiptime 21};

if (timeparam == 22) then {skiptime 22};

if (timeparam == 23) then {skiptime 23};

description.ext

//////////////////////////////////////////////////////////////////

// Description file for Armed Assault 2

// Created by: Lars

//////////////////////////////////////////////////////////////////

class Header

{

gameType = TEAM;

minPlayers = 1;

maxPlayers = 62;

playerCountMultipleOf = 1;

};

// === Respawn ===============================================>

respawn=3;

respawndelay=10;

respawnDialog=1;

titleParam1 = "Time limit:";

valuesParam1[] = {0, 900, 1800, 2700, 3600, 5400, 7200};

defValueParam1 = 3600;

textsParam1[] = {"Unlimited", "15 min", "30 min", "45 min", "60 min", "90 min", "120 min"};

titleParam2 = "Score to win:";

valuesParam2[] = {10000, 50, 75, 100, 150, 200, 250, 300};

defValueParam2 = 100;

textsParam2[] = {"Unlimited", 50, 75, 100, 150, 200, 250, 300};

class Params

{

class View

{

//paramsArray[0]

title="View Distance";

values[]={1000,2000,3000,4000,5000,6000,7000,8000,9000,10000};

texts[]={"1000m","2000m","3000m","4000m","5000m","6000m","7000m","8000m","9000m","10000m"};

default = 3000;

};

class Grass

{

//paramsArray[1]

title="Grass";

values[]={50,25,12.5,6.25,3.125};

texts[]={"No Grass","Default MP","Default SP","More","Max"};

default = 12.5;

};

class Environment

{

//paramsArray[2]

title="Enable Environment";

values[]={true,false};

texts[]={"True","False"};

default = true;

};

class Missiontime

{

//paramsArray[3]

title="Time Of Day";

values[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};

texts[]={"00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"};

default=11;

};

};

Share this post


Link to post
Share on other sites

You shouldn't just copy paste stuff without knowing how it works. I'm not going to fix the whole thing since it will be better if you figure out how to do it yourself.

Here's an example:

class View {
 title="View Distance";
 values[]={1000,2000,3000,4000,5000,6000,7000,8000,9000,100 00};
 texts[]={"1000m","2000m","3000m","4000m","5000m","6000m","7000m","8000m","9000m","10000m"};
 default = 3000;
};

You have tons of useless IF lines like viewparam == 1 etc, which actually do nothing. None of them will ever be true as the values given in desc.ext are from 1000 to 10000.

So, we can replace those 11 lines with just:

setViewDistance (paramsArray select 0);

It sets viewdistance to the value selected in parameters, no IF stuff required.

Share this post


Link to post
Share on other sites

Can anyone tell me why this does not work?

init.sqf

enableEnvironment (paramsarray select 0);

description.ext

class Params 
{
 	class Environment 
{
   		title = "Enable Environment";
   		values[] = {0, 1};
   		texts[] = {"False","True"};
   		default = 0;
 	};
};

Share this post


Link to post
Share on other sites

Because the command takes a boolean (true/false) and you are giving it a number (0/1).

Share this post


Link to post
Share on other sites

So I have also tried below but that does not work either.

class Params 
{
 	class Environment 
{
   		title = "Enable Environment";
   		values[] = {false, true};
   		texts[] = {"False","True"};
   		default = false;
 	};
};

Share this post


Link to post
Share on other sites

That's because BIS don't want to fix/change the feature where you can use 1/0 as true/false for the desc.ext options.

So, just do:

class Params 
{
 	class Environment 
{
   		title = "Enable Environment";
   		values[] = {0, 1};
   		texts[] = {"False","True"};
   		default = 0;
 	};
};

if ((paramsarray select 0) == 1) then {
 enableEnvironment true;
};

Share this post


Link to post
Share on other sites

Check out top of i_common.sqf in Domination how params array is dealt with. Not sure if relevant to question, but worth a look anyways.

Share this post


Link to post
Share on other sites

Thanks Shk and carlGustaffa for the assistance and I have looked at the f2 framework and the domination folders.

Share this post


Link to post
Share on other sites

This is what works with enableEnvironment

if ((paramsarray select 0) == 1) then {enableEnvironment true} else {enableEnvironment False}

---------- Post added at 09:51 AM ---------- Previous post was at 09:47 AM ----------

Here is a working multiplayer parameters

description.ext

class Params 
{
 	class TimeOfDay 
{
   		title = "Time of Day";
               values[] = {1337,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
	texts[] = {"Random","00.00","01.00","02.00","03.00","04.00","05.00","06.00","07.00","08.00","09.00","10.00","11.00","12.00","13.00","14.00","15.00","16.00","17.00","1800","19.00","20.00","21.00","22.00","23.00"};
               default = 12;
 	};

 	class Weather 
{
   		title = "Weather Conditions";
   		values[] = {0,1,2,3};
   		texts[] = {"Clear","Stormy","Cloudy","Foggy"};
   		default = 0;
 	};

 	class Terrain 
{
   		title = "Enable Grass";
   		values[] = {50,25,12.5,6.25,3.125};
   		texts[]={"No Grass", "Default MP", "Default SP", "More", "Max"};
   		default = 25;
 	};

 	class Environment 
{
   		title = "Enable Environment";
   		values[] = {0, 1};
   		texts[] = {"False","True"};
   		default = 0;
 	};

class ViewDistance
{	
	title = "View Distance:";
	values[] = { 1200, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000};
	texts[] = { "1.2 km", "1.5 km", "2 km", "2.5 km", "3 km", "3.5km", "4 km", "4.5 km", "5 km"};
	default = 2000;
};
};

init.sqf

skiptime (((paramsarray select 0) - daytime + 24) % 24);

switch (paramsarray select 1) do {
 case 1: { 0 setOvercast 0; 0 setRain 0; 0 setFog 0 };
 case 2: { 0 setOvercast 1; 0 setRain 1; 0 setFog 0.2 };
 case 3: { 0 setOvercast 0.7; 0 setRain 0; 0 setFog 0 };
 case 4: { 0 setOvercast 0.7; 0 setRain 1; 0 setFog 0.7 };
};

setTerrainGrid (paramsarray select 2);

if ((paramsarray select 3) == 1) then {enableEnvironment true} else {enableEnvironment false};

setViewDistance (paramsarray select 4);

Share this post


Link to post
Share on other sites

Thanks a lot for the info, guys.

How does one establish a parameter setting the time the mission will run for?

Share this post


Link to post
Share on other sites

Another technique I saw while poking through AAS (I think) is dynamically assigning the parameters to the values itself:

if (isNil "paramsArray") then {
if (isClass (missionConfigFile/"Params")) then {
	for "_i" from 0 to (count (missionConfigFile/"Params") - 1) do {
		_paramName = configName ((missionConfigFile >> "Params") select _i);
           _paramValue = getNumber (missionConfigFile >> "Params" >> _paramName >> "default");
           call compile format ["%1 = %2", _paramName, _paramValue];
	};
};
} else {
for "_i" from 0 to (count paramsArray - 1) do {
       _paramName = configName ((missionConfigFile >> "Params") select _i);
       _paramValue = paramsArray select _i;
       call compile format ["%1 = %2", _paramName, _paramValue];
};
};

Lets say you have:

class P_TimeOfDay 
{
   		title = "Time of Day";
               values[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
	texts[] = {,"00.00","01.00","02.00","03.00","04.00","05.00","06.00","07.00","08.00","09.00","10.00","11.00","12.00","13.00","14.00","15.00","16.00","17.00","1800","19.00","20.00","21.00","22.00","23.00"};
               default = 12;
 	};

Then in your script you can just do for example:

skipTime P_TimeOfDay;

If you run using the editor the parameters default to the default values. I like this method better than the index selecting, and think it is more readable.

Share this post


Link to post
Share on other sites
How to setup Multiplayer options using new class Params:

Sorry to dig up this thread, I want to ask how to add other parameters in the same place. I saw some mission seems have additional parameter, isn't it?

If so, how can I add, especially what is the "code" variable for new parameter? If not, please tell me how to let player set something before mission start, thx.

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

×