Forum Jump :

Author Message


Posts: 6
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2016-03-26 21:35        
     
Hi, im learning scripting recently and i cant get my script to work in Multiplayer,
It works in my Editor but in multiplayer it only shows the addAction to place the barrier.
Script:
Init_AddAction = {
	while {true} do {
		waitUntil{(alive player)};
		if(alive player) then
		{
			if(side player == west) then
			{
				player addAction["Tatort absperren<t color='#6699FF'> /_!_\</t>",{call SetzeBarriere;}]; // addAction to place Barrier - team blufor
			}
			else
			{
				if (side player == east) then
				{
					player addAction["Unfallort absperren<t color='#FFE500'> /_!_\</t>",{call SetzeBarriere;}];// addAction to place Barrier - team opfor
				};
			};
		};	
		waitUntil{(!alive player)};
	};
};

if(isServer) then
{
	[[Barriere],"Init_AddAction",[east,west],true] call BIS_fnc_MP;
};

Entferne_Barrieren = {
	while {count nearestObjects[player,["RoadBarrier_F"],30] > 0} do
	{
	waitUntil{(alive player)};
		if(alive player) then
		{
			Remove_Action = player addAction["Entferne Absperrung<t color='#66FF00'> /_!_\</t>",{ // addAction to delete the Barrier
				Barriere = position player nearObjects ["RoadBarrier_F", 30];
		
				_Remove_Item = (Barriere select 0);
				deleteVehicle _Remove_Item;
				sleep 0.1;
				if(count nearestObjects[player,["RoadBarrier_F"],30] < 1) then
				{
					player removeAction Remove_Action;
				};
			}];
		};
	waitUntil{(!alive player)};
	};
};

SetzeBarriere = { // placingBarrier
	if ( count nearestObjects[player,["RoadBarrier_F"],30] < 2 ) then
	{
		Barriere = createVehicle ["RoadBarrier_F",(player modelToWorld [0,5,0]),[],0,"CAN_COLLIDE"];
		Barriere setDir getDir player;
		
		if( count nearestObjects[player,["RoadBarrier_F"],30] > 0 ) then
		{
			[[Barriere],"Entferne_Barrieren",[east,west],true] call BIS_fnc_MP; // jumping to delete Barrier
			player removeAction Remove_Action;
		};
		
	}
	else
	{
		hint "Du kannst nur 2 Barriere im Umkreis von 30m platzieren!"; // you can only place 2 Barriers in range of 30m
	};
};

please help me to fix it, i also tried to add the action to the barrier, but then im the only one who can remove it. i want that Blufor and Opfor can spawn it and every Blutfor/Opfor member should be able to delete it.

Thanks.

This post was edited by H3xag0n (2016-03-27 19:15, 570 days ago)


Author Message


Posts: 83
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name: J.Shock

 
#2 Posted at 2016-03-27 20:13        
     
Create a sqf file named initPlayerLocal.sqf, put these in it:

//initPlayerLocal.sqf
Entferne_Barrieren = 
{
    while {count nearestObjects[player,["RoadBarrier_F"],30] > 0} do
    {
    waitUntil{(alive player)};
        if(alive player) then
        {
            Remove_Action = player addAction["Entferne Absperrung<t color='#66FF00'> /_!_\</t>",{ // addAction to delete the Barrier
                Barriere = position player nearObjects ["RoadBarrier_F", 30];
        
                _Remove_Item = (Barriere select 0);
                deleteVehicle _Remove_Item;
                sleep 0.1;
                if(count nearestObjects[player,["RoadBarrier_F"],30] < 1) then
                {
                    player removeAction Remove_Action;
                };
            }];
        };
    waitUntil{(!alive player)};
    };
};
 
SetzeBarriere = 
{ // placingBarrier
    if ( count nearestObjects[player,["RoadBarrier_F"],30] < 2 ) then
    {
        Barriere = createVehicle ["RoadBarrier_F",(player modelToWorld [0,5,0]),[],0,"CAN_COLLIDE"];
        Barriere setDir getDir player;
        
        if( count nearestObjects[player,["RoadBarrier_F"],30] > 0 ) then
        {
            [[Barriere],"Entferne_Barrieren",[east,west],true] call BIS_fnc_MP; // jumping to delete Barrier
            player removeAction Remove_Action;
        };
        
    }
    else
    {
        hint "Du kannst nur 2 Barriere im Umkreis von 30m platzieren!"; // you can only place 2 Barriers in range of 30m
    };
};

Create another file name onPlayerRespawn.sqf and put this:

if(side player == west) then
{
	player addAction["Tatort absperren<t color='#6699FF'> /_!_\</t>",{call SetzeBarriere;}]; // addAction to place Barrier - team blufor
};
if (side player == east) then
{
	player addAction["Unfallort absperren<t color='#FFE500'> /_!_\</t>",{call SetzeBarriere;}];// addAction to place Barrier - team opfor
};


Info on those two files: https://community.bistudio.com/wiki/Event_Scripts

You shouldn't need anything else.

John Shock
Scripter, Mission Developer

My scripts: Simple Mortar Script, Redressing Script, Cruise Control Script

My Missions: [COOP-40]Operation Bloody Bayonet

Advertisement


Author Message


