Jump to content
Sign in to follow this  
unknownx9

Fixing a Popup Script

Recommended Posts

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

// Function file for Armed Assault

// Created by: TODO: Author Name

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

// How to use.

// 1. Place a popup target and name it to pt1

// 2. copy it 8 times and it will auto name the targets

// 3. place this line in a trigger or init nul=[] execVM "popup.sqf"

_inc = 0;

_count = 0;

_targets = [MG22, MG23, MG24, MG25, MG26, MG27, MG28, MG29, MG30, MG31, MG32, MG33, MG34, MG35, MG36, MG37, MG38, MG39, MG40, MG41, MG42];

_many = count _targets;

_SoldierOne = player;

_pass = 16; // number of targets you are required to hit.

{_x animate["terc",1]} forEach _targets;

_rnumber1=0;

_rnumber2=0;

_rnumber3=0;

_soldierOne groupChat "Welcome to the firing range";

sleep 5;

_soldierOne groupChat "Setting up the Range";

sleep 2;

_soldierOne groupChat "The Qualification Course will begin in 2 Seconds";

sleep 2;

_soldierOne groupChat "Begin!";

while {_inc<17} do

{

_rnumber1 = random _many;

_int = _rnumber1%1;

_rnumber1 = _rnumber1-_int;

while {(_rnumber1 == _rnumber2) or (_rnumber1 == _rnumber3) or (_rnumber2 == _rnumber3)} do

{

_rnumber2 = random _many;

_int = _rnumber2%1;

_rnumber2 = _rnumber2-_int;

_rnumber3 = random _many;

_int = _rnumber3%1;

_rnumber3 = _rnumber3-_int;

};

_rtarget1 = _targets select _rnumber1;

_rtarget2 = _targets select _rnumber2;

_rtarget3 = _targets select _rnumber3;

_rtarget1 animate["terc", 0];

_rtarget2 animate["terc", 0];

_rtarget3 animate["terc", 0];

sleep 6;

if (_rtarget1 animationPhase "terc" > 0.1) then

{

_count = _count+1;

};

if (_rtarget2 animationPhase "terc" > 0.1) then

{

_count = _count+1;

};

if (_rtarget3 animationPhase "terc" > 0.1) then

{

_count = _count+1;

};

_soldierOne groupChat format ["Targets :%1 Hit :%2",(_inc+1)*3,_count];

_rtarget1 animate["terc", 1];

_rtarget2 animate["terc", 1];

_rtarget3 animate["terc", 1];

sleep 2;

_inc = _inc + 1;

};

sleep 2;

_soldierOne groupChat "Session Complete";

sleep 1;

_soldierOne commandChat format ["%1",_count];

//if (_count >= _pass ) then {_soldierOne commandChat "Congratulations you have passed";} else {_soldierOne commandChat "Sorry you must do better";};

This is a script I found on Bi forums for pop up targets. I am trying to modify with my limited knowledge in scripting but it is not going well.

First off to tell you what I am trying to make this script do other than what it is does well in it's current state.

I am looking to make the popup targets popup in groups of 4 next to each other, rather than have 4 popups popup in 4 different location within the shooting range. I have already created the editor part of this, but was unsuccessful in modify this script.

I have tried this:

_target1 = [AR1,AR2,AR3,AR4];

_target2 = [AR5,AR6,AR7,AR8];

_target3 = [AR9,AR10,AR11,AR12];

_target4 = [AR13,AR14,AR15,AR16];

_targets = _target1, _target2, _target3, _target4;

Hoping the above code could make any difference but to no avail. This is not what I tried alone, I have tried a lot of things but I lost track and I do not want to flood the whole page with what I have tried to do.

If anyone can assist me in accomplishing my task, that would be greatly appreciated.

unknownx9

Share this post


Link to post
Share on other sites

Whats wrong with this?

_targets = [[AR1,AR2,AR3,AR4],[AR5,AR6,AR7,AR8],[AR9,AR10,AR11,AR12],[AR13,AR14,AR15,AR16]];

Wiki says this:

Arrays of Arrays

You can have an array of arrays (aka a multi-dimensional array)

For example:

dudearray = [["Whatever", 2, 3, 1, 6], ["Whatever2", 2, 8, 3]]

firstelement = dudearray select 0

geteight = (dudearray select 1) select 2

_a1 = [[1,1],[2,2],[3,3]];

Every time I add this to the pop up script above the script does not work. When I comment it out it works.

Share this post


Link to post
Share on other sites

This script was designed to select a few random targets from a large list of targets and pop them up.

So you cant just copy and pastes snip-its of code and expect it to work. It needs to be rewritten to do what you want it to do.

This is not tested and the scoring probably will not work like that( I normally use eventHandlers to score) but this will get you heading in the right direction.

I didn't know how you were going to differentiate between the different sets of targets so I just put a 15 second pause in between each course.

