Jump to content
Sign in to follow this  
tophe

Running local script and hint global

Recommended Posts

In my mission I use a death count,

Everytime a player is killed a variable is increased by 1.

A trigger is set to:

Cond: not alive player

Activ: [] exec "deathcount.sqs"

So that it will locally run the script on the killed players game.

In the deathcount script it says:

dc = dc + 1

publicVariable "dc"

So far so good. The variable is increased by one and broadcasted to all computers (right? If I use the publicVariable in a local script it will broadcast to all somputers on the network?)

But after this I want a hint to appear on all computers stating the present count. If i put the hint in the script it will only appear on the players computer, since it will be local. Any suggestions to an easy sollution to this?

Share this post


Link to post
Share on other sites

If it's just for debugging, you could use something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[WEST, "HQ"] sideChat Format[ "Deathcount=%1", dc ];

--OR--

player globalChat Format[ "Deathcount=%1", dc ];

Share this post


Link to post
Share on other sites

That's an idea.

But I really want the result to show up in the hint-box.

Somehow I need the other players to be notified that the DC has been increased so that all computers will use the hint command.

Either a trigger that goes off on all computers or the possibility to use the hint command globally in a local script.

Another sollution could have been

Cond: not alive unitname

Activ: [] exec "deathcount.sqs"

That would trigger the deathcount-script on all computer since all will know that the unit is dead. But that would also make every computer do DC + DC + 1, thus leaving me with 6 deathcounts per kill.

Maybe I could just do a trigger that goes

Countdown: 2

Cond: not alive unit or not alive unit2 or not alive unit3....

Activ: hint format ["Number of kills:%1",dc"]

But I wonder what will happen if one unit is not even in the game (AI disabled). Will it be recognized as dead or will it just be ignored? The countdown should let the deathcount.sqs finish globalVariable "dc" before hinting the current death count.

What do you think?

Will the nonpresent units be a problem?

Share this post


Link to post
Share on other sites

Not sure, but maybe you could investigate using addEventHandler with EventHandler: Killed with something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">EHkilled = player addEventHandler ["killed", {_this exec "playerKilled.sqs"}]

Share this post


Link to post
Share on other sites

Beware of people dying at the same time (i.e. from the same hand grenade). They will both run the script at the same time on their local PCs and perform the same calculation and publicvariable. What you end up with is only 1 death showing up.

Share this post


Link to post
Share on other sites

I will look into the addeventhandler.

Strango. I've thought of that, but I am not sure that will happen. Just a few milliseconds of unsync should make one of them public the variable before the other one increases it.

But I am not sure of course.

But will a nonexisting unit return alive = true or will it be false?

*** EDIT ***

Just read about addEventhandler on the biki.

It said MP notes: "Killed" and "Hit" eventhandlers are executed where given unit is local.

So addEventhandker should in this case pretty do the same thing as the trigger. What I need is to tigger a script locally and then hint globally.

Share this post


Link to post
Share on other sites

INIT.SQF

attach a killed event handler to the player, best done in the init.sqf/sqs

in addition define 2 variables

tx_dc = 0;

tx_update = false;

have the killed event script increment your deathcount (tx_dc) by 1 and then public variable it

In addition, also have it re-define your update boolean as true

eg

tx_update = true;

and publicvariable it

{publicvariable _x}foreach [tx_dc,tx_update];

MISSION EDITOR

create a trigger

activation: nobody

condition:tx_update

On activation: [] execvm "tx_update.sqf"

size 0,0

tx_update.sqf

tx_update = false;

hint format ["Deathcount = %1",tx_dc];

Basically you have a trigger which will call your update.sqf on all clients once the dead players event handler script publicvariables tx_update

triggers run at a loop speed of 0.5 seconds, so if 2 or more units are killed within a half second, the update.sqf hint report may not be pinpoint accurate at that point, however the tx_dc increment should be, because its working off a killed event, therefore the next time the trigger is activated, it should have rectified any inconsistencies caused by say a satchel blast etc

The script called by the trigger then resets the trigger by redefining the boolean tx_update as false

Your killed event script should also have code that

a) removes the killed eventhandler on death

b) waitrs for the player to be alive again

c) re-attaches the killed event back to the player

<span style='color:red'>NB>> Notice the use of the tx_ tag</span>

As the arma community grows, you will find that addons, other's scripts and content from your missions may be used to create new missions. Because of this and to avoid conflicts using global variables, it is sound practice to "tag" your public variables, my personal tag is tx_

with the implementation of the bis sub folder (execVM) search, it would also be a good idea to tag your scripts as well

Share this post


Link to post
Share on other sites
<span style='color:red'>NB>> Notice the use of the tx_ tag</span>

As the arma community grows, you will find that addons, other's scripts and content from your missions may be used to create new missions. Because of this and to avoid conflicts using global variables, it is sound practice to "tag" your public variables, my personal tag is tx_

OFPEC TAGs are a good idea. Without a register, how are you to know someone else is not using the same tag?

username terox is already on the register twice!

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  

×