Posts: 6
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2016-03-27 20:23        
     
Hi, thanks for your reply.
wouldnt it be better if i execute a script with the part i should put in initLocalPlayer, from initLocalPlayer ?
and is it even possible that the addAction can open a other script just by the name of the function ?


Author Message


Posts: 83
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name: J.Shock

 
#4 Posted at 2016-03-27 20:27        
     
Functions are essentially global variables, variables with the data type "code", so yes when you have "call FUNCTION" it will run the code within that function. So when I put those two functions in initPlayerLocal, all players get each function defined on their client, therefore, they can call those functions at anytime. You shouldn't need the BIS_fnc_MP here since create/deleteVehicle are global effect commands.

John Shock
Scripter, Mission Developer

My scripts: Simple Mortar Script, Redressing Script, Cruise Control Script

My Missions: [COOP-40]Operation Bloody Bayonet

Author Message


Posts: 6
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2016-03-27 20:37        
     
Wow, is there anything where i can read all this ? or do i have to check every command on BI-Wiki ?
btw would this work then ?
//initLocalPlayer.sqf
[] execVM "Barrier.sqf";
//Barrier.sqf
Entferne_Barrieren = 
{
    while {count nearestObjects[player,["RoadBarrier_F"],30] > 0} do
    {
    waitUntil{(alive player)};
        if(alive player) then
        {
            Remove_Action = player addAction["Entferne Absperrung<t color='#66FF00'> /_!_\</t>",{ // addAction to delete the Barrier
                Barriere = position player nearObjects ["RoadBarrier_F", 30];
        
                _Remove_Item = (Barriere select 0);
                deleteVehicle _Remove_Item;
                sleep 0.1;
                if(count nearestObjects[player,["RoadBarrier_F"],30] < 1) then
                {
                    player removeAction Remove_Action;
                };
            }];
        };
    waitUntil{(!alive player)};
    };
};
 
SetzeBarriere = 
{ // placingBarrier
    if ( count nearestObjects[player,["RoadBarrier_F"],30] < 2 ) then
    {
        Barriere = createVehicle ["RoadBarrier_F",(player modelToWorld [0,5,0]),[],0,"CAN_COLLIDE"];
        Barriere setDir getDir player;
        
        if( count nearestObjects[player,["RoadBarrier_F"],30] > 0 ) then
        {
            [[Barriere],"Entferne_Barrieren",[east,west],true] call BIS_fnc_MP; // jumping to delete Barrier
            player removeAction Remove_Action;
        };
        
    }
    else
    {
        hint "Du kannst nur 2 Barriere im Umkreis von 30m platzieren!"; // you can only place 2 Barriers in range of 30m
    };
};
//onPlayerRespawn.sqf
if(side player == west) then
{
	player addAction["Tatort absperren<t color='#6699FF'> /_!_\</t>",{call SetzeBarriere;}]; // addAction to place Barrier - team blufor
};
if (side player == east) then
{
	player addAction["Unfallort absperren<t color='#FFE500'> /_!_\</t>",{call SetzeBarriere;}];// addAction to place Barrier - team opfor
};

Thanks for your help.


Author Message


Posts: 83
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name: J.Shock

 
#6 Posted at 2016-03-27 20:41        
     
Yes, that's the same thing.

Functions:

https://community.bistudio.com/wiki/Function

https://community.bistudio.com/wiki/Functions_Library_(Arma_3)

https://youtu.be/-W1-rg429RM

John Shock
Scripter, Mission Developer

My scripts: Simple Mortar Script, Redressing Script, Cruise Control Script

My Missions: [COOP-40]Operation Bloody Bayonet

Author Message


Posts: 6
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#7 Posted at 2016-03-27 20:47        
     
Thank you very much !


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#8 Posted at 2016-03-27 21:00        
     
To make it "short", addAction works fine in MP. You can place it in init.sqf or initPlayerLocal.sqf depending on what you want to obtain. init.sqf is run for each player connecting + server. So, it needs some adjustments if you don't want to duplicate the addAction.
addAction is not persistent. So you need to re-run it after respawn. That's the reason why usually the code is also placed in onPlayerRespawn.sqf or in a EH "respawn". Some missions start with respawn so you need this double addAction. On the other hand; onPlayerRespawn is always run in... SP! It's weird. You can easily duplicate the addAction.
There are so much to write about addAction.
Keep on mind you can add conditions in it. It's useful for make it appear in the menu (but the addAction is here and CPU has to check it).
You can also check if an addAction still exists (useful in while loop checking for new unit/object to be treated): if (isNil "my_action") then {my_action = spawned_unit addAction [...]}

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 6
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name:

 
#9 Posted at 2016-03-27 21:45        
     
You are confusing me .. so i have to put the code in onPlayerRespawn, but i have to remove the addaction ?


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#10 Posted at 2016-03-27 23:09        
     
We are discussing about addAction applied to player.
Then, you'll need onplayerRespawn.sqf or in EH "respawn" for sure if you want to keep it after respawn, because your player is another "body". In fact, addAction remains in dead corpse and you can have it when approaching it, but your new "body" has lost it.
Removing your addAction is your problem, when you don't need it any more.
Duplication of addAction occurs when the code is run several times, for a reason or another, (or approaching your corpse after respawn).

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS