Jump to content

Recommended Posts

Hello Community,

 

First off im new to this forum and im not very good at scripting in ARMA 3. Im the typically copy & paste scripter :)

Im currently working at a Custom Sector B Mission. Your task is to destroy / defend the objective. I used this script for my mission: 

http://www.armaholic.com/page.php?id=24272

 

In the SP there arent any problems, But there are a few problems when you play this in the MP.

 

Problems:

  • Timer issue. The countdown timer is on every client different. It means that my timer for example is on 60min while my friends timer is on 55min.

 

  • Respawn Tickets. The next issue are the respawn tickets (Lives). If Blufor (Attackers) dies 15 times the mission will be over and Opfor wins. In the SP the respawn tickets are working but not for the MP. Sometimes it does work and sometimes it doesnt work. Its totally random in the MP.  

 

Here are my scripts:

 

 

 

description.ext

 

respawn = 3;
respawnDelay = 15;
respawnVehicleDelay = 60;
respawnDialog = 0;
respawnTemplates[] = {"Revive", "MenuPosition"};
respawnOnStart = -1;

class RscTitles
{
	#include "scripts\hud\hud_dialog.cpp"	
};

class Header
{
	gameType=Coop;
	minPlayers=2;
	maxPlayers=10;
};

author = "Grimm"; 
onLoadName = "Sector B";
onLoadMission = "Protected By High Walls And The Worlds Top Trained Elite Mercenaries";
loadScreen = "images\loadScreen.jpg";

class Params
{	
	
	class ViewDistance
	{
		title = "View distance (in metres)";
		values[] = {500,1000,2000,5000};
		// When 'texts' are missing, values will be displayed directly instead
		default = 1000;
		file = "setViewDistance.sqf"; // (Optional) Script called when player joins, selected value is passed as an argument
	};
	
	class vidas
	{
		title = "Tickets";
		values[] = {5,10,15,20,25,30,35,40,45,50};
		texts[] = {"5", "10", "15", "20", "25", "30", "35", "40", "45", "50"};
		default = 15;
	};
	
	class tiempo
	{
		title = "Time";
		values[] = {70,75,80,85,90,95,100,105,110,115,120};
		texts[] = {"70", "75", "80", "85", "90", "95", "100", "105", "110", "115", "120"};
		default = 120;
	};
	
	class Daytime
	{
		title = "World Time";
		texts[] = {"Morning","Day","Evening","Night"};
		values[] = {6,12,16,0};
		default = 12;
		function = "BIS_fnc_paramDaytime"; // (Optional) Function called when player joins, selected value is passed as an argument
 		isGlobal = 1; // (Optional) 1 to execute script / function locally for every player who joins, 0 to do it only on server
	};

};


class CfgNotifications
{

	class B0
	{
		title = "ATTENTION";
		iconpicture = "icons\defuse.paa";
		description = "The bomb has been defused";
		color[] = {0,1,0,0.8};
		priority = 7;
		difficulty[] = {"netStats"};
	};
	class B1
	{
		title = "ATTENTION";
		iconpicture = "icons\bomba.paa";
		description = "The bomb has been activated";
		color[] = {1,0,0,0.6};
		priority = 7;
		difficulty[] = {"netStats"};
	};
	class R1
	{
		title = "Objective destroyed";
		iconpicture = "icons\win.paa";
		description = "The target has been destroyed";
		color[] = {1,0,0,0.6};
		priority = 7;
		difficulty[] = {"netStats"};
	};
};

class CfgDebriefing
{  
	class Blufor
	{
		title = "Blufor wins";
		subtitle = "";
		description = "";
		pictureBackground = "";
	};
	class Opfor
	{
		title = "Opfor wins";
		subtitle = "";
		description = "";
		pictureBackground = "";
	};
};

 

init,sqf

 

publicVariable "tempo","bomba","ronda","vidas","tiempo","segundos","minutos";


