Jump to content
Sign in to follow this  
greenshadow

Creating a Simple Counter

Recommended Posts

Hi all.

first of all, I have just started making my first mission and I am enjoying the experience due to the amazing levels of support and content available here! Hopefully one day I will know enough about Editing & Scripting ARMA titles to continue this cycle.. - but I digress! (I thought as my first post, it ought to contain something a little sentimental :P)

The main goal of the mission I have been working on, is to destroy 3 OPFOR buildings, (named barracks, UAV, SupplyPoint) and I thought It would be useful to provide a hint that updates the player as to how many of the buildings he has destroyed. Ideally, I would like it to say "You have destroyed x/3 buildings" where x is the amount of buildings destroyed.

Initially (and this is where my lack of experience in SQF shows) my idea was to declare a variable in the init file called "DestructionCount" so my init.sqf now looked like this:

execVM "briefing.sqf";
DestructionCount=0

and then in game make a new trigger with the following

Condition:

!alive barracks

OnAct:

DestructionCount = DestructionCount + 1;  hint format["%1",DestructionCount]; 

this did not work, as the output displayed as "any" where I expected it would be "1" (and even then I am not sure about how I would work actual text into this hint)

so I started researching it, and from what I can tell I need to use a Function. But because I am not very good at coding in general, I struggle to get my head around how I would do this. so my hope was, that by posting my problem, someone who knew what they were talking about, would be able to explain the best way of getting this to work, in as simple a way that is possible.

Thanks in advance!

Share this post


Link to post
Share on other sites

you did it the right way (one of many) but you had a missing ; in your init.sqf

DestructionCount=0;

also if it still dont work, try this instead of !alive barracks

(getdammage barracks) >= 1

PS: welcome to the game, its a rabitthole ;)

Share this post


Link to post
Share on other sites

even then I am not sure about how I would work actual text into this hint

%1 is a placeholder within the text:

hint format["%1 Target(s) destroyed! GJ!",DestructionCount];

Share this post


Link to post
Share on other sites

Bear in mind that there are two Ms in damage not because demonized made a typo, but because the game was written by Czechs.

Share this post


Link to post
Share on other sites

setDamage was added, but I guess getDamage wasn't. "damage" does the same though, doesn't it? Too sleepy to check. heh

Share this post


Link to post
Share on other sites

yes damage does the same function.

a difference on damage from getDammage is that damage is marked as a global command, getdammage has no locality marking, so maybe stick with damage if no issues arise.

Share this post


Link to post
Share on other sites

A big thanks to Demonized and ])rStrangelove for the help. the system is working really well now. I used

(getdammage Barracks) >= 1

which seemed to do the trick.

However just for the sake of learning, Demonized, you said there were many ways of doing this. Is there a quicker/cleaner/more efficient way to accomplish this task that you would usually prefer to use?

cheers.

Share this post


Link to post
Share on other sites

many different ways of handling tasks, what you did is probably the most common way, and imo the most easiest way to keep track of anything.

assigning a variable and add to it after a certain goal is achieved.

some examples:

1:

but you can do this as well, using count command, eliminating the need for triggers or the global variable DestructionCount.

_targetBuildings = [building1,building2,building3];
hint format["You have destroyed %1 target buildings",({(getDammage _x) >= 1} count _targetBuildings)];

but its a matter of practicality, not functionality.

it all just depends on what you need for your specific mission.

2:

you can also use this as a trigger condition for example an end trigger:

({(getDammage _x) >= 1} count [building1,building2,building3]) == 3

on act:

hint "you have destroyed all 3 buildings";

3:

you can also create the global variable

DestructionCount = 0;

then have a repeated trigger with condition:

({(getDammage _x) >= 1} count [building1,building2,building3]) != DestructionCount

on act:

DestructionCount = ({(getDammage _x) >= 1} count _targetBuildings);
hint format["You have destroyed %1 target buildings",DestructionCount];

now trigger will display a hint with how many buildings destroyed whenever the count changes from the global variable, and update the variable so it will work for next building to be destroyed.

4:

performance wise, none of the above is having any "viewable" impact on lag.

i tend to use scripts and waitUntils in while loops for these tasks instead of triggers, working same way but eliminates need for trigger placement.

(a trigger is basically a waitUntil command btw.)

_cnt = 0;
_targetBuildings = [building1,building2,building3];
while {_cnt != 3} do {
// here we use a sleep in the waitUntil, meaning it will only check every 5 seconds, saving performance.
waitUntil { sleep 5; ({(getDammage _x) >= 1} count _targetBuildings) != _cnt };
_cnt = ({(getDammage _x) >= 1} count _targetBuildings);
hint format["You have destroyed %1 target buildings",_cnt];
};
// here it exits automatically once _cnt is 3.

anywho... it all comes down to personal preference for the individual mission.

hope this gave some insight or ideas.

Regards Demonized.

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  

×