Jump to content
Sign in to follow this  
lozz08

Interactive text

Recommended Posts

Hello, I am just wondering if anybody could help with a problem I have.

I've made a zombie survival mission, where you survive for as long as you can.

I am just wondering how I could make the total time from the start of the mission until all players are dead come up in text when we all die, in the outro.

Thanks for any help.

Share this post


Link to post
Share on other sites

Hi,

i created this for you. :)

init.sqf

[font="Fixedsys"]nul = execVM "count.sqf";[/font]

count.sqf

[font="Fixedsys"][color="RoyalBlue"]// --- server only[/color]
if (!isServer) exitWith {};

[color="RoyalBlue"]// --- variables[/color]
TimeSurvived = 0;
MissionRunning = true;

[color="RoyalBlue"]// --- wait until all players are dead and broadcast the time[/color]
[] spawn {
waitUntil {!(alive [color="DarkOrange"]player1[/color]) && !(alive [color="DarkOrange"]player2[/color])};
MissionRunning = false;
sleep 2;
TimeSurvivedDisplay = round(TimeSurvived / 60); publicVariable "TimeSurvivedDisplay";
};

[color="RoyalBlue"]// --- count the time while mission running[/color]
while {MissionRunning} do {
TimeSurvived = TimeSurvived + 1;
sleep 1;
};[/font]

For displaying the time you can use the TimeSurvivedDisplay variable. For example:

[font="Fixedsys"]titleText [format["You survived %1 minutes!", TimeSurvivedDisplay], "PLAIN", 1];[/font]

I converted it, so it displays the minutes. Seconds are also possible. Feel free to ask me for changes. It works in multiplayer, singleplayer and hosted.

Share this post


Link to post
Share on other sites

Thanks so much for that. I appreciate it.

PS. One Question, what is the use of the [] spawn { bit? I see this [] thing used a lot but I've no idea what it is.

Edited by lozz08

Share this post


Link to post
Share on other sites

[] spawn {} creates a separate thread of execution. It's like making another script inside a script that runs independently. That way all of the commands inside the spawn will execute on their own, and the script can continue on to the next commands without waiting.

Share this post


Link to post
Share on other sites

Ah, I see, otherwise it would be adding a second to the counter every 3 seconds. Well, I've learned a fair bit from this.

Edit: hm, upon trying, it seems to be saying "you survived any minutes" where it should say a number instead of any...

Edited by lozz08

Share this post


Link to post
Share on other sites

Just get sure that you wait some seconds ~5 before using the variable.

sleep 5;

titleText [format["You survived %1 minutes!", TimeSurvivedDisplay], "PLAIN", 1];

For example.

And you have to change this line of course:

waitUntil {!(alive player1) && !(alive player2)};

player1 and palyer2 are the unit names, from the editor.

To add more player just do it lke that:

waitUntil {!(alive player1) && !(alive player2) && !(alive player3) && !(alive player4)};

Share this post


Link to post
Share on other sites
I see this [] thing used a lot but I've no idea what it is.

In the above examples, it's used to pass parameters into the script.

ie:

[car] execVM "myScript.sqf"

and inside the script you may see:

_car = _this select 0;

Works in plenty of places, including spawn - to try and describe it as simply as possible - it's used to send references to objects or extra details the script otherwise couldn't access without your help; The script doesn't know which car you refer to unless you tell it.

The [] symbols in general refer to an array.

Share this post


Link to post
Share on other sites

Think you guys are maybe making this way too complicated.

According to the BIKI:

allUnits returns all units except those dead or waiting for respawn.

Try this solution:

Create a trigger:

Condition: {isPlayer _x} count allUnits < 1
On Act: titleText [format["You survived %1 minutes!", round (time/60)], "PLAIN", 1];

time returns the time since mission start.

You can add a couple of seconds to the timeout values (min, mid max) to create a delay before the message, and perhaps so the condition doesn't return true on a slow initialization.

Have not tested it!!!

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

My experience was that the time command is not accurate. If you get lags maybe, im not sure why. Im not using it anymore...

But you're right, i always make things too complicated... :D

Share this post


Link to post
Share on other sites

Didn't know that just checked it out on the BIKI, that servers may lag behind if the are overloaded. :o However, time is synchronized on join and then the client takes over, so as long as the client functions reasonable it should be accurate.

However, that would make sleep even more inaccurate than it already is. Sleep sleeps the minimum amount of time you tell it to and it is pretty inaccurate and unreliable so TimeSurvived will in a perfect world increase once per second. It is more likely that it will lag even more behind, especially if the server is overloaded. And your solution is run on the server; what makes it more reliable than the built in time which probably functions the exact same way?

But down to practicality, does it matter if it says to dude A that they survived 34 minutes and to dude B 33 minutes? :p

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

I used waitUntil time > x in a mission and it never fired, so that's why im not using it anymore.

Well i changed the script a bit (forgot the objNull if player2 not exists)

Here a demo mission:

http://server.arma2.co/Count.Takistan.rar

Just change this:

waitUntil {{alive _x} count units group player < 2};

to this:

waitUntil {{alive _x} count units group player < 1};

2 is for demo only, so that you see the titleText after killing the 2 dudes. :)

Share this post


Link to post
Share on other sites

Ok, both spx 2 and muzzleflash's methods work. I think seeing as I am designing this to be played by up to four people and hopefully have it hosted on some servers, I should use spx 2 method because it only allows the server to do the counting.

By the way this is for a remake of call of duty's Nazi Zombies, I always wished I could reproduce that without the annoying way the zombies get stronger over time with COD.

Hopefully if the mission is good enough I can get some kind of a leaderboard going and some competition among people.

Anyhoo, is there a way I can make the text red with maybe a different font?

Share this post


Link to post
Share on other sites

You should learn to use parseText/StructuredText, however, I am not sure they will work with titleText. This is the way you make colored text or larger font sizes for hint for example. Reading the comments at the bottom will show you what you can do. As I said i'm not sure they work with titleText: http://community.bistudio.com/wiki/parseText

Share this post


Link to post
Share on other sites

Just realized another mistake:

Please change

waitUntil {{alive _x} count units group player < 1};

to:

waitUntil {{alive _x} count units YourGroupName < 1};

And put this into the leaders init:

YourGroupName = group this;

Otherwise it won't work in dedicated environment. Because player does not exist on a dedi server... Sorry.

Btw i like zombie missions. Will give it a go on our server when you're done.

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  

×