_inc = 0;
_count = 0;
_target1 = [AR1,AR2,AR3,AR4];
_target2 = [AR5,AR6,AR7,AR8];
_target3 = [AR9,AR10,AR11,AR12];
_target4 = [AR13,AR14,AR15,AR16];
_many = (count _targets1) + (count _targets2) + (count _targets3) + (count _targets4);
_SoldierOne = player; 
_pass = 16; // number of targets you are required to hit. 

{_x animate["terc",1]} forEach _targets1;
{_x animate["terc",1]} forEach _targets2;
{_x animate["terc",1]} forEach _targets3;
{_x animate["terc",1]} forEach _targets4;

_soldierOne groupChat "Welcome to the firing range";
sleep 5;
_soldierOne groupChat "Setting up the Range";
sleep 2;
_soldierOne groupChat "The Qualification Course will begin in 2 Seconds";
sleep 2;
_soldierOne groupChat "Begin!";

// First set of targets.

{_x animate["terc",0]} forEach _targets1;

// I dont know if the scoring will work like this, I normaly use eventhandlers to score.
if ({_x animationPhase "terc" > 0.1} forEach _targets1) then

{
_count = _count+1;
};
sleep 15;

//Second set of targets.

_soldierOne groupChat "Next Round Starts Now!";

{_x animate["terc",0]} forEach _targets2;

if ({_x animationPhase "terc" > 0.1} forEach _targets2) then

{
_count = _count+1;
};
sleep 15;

//Third set of targets.

_soldierOne groupChat "Next Round Starts Now!";

{_x animate["terc",0]} forEach _targets3;

if ({_x animationPhase "terc" > 0.1} forEach _targets3) then

{
_count = _count+1;
};
sleep 15;

//Fourth set of targets.

_soldierOne groupChat "Next Round Starts Now!";

{_x animate["terc",0]} forEach _targets4;


if ({_x animationPhase "terc" > 0.1} forEach _targets4) then

{
_count = _count+1;
};

_soldierOne groupChat format ["Targets :%1 Hit :%2",(_inc+1)*3,_count];

sleep 2;
_inc = _inc + 1;
};
sleep 2;
_soldierOne groupChat "Session Complete";
sleep 1;
_soldierOne commandChat format ["%1",_count];
//if (_count >= _pass ) then {_soldierOne commandChat "Congratulations you have passed";} else {_soldierOne commandChat "Sorry you must do better";};

Share this post


Link to post
Share on other sites

Thank you for your reply Riouken.

That line was actually one of the line I modified in addition to other lines. But I was chipping out pieces of the script and trying to figure out which part of the script it did not like. And was confused about it since it says in wiki you can create an array of arrays in the manner I specified but it did not like it.

Either way thank you for your support I will test it out and tell you what I find.

unknownx9

Share this post


Link to post
Share on other sites

This script will work, but not random. Also you are right about the counting in this script, it will not work correctly.

Another thing to point out is that in order for this script to run, you have to call the array with the correct name. From the body of the script the array is being called as "_targets1", but the array declaration is "_target1".

Thanks again.

Share this post


Link to post
Share on other sites

I do have a script that will pop up three at a time, it should be easy enough to change it to four. You will also have to change the script to accept your target names. You will need to place your targets in the correct groups in this case "pt1 pt1_1 pt1_2" "pt1_3 pt1_4 pt1_5" ect.

//////////////////////////////////////////////////////////////////
//                 How to use. 
// 1. Place a popup target and name it to pt1 
// 2. copy it several times and it will auto name the targets
// 3. place this line in a trigger or init  nul=[] execVM "popup3set.sqf" 
// This script will pop up 3 targets at a time.

_inc     = 0;
_count   = 0;
_pass    = 20; // number of targets you  are required to hit. 
_targets = [pt1, pt1_1, pt1_2, pt1_3, pt1_4, pt1_5, pt1_6, pt1_7, pt1_8, pt1_9, pt1_10, pt1_11];
//_targets = [pt1, pt1_1, pt1_2, pt1_3, pt1_4, pt1_5, pt1_6, pt1_7,pt1_8];
_many    =  (count _targets)/3;
nopop=true;
{_x  animate["terc",1]} forEach _targets;

hint "Welcome to the 101st Airborne's 1st Live Fire Rifle Qualification Range";
sleep 5;
hint "Setting up the Range";
sleep 3;
hint "The Qualification Course will begin in 10 Seconds";
sleep 2;
hint "The Qualification Course will begin in 8 Seconds";
sleep 2;
hint "The Qualification Course will begin in 6 Seconds";
sleep 2;
hint "The Qualification Course will begin in 4 Seconds";
sleep 2;
hint "The Qualification Course will begin in 2 Seconds";
sleep 2;
hint "Begin!";