if (time < 10) then {
 setDate [2048, 7, 6, (paramsArray select 3), 1];
vidas = paramsArray select 1;
tiempo = paramsArray select 2;
};

_null = [] execVM "scripts\motor.sqf";
_null = [] execVM "scripts\tiempo.sqf";
_null = [] execVM "scripts\icono.sqf";

enableSaving [false, false];
enableSentences false; //Disables auto spotting radio chatter


if ( (!isServer) && (player != player) ) then
{
waitUntil {player == player};
waitUntil {time > 10};
};

if !(isnull player) then {
[] spawn {
			_colorEast = EAST call BIS_fnc_sideColor;
			_colorWest = WEST call BIS_fnc_sideColor;
			{_x set [3, 0.73]} forEach [_colorEast, _colorWest];
			if (side player == east) then {
			[getmarkerPos "orbitopfor","Defend all the objectives!",5,30,250,0,
			[["\a3\ui_f\data\map\Markers\NATO\n_support.paa", _colorEast, markerPos "orbitopfor", 2, 1, 0, "Opfor", 0],   
			["\a3\ui_f\data\map\Markers\NATO\n_support.paa", _colorWest, markerPos "orbitblufor", 2, 1, 0, "Blufor", 0]]]
			spawn BIS_fnc_establishingShot;
			playMusic "Track09_Night_percussions";
			};
			if (side player == west) then {
			[getmarkerPos "orbitblufor","Destroy all the objectives!",15,120,140,0,
			[["\a3\ui_f\data\map\Markers\NATO\n_support.paa", _colorEast, markerPos "orbitopfor", 2, 1, 0, "Opfor", 0],   
			["\a3\ui_f\data\map\Markers\NATO\n_support.paa", _colorWest, markerPos "orbitblufor", 2, 1, 0, "Blufor", 0]]] 
			spawn BIS_fnc_establishingShot;
			playMusic "Track09_Night_percussions";
			};			
		};
	 	waitUntil {!isnil "BIS_fnc_establishingShot_playing" && {!BIS_fnc_establishingShot_playing}};
		[] call compile preprocessFileLineNumbers "scripts\hud\hud_create.sqf";
};

[
		20, // seconds to delete dead bodies (0 means don't delete) 
		120, // seconds to delete dead vehicles (0 means don't delete)
		60, // seconds to delete dropped weapons (0 means don't delete)
		240, // seconds to deleted planted explosives (0 means don't delete)
		120 // seconds to delete dropped smokes/chemlights (0 means don't delete)
	] execVM "repetitive_cleanup.sqf";


	
	
	
	
{
	_x setSkill ["aimingspeed", 0.1];
	_x setSkill ["spotdistance", 0.1];
	_x setSkill ["aimingaccuracy", 0.1];
	_x setSkill ["aimingshake", 0.1];
	_x setSkill ["spottime", 0.1];
	_x setSkill ["spotdistance", 0.5];
	_x setSkill ["commanding", 1];
	_x setSkill ["general", 1];
} 	forEach allUnits;





if (local player) then {
player enableFatigue false;
player addEventhandler ["Respawn", {player enableFatigue false}];
}; 






waitUntil { !isNull player }; // Wait for player to initialize

// Compile scripts
getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf';
setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf';

// Save loadout every 2 seconds
[] spawn {
while{true} do {
if(alive player) then {
loadout = [player,["repetitive"]] call getLoadout;
};
sleep 2;
};
};

// Load saved loadout on respawn
player addEventHandler ["Respawn", {
[player,loadout] spawn setLoadout;
}
];

 

OnPlayerRespawn.sqf

 

If (Side Player == west) then {
	vidas = vidas - 1;
};

if ( (!isServer) && (player != player) ) then
{
waitUntil {player == player};
};

if (player == player) then {
		[] call compile preprocessFileLineNumbers "scripts\hud\hud_create.sqf";
};

 

