Advertisement

Author Topic: PUBLICVARIABLE IN SERVER SCRIPTS (v196)  (Read 805 times)

0 Members and 1 Guest are viewing this topic.

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« on: 22 Jun 2004, 10:24:04 »
I'm having difficulties with the publicVariable working in a server script.

Seems like the client pc don't receive the content of a variable published by the server.

REVIVIAL PACKS SYSTEM
To stop people in my MP missions running lone Rambo tactics and dying alot, I'm using what I call 'Revival Packs' system which counts down each time a player dies. The total Rev'packs available varies from mission to mission. Lets say we start with 10. A global variable holds this number. (I'll refer to it as 'vNumRevPacks'.) PS! The 10 represent available deaths to the WHOLE squad, not for each player.

SERVER FOR REVPACK HANDLING
I'm running a serverscript handling these rev'packs, which is triggered by another global variable (Lets call it 'vRevPackFlag'). Initially the vRevPackFlag is 0 (zero), but if a player dies, this is set to -1, which again activates the server. vNumRevPacks is deducted by one - and if the total number of vNumRevPacks is equal to or greater than zero, the game continues. (A END trigger is waiting for vNumRevPacks to be -1).

TRIGGER FOR DETECTING DEATHS
I am using triggers to detect if a player dies. (cond. !(alive player)) - if he/she dies - the vRevPackFlag is set to '-1' by the trigger - which activates the server script. It also broadcasts the name of the player who died using vNameOfDeadPlayer = name player; publicVariable "vNameOfDeadPlayer". PS! The trigger is a "continious" trigger.

TRIGGER FOR BROADCASTING MESSAGES
When the server is finished subtracting 1 from the vNumRevPacks, it makes a string message - ie. vMessage = format["%1 died, you now have %2 rev'packs left.", vNameOfDeadPlayer, vNumRevPacks] - and setting a global variable 'vBroadcastMsg' to true. This global variable activates the broadcast trigger which hopefully would broadcast the message to all players ie. "ZNorQ died, you know have 4 rev'packs left.". The trigger also sets the vBroadcastMsg to false - but doesn't publicVariable it. PS! The trigger is a "continious" trigger.

AND THE PROBLEM?
Well, client's receive a "scalar bool" message instead of the "ZNorQ died..." message.. I KNOW I'm using publicVariables on all variables created by the serverscript (atleast the once that is supposed to be known to all other clients - ie. the "ZNorQ died..." message..

I'm going to reinstall flashpoint and patch it with v1.91 to see if that helps.. I've had some strange things happening to my flashpoint since v1.96, don't know if anybody else have had that?

Sorry I couldn't supply you with code, because I'm at work earning my well deserved money :D

ZNorQ

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« Reply #1 on: 22 Jun 2004, 10:42:01 »
Broadcast variable value to all computers. Only type Number is supported in 1.33 and before. Following types are supported since 1.34: Number, Boolean, Object, Group.
You might not be able to send a string with publicvariable. Maybe you need to find a work-a-round.
Not all is lost.

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« Reply #2 on: 22 Jun 2004, 11:07:46 »
Ouch, that sucks! You might be right there...

Well, the trigger could contain a standard text - or it could execute a script that contains a set of standard texts.

What if I use 'vDeadPlayer = player' in the death trigger - and publicVariable that to the broadcast trigger. The Broadcast trigger could then use the following statement; hint format["%1 died, you now have %2 kits left.", name vDeadPlayer, vNumRevPacks]

Think that'll work?

(I'm not at home, so I can't test it for myself.. :-\)

ZNorQ

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« Reply #3 on: 22 Jun 2004, 18:01:25 »
Hope the following helps
Points to note:

1) An addeventhandler "killed" to a player is far more efficient than a number of triggers waiting for condition Alive for each unit on the map

With the system below, all you need is an "ENDMISSION" trigger waiting for condition:tx_stopmission, some entries into the init.sqs and a looping script




INIT.SQS
Quote
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
;;following is number of respawns allowed for the team
tx_Killcount = 10
tx_Player  = objnull
tx_Stopmission = false
[] exec "Monitor.sqs"



Playerkilled.sqs
Quote
player removeAllEventHandlers "Killed"
tx_player = player
tx_Killcount = tx_Killcount - 1
{PublicVariable _x;}foreach["tx_killcount","tx_Player"]
?(tx_killcount < 0): goto "STOPMISSION"
@ alive player
player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
exit

#STOPMISSION
;;do whatever you need to end the mission
;;eg pv a boolean that stops the mission when the number of respawns is more than the respawn limit
;; in this example we use tx_stopmission and have a trigger waiting on the condition to become true
tx_stopmission = true; publicvariable "tx_Stopmission"
exit




Now every machine then needs a script running on it in a constant loop

lets call it the "Monitor.sqs"

MONITOR.sqs
Quote
#START
@ (not isnull tx_Player)
#MESSAGE
_RespawnsLeft = tx_Killcount
?(_RespawnsLeft < 0): _respawnsleft = 0
titletext[format["%1\nhas been killed\n\nRespawns available = %2", name tx_player,_RespawnsLeft],"PLAIN"]
tx_Player  = objnull
goto "START"



havent tested whether you can pull the name from the tx_Player variable

however, no biggy as the global chat always shows the name of the killed player anyway, so why do you need to re publicise it

the rest of the system will work
« Last Edit: 22 Jun 2004, 18:02:05 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« Reply #4 on: 23 Jun 2004, 10:19:45 »
Thx people, good feedback from you.

The answer was really that publicVariable doesn't work with strings, in which case I had to rethink how to make it work. Good tips from you Terox - thx man.

But I'm abit uncertain why it is more feasible to use the addEventHandler instead of a trigger. I'm not very experienced with addEventHandlers, and got very little time to experiment with that, and the trigger seems to work fine. I'll have a closer look into addEventHandler when I got more time.

Again, thx folks!
ZNorQ
« Last Edit: 23 Jun 2004, 14:27:44 by ZNorQ »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« Reply #5 on: 23 Jun 2004, 16:40:12 »
eventhandlers simply cause less cpu stress than a trigger.


also in the example i gave above, each client only has 1 event handler to monitor

whereas when you have say 15 players using your trigger method then each client has 15 triggers running on his machine, only 1 of which is of any use to him

triggers loop at 0.5 seconds checking for the condition

i suppose you could simplify your trigger and instead of say 15 waiting on condition: alive unitname

you could replace them by having just 1 trigger condition: alive Player

Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline ZNorQ

  • Members
  • *
  • ehr... uhm... duh...
Re:PUBLICVARIABLE IN SERVER SCRIPTS (v196)
« Reply #6 on: 24 Jun 2004, 15:42:03 »
Sounds logical, Terox. Well then, I'll just have to get in touch with event handlers I guess. I always knew about them, but I never actually bathered looking deeper into the wonderful world of addEventHandler.

Thx man.

ZNorQ