while {_inc < 10} do 
{
_inc = _inc + 1;
_rnumber = floor random _many;
_rnumber = _rnumber *3;
_rtarget1 = _targets select _rnumber+0;
_rtarget2 = _targets select _rnumber+1;
_rtarget3 = _targets select _rnumber+2;
_rtarget1 animate["terc", 0];
_rtarget2 animate["terc", 0];
_rtarget3 animate["terc", 0];


_rtarget1 say ["clunk",0];
sleep 1;
hintsilent format ["Targets :%1 Hit :%2",_inc*3,_count];
sleep 2;
if (_rtarget1 animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
if (_rtarget2 animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
if (_rtarget3 animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
 hint format ["Targets :%1 Hit :%2",_inc*3,_count];
_rtarget1 animate["terc", 1];
_rtarget2 animate["terc", 1];
_rtarget3 animate["terc", 1];


sleep 1;
};

sleep 2;
hint "Session Complete";
sleep 1;

hint format ["%1",_count];
if  (_count >= _pass ) then {Hint "Congratulations you have passed";MAG_tskObj0 settaskState "SUCCEEDED"} else {hint "Sorry you must do better";MAG_tskObj0 settaskState "Failed"}; 

Share this post


Link to post
Share on other sites
I do have a script that will pop up three at a time, it should be easy enough to change it to four. You will also have to change the script to accept your target names. You will need to place your targets in the correct groups in this case "pt1 pt1_1 pt1_2" "pt1_3 pt1_4 pt1_5" ect.

//////////////////////////////////////////////////////////////////
//                 How to use. 
// 1. Place a popup target and name it to pt1 
// 2. copy it several times and it will auto name the targets
// 3. place this line in a trigger or init  nul=[] execVM "popup3set.sqf" 
// This script will pop up 3 targets at a time.

_inc     = 0;
_count   = 0;
_pass    = 20; // number of targets you  are required to hit. 
_targets = [pt1, pt1_1, pt1_2, pt1_3, pt1_4, pt1_5, pt1_6, pt1_7, pt1_8, pt1_9, pt1_10, pt1_11];
//_targets = [pt1, pt1_1, pt1_2, pt1_3, pt1_4, pt1_5, pt1_6, pt1_7,pt1_8];
_many    =  (count _targets)/3;
nopop=true;
{_x  animate["terc",1]} forEach _targets;

hint "Welcome to the 101st Airborne's 1st Live Fire Rifle Qualification Range";
sleep 5;
hint "Setting up the Range";
sleep 3;
hint "The Qualification Course will begin in 10 Seconds";
sleep 2;
hint "The Qualification Course will begin in 8 Seconds";
sleep 2;
hint "The Qualification Course will begin in 6 Seconds";
sleep 2;
hint "The Qualification Course will begin in 4 Seconds";
sleep 2;
hint "The Qualification Course will begin in 2 Seconds";
sleep 2;
hint "Begin!";



while {_inc < 10} do 
{
_inc = _inc + 1;
_rnumber = floor random _many;
_rnumber = _rnumber *3;
_rtarget1 = _targets select _rnumber+0;
_rtarget2 = _targets select _rnumber+1;
_rtarget3 = _targets select _rnumber+2;
_rtarget1 animate["terc", 0];
_rtarget2 animate["terc", 0];
_rtarget3 animate["terc", 0];


_rtarget1 say ["clunk",0];
sleep 1;
hintsilent format ["Targets :%1 Hit :%2",_inc*3,_count];
sleep 2;
if (_rtarget1 animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
if (_rtarget2 animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
if (_rtarget3 animationPhase "terc" > 0.1) then
{
	_count = _count+1;
	    };
 hint format ["Targets :%1 Hit :%2",_inc*3,_count];
_rtarget1 animate["terc", 1];
_rtarget2 animate["terc", 1];
_rtarget3 animate["terc", 1];


sleep 1;
};

sleep 2;
hint "Session Complete";
sleep 1;

hint format ["%1",_count];
if  (_count >= _pass ) then {Hint "Congratulations you have passed";MAG_tskObj0 settaskState "SUCCEEDED"} else {hint "Sorry you must do better";MAG_tskObj0 settaskState "Failed"}; 

"pt1 pt1_1 pt1_2" "pt1_3 pt1_4 pt1_5"

Script will not start if I group them like this.

The script currently pops up 3 targets in different area's, and I am guessing because the pop up targets are not grouped together.

Can you please elaborate more thanks.

unknownx9

Share this post


Link to post
Share on other sites

The script should work as is but in the game you will need to place your targets in groups of three. This was just to show how the numbers that make the groups are set "pt1 pt1_1 pt1_2" "pt1_3 pt1_4 pt1_5" ect.

Share this post


Link to post
Share on other sites

Thank you very much for your help F2K Sel.

unkownx9

Share this post


Link to post
Share on other sites

Since we are on the topic of pop up scripts, there is this small script I put together but it is not working the way I want it to.

private["_target","_instructor"];

_target = AR49;

_instructor = player;

endNumber = 0;

cnt = 0;

_instructor commandChat "Welcome to the range.";

sleep 2;

_instructor commandChat "Setting up course.";

sleep 2;

_instructor commandChat "Ready";

_target animate["terc", 0];

while{endNumber == 0}do

{

_target addEventHandler ["hit",{cnt = cnt + 1;}];

waitUntil {_target animationPhase "terc" != 0};

_target animate["terc", 0];

};

if(endNumber != 0)exitWith{};

It works at keeping the pop up target from going down, which is what I want it to do. But the counting system is really messed up. I hit a couple of times using the Machine gun but my "cnt" will equal 11579 :( .

This is the other Script that ends the previous one:

private["_target","_instructor"];

endNumber = 1;

_target = AR49;

_instructor = player;

_target animate["terc", 0];

_target removeEventHandler ["hit", 0];

_instructor commandChat format ["Targets hit: %1", cnt];

cnt = 0;

_instructor commandChat "Training complete";

Any input is appreciated.

unknownx9

Edited by unknownx9

Share this post


Link to post
Share on other sites

At a guess it may be counting the hit multiple times, try putting in a delay and see if the number of hits changes.

Share this post


Link to post
Share on other sites
At a guess it may be counting the hit multiple times, try putting in a delay and see if the number of hits changes.

Not sure I am following you there. Do you mean like put a "sleep" timer ? If so, wouldn't that affect the counting of the number of bullets as well?

Share this post


Link to post
Share on other sites

Last time I checked sleep did have an effect which it shouldn't have done. I've looked at it again today and it's so obvious this time what's wrong.

your placing multiple eventhandlers on the target so you will get multiple hits.

move _target addEventHandler ["hit",{cnt = cnt + 1;}]; to before the while{endNumber == 0}do line and not within it as it is now.

Share this post


Link to post
Share on other sites

I posted this at OFPEC forums but no reply yet.

The passing of the variable "endNumber" from one script to another is working, but unfortunately the "cnt" variable is not when I am testing it out in MP. When I preview it in the editor I get the correct count number of how many targets I have hit, but when I tried the mission in MP it always returns a count of 0 :confused:, any ideas?

I have tried placing the count in the same script, but now it is not showing up the count at all.

I have tried like this after switching the variable to local so it does not have to be passed from one script to another, but that did not work either:

while{endNumber == 0}do

{

waitUntil {_target animationPhase "terc" != 0};

_target animate["terc", 0];

};

_instructor commandChat format ["Targets hit: %1", _cnt]

_instructor commandChat "Training complete";

if(endNumber != 0)exitWith{};

And like this:

while{endNumber == 0}do

{

waitUntil {_target animationPhase "terc" != 0};

_target animate["terc", 0];

};

_instructor commandChat "Training complete";

if(endNumber != 0)exitWith{_instructor commandChat format ["Targets hit: %1", _cnt]};

I have also tried adding MPEventhandler rather than the EventHandler alone, same thing nothing.

I was thinking it might be because of the two private variables "_instructor" in both scripts overwriting each other, but then how come it passes the variable from one script to another in the editor, so I do not think that is the case.

So I am stuck now and do not know what to do, any help would be appreciated.

Thanks.

Share this post


Link to post
Share on other sites

I haven't done any MP script myself so it's really beyond my understanding.

It confuses me trying to work out if the script needs to run on just the server or the client or on all there.

Have you tried publicVariable "cnt"; that should broadcast it to all pc's

Share this post


Link to post
Share on other sites
I haven't done any MP script myself so it's really beyond my understanding.

It confuses me trying to work out if the script needs to run on just the server or the client or on all there.

Really hope that a method is made to help simplify this process for us in Arma 3.

Have you tried publicVariable "cnt"; that should broadcast it to all pc's

Tried that again today works when I start an MP on my PC. So I uploaded to dedicated to test and it returned 0 for the "cnt" variable.

I also noticed that when added the publicVariable to the script the PC went wild a bit in processing, not sure if that because of updating the variable on all clients or something else.

Anyways, if anyone has any ideas on how to fix the passing of "cnt" variable from script to script on a dedicated please let me know.

Thanks.

Share this post


Link to post
Share on other sites

Have you seen this one it seems to be doing most of what your after

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

you can unpack it and take a look at the code.

I took a quick look and what it seems to do is use the eventhandler to execute another script for counting rather than setting a variable within the handler.

yours may look something like this.

_target addEventHandler ["hit", {[_this select 1] execvm "count.sqf";}]; 

Share this post


Link to post
Share on other sites

Is it possible to scripting a popup so that it goes down only when it was hit twice? (Double Tap)

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
Sign in to follow this  

×