motor.sqf

 

					
if (isServer) then {

	tempo = 200;
	publicVariable "tempo";
	bomba = 3;
	publicVariable "bomba";
	ronda = 1;
	publicvariable "ronda";

	vidas = ParamsArray Select 1;
	publicVariable "vidas";
	
	minutos = ParamsArray Select 2;
	publicVariable "minutos";
	segundos = 1;
	publicVariable "segundos";	

			
};


	

while {true} do
{
			call compile preprocessFileLineNumbers "scripts\hud\hud_update.sqf";
			_side = side player;

			
				
			//transcurso de las rondas
			
			if ((ronda == 1) and ((tempo == 0) or (tempo < 0))) then {
				explosion = "Bo_GBU12_LGB_MI10" createVehicle (getMarkerPos "explosion1");	
				tempo = 200;
				bomba = 3;
				ronda = ronda + 1;
				["R1"] call bis_fnc_showNotification; 
				itembomba setPos (getMarkerPos "sitiobomba2");  
				trgbomba0 setpos (getMarkerpos "sitiobomba2");
				trgbomba1 setpos (getMarkerpos "sitiobomba2");
				"bombamrk" setmarkerpos (getMarkerpos "sitiobomba2");
				"bombamrk" setmarkercolor "ColorGreen";

			};	
			if ((ronda == 2) and ((tempo == 0) or (tempo < 0))) then {
				explosion = "Bo_GBU12_LGB_MI10" createVehicle (getMarkerPos "explosion2");	
				tempo = 200;
				bomba = 3;
				ronda = ronda + 1;
				["R1"] call bis_fnc_showNotification; 
				itembomba setPos (getMarkerPos "sitiobomba3");  
				trgbomba0 setpos (getpos itembomba);  
				trgbomba1 setpos (getpos itembomba);
				"bombamrk" setmarkerpos (getpos itembomba);
				"bombamrk" setmarkercolor "ColorGreen";

			};
			if ((ronda == 3) and ((tempo == 0) or (tempo < 0))) then {
				explosion = "Bo_GBU12_LGB_MI10" createVehicle (getMarkerPos "explosion3");	
				tempo = 200;
				bomba = 3;
				ronda = ronda + 1;
				["R1"] call bis_fnc_showNotification; 
				itembomba setPos (getMarkerPos "sitiobomba4");  
				trgbomba0 setpos (getpos itembomba);  
				trgbomba1 setpos (getpos itembomba);
				"bombamrk" setmarkerpos (getpos itembomba);
				"bombamrk" setmarkercolor "ColorGreen";
			};
			if ((ronda == 4) and ((tempo == 0) or (tempo < 0))) then {
				explosion = "Bo_GBU12_LGB_MI10" createVehicle (getMarkerPos "explosion4");	
				tempo = 200;
				bomba = 3;
				ronda = ronda + 1;
				["R1"] call bis_fnc_showNotification; 
				itembomba setPos (getMarkerPos "sitiobomba5");  
				trgbomba0 setpos (getMarkerPos "sitiobomba5");
				trgbomba1 setpos (getMarkerPos "sitiobomba5");
				"bombamrk" setmarkerpos (getpos itembomba);
				"bombamrk" setmarkercolor "ColorGreen";
			};
			if ((ronda == 5) and ((tempo == 0) or (tempo < 0))) then {
				explosion = "Bo_GBU12_LGB_MI10" createVehicle (getMarkerPos "explosion5");	
				"Blufor" call BIS_fnc_endMission;
				ronda = ronda + 1;
			};
				
			
			//Mantiene el trigger con itembomba

			trgbomba0 setpos (getPos itembomba);
			trgbomba1 setpos (getPos itembomba);
	
			
			//Switch de bombas
			if ((ronda == 1) or (ronda == 2) or (ronda == 3) or (ronda == 4) or (ronda == 5)) then {
				
				if (bomba == 1) then {
					tempo = tempo - 1;
					publicVariable "tempo";
					"bombamrk" setmarkercolor "ColorRed";
					alarma setpos (getpos itembomba);
				};
				
				if (bomba == 0) then {
					tempo = 200;
					publicVariable "tempo";
					"bombamrk" setmarkercolor "ColorGreen";
					alarma setpos (getmarkerpos "lejos");
				};
			};
	publicVariable "tempo";
	publicVariable "bomba";
	publicVariable "ronda";
	publicVariable "vidas";
	sleep 1;	
};

 

