OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: pazuzu on 05 Nov 2005, 07:56:32
-
I'm using a trigger to repair a dammaged bridge in my mission and I have it timedout for 30min. I've read that using timeout in MP doesn't work in that I cant make it an average time so it ends up being random.
I was wondering if there is another way to make the trigger time random that works in MP?
Thanks.
-
I have little experience of MP but what about trying a script:
~ (30 + random 5)*60
or some such?
-
What does this do?
-
~ = wait for number of seconds
(30 + random 5)*60 = create a random number between 30 to 35 and multiplicate it with 60. Endresult is between 1800 to 2100.
-
Which is a random number between 30 and 35 minutes
-
I have little experience of MP but what about trying a script:
~ (30 + random 5)*60
or some such?
means
~ means "wait" or "pause this script from continuing for
(30 + random 5) creates a value somewhere between 30 and 35
*60 multiplies that value by 60
so what it basically states is
wait (1800 to 2100 seconds)
wait (30 to 35 minutes)
before continuing on with the script
any value used with the wait function is seen in seconds
If you are new to mp scripting and mission making, there are some important facts that you need to know.
Please excuse me if some of the following is obvious to you
1) an MP sessions is made up of
..... a) A server
..... b) A number of clients (Players machines)
Objects such as units, vehicles are often local to only 1 machine at a time.
By local, i mean controlled by that one machine.
Example
AI groups with units that are only AI are controlled by the server
Some commands only work locally, eg, for them to work they must be run on the machine that is local to that object/vehicle/unit
Example of local command "setdir"
Some commands are global, meaning no matter what machine that code is run on, the command will work on it
Example of global command "setpos"
and if every machine runs that code, the unit would receive multiple setpos commands (not good)
To decide what script is run where, we have the "local" command available to us
?(Local server):
?!(Local server):
?(Local Player):
?!(Local Player):
?(local objectname):
"Local server" is often used by most scripters, there is no such thing as a "server" and is no command to call it, however what it actually refers to is an "object", namely a "Gamelogic" which the mission maker has named "Server"
and the reason for this, is that a gamelogic, is always ONLY LOCAL TO THE SERVER
and therefore
?(local gamelogicname): will only be run on a server
Now getting down to your bridge damage control system
INIT.sqs is run on all machines at the start
To repair the bridge, we will need to use the "setdammage" command
Setdammage is a global command and therefore can be run from any machine to repair anything anywhere, (within reason)
We dont particularly want the setdammage command to be run on all machines, as this would cause unescessary network traffic, so what we do, is run a script, from the server only to repair the bridge sections.
We do this by launching the script from the INIT.sqs
But first we need to create a gamelogic in the mission editor and name it "server"
INIT.sqs
?(local server): [] exec "Bridgerepair.sqs"
BridgeRepair.sqs
_rnd = 1800 + (random 600)
~ _rnd
{_x setdammage 0}foreach [object 167669,object 167792,object 167793,object 167794,object 167795,object 167797]
the script will basically start up when the mission starts
wait between 30 and 35 minutes
then repair each of the bridge sections on the Nogova bridge
If you wanted to maintain the bridge throughout the mission, then you would simply loop the script, say every 3 seconds or slower
BridgeRepair.sqs
#START
_rnd = 1800 + (random 600)
~ _rnd
#LOOP
{_x setdammage 0}foreach [object 167669,object 167792,object 167793,object 167794,object 167795,object 167797]
~3
goto "LOOP"
PS.... I may be wrong about setdammage being global (AFAIK it is), if it is local, eg the server repairs the bridge but you dont see a repaired bridge, then run the script on all machines.
Static objects such as buildings, ammo crates etc, i believe are local everywhere, similar but not quite the same as global.
Again, if i am wrong it wont take long before someone posts to correct me
OOPS! someone posted about the wait command while i was typing this essay ::)
-
Thanks guys that works nicely...
Before I close this thread I wanted to ask one question.
Is it possible to detect what time it is in a mission? I mean like having a Hint or sidechat message from a trigger telling what time it is at any given point in the mission?
Thanks again.
-
dont know which one you want, but you have 2 options
hint format ["%1",daytime]
returns the actual time of day
hint format ["%1",Time]
returns the time spent since the mission started (In seconds)
If you have a time limit, eg a value in Param1 or some other limiting mission time variable
then you could also do
_secsremaining = (Param1 - Time)
From either the Time command or the _secsremaining value some basic maths will then allow you to
change the seconds into hours, minutes and seconds (use of mod 1 command required)
which you can then display as a more informative hint format
hint format ["Mission time : %1-%2-%",_hrs,_mins_secs]
I suggest you check the online comref that OFPEC kindly host