Jump to content
Sign in to follow this  
nominesine

Syntax Check

Recommended Posts

I'm proofreading a script but have no testing oportunities. Can somebody check the syntax in this line for me:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

{_x addEventHandler ["fired",{nomin_count=nomin_count+1; publicVariable “nomin_countâ€}]} forEach units teamOne

It's supposed to add an eventhandler to every unit in a GROUP designated as TEAMONE and add the value +1 to a counter named nomin_count whenever a team member fires his weapon, thus counting how many rounds TEAMONE has fired during the mission.

Life ain't easy when Ofpec is off line confused_o.gif

Share this post


Link to post
Share on other sites

Well, theoretically yes, but this will cause a lot of traffic because of all the publicvariables in a fire fight. I would try another approach:

Store the fired rounds locally on every client, and when you want to know the over-all statistics, you receive and add the values.

Could work like that:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addEventHandler ["fired",{firedCount=firedCount+1}]} forEach units teamOne

And a script (requires the usual "Server" logic):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_group = _this

?! local Server : goto "Client"

; total count

_total=0

; Id to be received

RECEIVER_ID=0

; Set count to -1

RECEIVER_CNT=-1

#receive

publicVariable "RECEIVER_ID"

_tm=_time

@((RECEIVER_CNT!=-1) or (_time-_tm>60))

? (RECEIVER_CNT==-1) : Server globalChat format ["Client %1 not responding. Script execution terminated.",RECEIVER_ID]; exit

_total=_total+RECEIVER_CNT

RECEIVER_ID=RECEIVER_ID+1

? (RECEIVER_ID<count(_group)) : goto "receive"

Server globalChat format ["%1 Shots fired",_total]

exit

#Client

?! (player in _group) : exit

_id=0

while{(units _group select _i)!=player} do {_id=_id+1}

@(RECEIVER_ID==_id)

RECEIVER_CNT=firedCount

publicVariable "RECEIVER_CNT"

exit

to be called on both server and client. _total will contain the total number.

Share this post


Link to post
Share on other sites

Thank's for the help. I apreciate the effort you put into the reply.

* pastes and copies *

Share this post


Link to post
Share on other sites
Thank's for the help. I apreciate the effort you put into the reply.

No problem. Excuse the little explanation of the code, I didn't have a lot of time when I wrote it.

The script has, as to be seen, two parts: One that is executed on the server and the other one that runs on the clients.

The script should be called globally with the desired group as its only parameter. I just notice that the script, as it is now, doesn't count the fired rounds of the AI soldiers in the group. If you want to allow that, you have to do some changes.

The server part of the script initializes the two variables RECEIVER_ID and RECEIVER_CNT, of which the first stores the array index (in the group array) of the unit, that should send its number. It increments the id until the count of every client is received.

The client parts check for their array index aswell and wait, until RECEIVER_ID equals their index. When it does so, they publish their fired-rounds-number via the second superglobal variable.

Here is the script that should work with AI aswell (note the bold parts)

Quote[/b] ]_group = _this

?! local Server : goto "Client"

; total count - AI soldiers may have increased the firedCount on the server

_total=firedCount

; Id to be received

RECEIVER_ID=0

; Set count to -1

RECEIVER_CNT=-1

#receive

; AI?

? local (units _group select RECEIVER_ID) : RECEIVER_ID=RECEIVER_ID+1; goto "receive"

publicVariable "RECEIVER_ID"

_tm=_time

@((RECEIVER_CNT!=-1) or (_time-_tm>60))

? (RECEIVER_CNT==-1) : Server globalChat format ["Client %1 not responding. Script execution terminated.",RECEIVER_ID]; exit

_total=_total+RECEIVER_CNT

RECEIVER_ID=RECEIVER_ID+1

? (RECEIVER_ID<count(_group)) : goto "receive"

Server globalChat format ["%1 Shots fired",_total]

exit

#Client

?! (player in _group) : exit

_id=0

while{(units _group select _i)!=player} do {_id=_id+1}

@(RECEIVER_ID==_id)

RECEIVER_CNT=firedCount

publicVariable "RECEIVER_CNT"

exit

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  

×