tiempo.sqf

 

if (isServer) then {
		
	publicVariable "minutos";
	publicVariable "segundos";
	

			
};



while {segundos !=0} do
{
	segundos = segundos - 1;

	
	if ((segundos == 0) and (minutos > 0)) then {
		minutos = minutos - 1;
		segundos = 59
	};

sleep 1;
};




//
//	if (segundos < 10) then {
//	segundos = format ["0%1", segundos];
//	};
//	if (segundos > 10) then {
//	tiempo = format ["%1", segundos];
//	};

 

hud_create.sqf

 

private ["_ui", "_tempo", "_tiempo", "_vidas", "_ronda"];

disableSerialization;
("UiLayer" call BIS_fnc_rscLayer) cutRsc ["DTASHUD","PLAIN"]; 
_ui = uiNamespace getVariable "DTASHUD";

_tempo = _ui displayCtrl 1001;
_tiempo = _ui displayCtrl 1101;
_vidas = _ui displayCtrl 1102;
_ronda = _ui displayCtrl 1002;

{_x ctrlShow true} foreach [_tempo, _tiempo, _vidas, _ronda];

 

hud_update.sqf

 

private ["_ui"];


disableSerialization;

_ui = uiNamespace getVariable "DTASHUD";

(_ui displayCtrl 1001) ctrlSetText format ["%1",tempo];
(_ui displayCtrl 1101) ctrlSetText format ["%1:%2",minutos,segundos];
(_ui displayCtrl 1102) ctrlSetText format ["%1",vidas];
(_ui displayCtrl 1002) ctrlSetText format ["R %1/5",ronda];

 

There are more scripts but i dont think you need them. I think only these scripts are relevant. Let me know if you need anything. I hope you can help me.

 

Sincerely Yours

Grimm

 

And im sorry for my bad english :).

  • Like 1

Share this post


Link to post
Share on other sites

could u please Spoiler ur scripts one by one?

[spoiler]

// your script

[/spoiler]

that would elongate my mouse wheels life so much ;-)

Share this post


Link to post
Share on other sites

could u please Spoiler ur scripts one by one?

[spoiler]

// your script

[/spoiler]

that would elongate my mouse wheels life so much ;-)

Ok i saved your mouse wheel  :D

Share this post


Link to post
Share on other sites

Do it with a seperate sever init maybe? 

Yeah i agree. but i have no clue how to do that.

Share this post


Link to post
Share on other sites
// Compile scripts
getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf';
setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf';

// Save loadout every 2 seconds
[] spawn {
while{true} do {
if(alive player) then {
loadout = [player,["repetitive"]] call getLoadout;
};
sleep 2;
};
};

That's the reason why so many ppl complain about bad fps. Why would you want to save the loadout every 2 seconds? Use an eventHandler.

 

 

 

For your countdown issue: Try this function I wrote a few month ago.

/*
    Author: Revo

    Description:
    Shows a global countdown.

    Parameter(s):
        0: number
    Returns:
    countDownFinished - Only available on the server
*/

if (!isServer) exitWith {};

_countdown = param [0,60];
countdownFinished = false;

for "_i" from 1 to _countDown do
{
    _timeleft = [_countdown - _i] call BIS_fnc_secondsToString;
    [[[_timeLeft],{hintSilent format ["Time left: %1",_this select 0]}],"BIS_fnc_spawn",true] spawn BIS_fnc_MP;
    sleep 1;
};    

countdownFinished = true;

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

×