Home   Help Search Login Register  

Author Topic: individualising addon vars (scripting question)  (Read 2187 times)

0 Members and 1 Guest are viewing this topic.

ROBINO

  • Guest
individualising addon vars (scripting question)
« on: 07 Dec 2005, 16:00:29 »
OK my question in a nutshell is this:

How do I individualise publicvariables - used to sychronise the changing status of an addon in a MP mission - to the specific instance of the addon.

Here is my question in a more detialed manner:

I have boat1 which is meant to "deploy" (createvehicle), boat2.  Only 1 boat2 can be deployed for each boat1. The deployment is triggered by a player activating an action in the action list of boat1.  To keep the action list updated for all the other players a publicvariable is made true (and transmitted to other players) when boat2 is deployed - like this:

Code: [Select]
boat2deployed = true
publicvariable "boat2deployed"


But if I have 2 boat1's in a mission - they use the same publicvariable - and thats my problem.  Because when   boat1(a) deploys a boat2, boat1(b) also thinks it has deployed a boat2 aswell. And boat1(b) cannot deploy anymore.

I'm sure my question has been asked before. Other addons I have seen use animationphases to monitor the status of each instance of thier addons in-mission. Unfortunately boat1 does not have any animations.

Also, in trying to make the addons as robust as possible, lets assume that the person making missions with the addon has NOT given either boat1 a name - and expects both boat1(a) and boat1(b) to deploy their invididual boat2's.

Thnx for any help you can be.
« Last Edit: 07 Dec 2005, 16:03:44 by ROBINO »

LoTekK

  • Guest
Re:individualising addon vars (scripting question)
« Reply #1 on: 07 Dec 2005, 16:27:07 »
I'm not particularly well versed with MP scripting, but could you possibly define an array to hold a separate instance of each boat1's status?

ROBINO

  • Guest
Re:individualising addon vars (scripting question)
« Reply #2 on: 07 Dec 2005, 18:00:31 »
but then i need a unique identity for each array for each boat1

so we have the original problem all over again

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:individualising addon vars (scripting question)
« Reply #3 on: 07 Dec 2005, 18:02:12 »
Have you investigated if Fragorl's setProperty and getProperty functions could be used for this? If not, then it might be worth to look at them. They are in the function library. Read also what Fragorl wrote to Properties for objects.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:individualising addon vars (scripting question)
« Reply #4 on: 07 Dec 2005, 18:40:14 »
I think this topic would be better suited in the MP editing board, or at least it'd have the best chance of being seen by the right people there.

Anywhoo, this is kinda a tricky one. First of all, I believe you can always add an invisible part to a model, and have that animate. However, the 'animationphase' command doesn't work on a dedicated server, so that isn't a good route to go for a MP-compatable addon.

Arrays would be a simple solution. You could have one global array (ROB_boats) that holds all the boats that have not yet deployed a second boat. When they deploy that second boat, you would then remove the boat from the array.

The problem, of course, is that 'publicvariable' does not support arrays!

I would suggest that you take a look at the CoC's Network Services 2 (found on their website; currently down). It has all sorts of functions that make MP scripting super-useful. One of them is to transfer arrays across the network.

Of course, that would mean that missions made with your addon would also have to be using NS, which you might not like. But if you have any more MP scripting than just this, it might be well worth using it anyway.

If you want to do it without NS, then I actually have no idea how to go about it.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

ROBINO

  • Guest
Re:individualising addon vars (scripting question)
« Reply #5 on: 07 Dec 2005, 19:46:43 »
Ok thnx for rapid feedback.

I've looked at Fragorl's scritps and from what I can make-out it does not make the transferal or creation of individual addon vars for MP easier.

@general barron

i'm sure the animationpahses work in all MP situations because they are defined as conditions in config.cpp.  When one player activates the door (on UKF's Landrovers for example) we see an updated action list on all client machines. I took this line from thier config.cpp referring to useraction "openrightdoor":

Code: [Select]
condition="isnull (driver this) && !(isengineon this) && this animationPhase {RightDoor} ==0";


Anyway i think  i may have an idea - a way for each client to assign individual publicvariable names for each instance of the boat1 addon - from the start of the mission

1) the addon scripts initialise but do not initialise any publicvars yet
2) script1 does a getpos on its instance of boat1
3) it converts the returned position to a string and adds it to a string boat2deployed i.e so we get  boat2deployed5567865

now each client is able to arrive at the same var name for each boat1 without having to communicate with the server or any other client.

Now all I have to do is figure out a way to use these var names...

If anyone can be anymore help plz do. If i'm barking up the wrong tree plz tell me.



Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:individualising addon vars (scripting question)
« Reply #6 on: 07 Dec 2005, 20:13:04 »
I checked, and it turns out that the bug is that when called on a dedicated server, animationphase is always 0. Since the action is checked on the player's machines, you're right, it is fine.

So in your case, I would suggest making a invisible something on the model, and make an animation for it. That would be the easiest solution.

The problem with trying to make a variable based off of the position is that:

1) A position consists of like a 8-digit number with a decimal
2) You have no way of doing the reverse: that is, finding which boat belongs to which variable

---------------------

Here is a method that MIGHT work, although I'd still recommend using animations or CoC NS:

Each boat adds itself to a global array:

Code: [Select]
ROB_boats = ROB_boats + [this]So the array would look something like this after the mission starts:

Code: [Select]
ROB_boats = [boat1, boat2, boat3...]The condition for the action to deploy another boat looks something like this:

Code: [Select]
this in ROB_boats
This means that as long as the boat is in the global array, you can deploy another boat from it. Therefore, if you deploy another boat from, say, boat2, that means you need to remove boat2 from the ROB_boats array on every client.

So in your deployment/action script, you would need to add something like this:

Code: [Select]
ROB_boat_deployed =  [_boat, ROB_boats] call indexOf
publicvariable "ROB_boat_deployed"
IndexOf is a simple function to find the index of a variable within an array. Grab it here.

Finally, you would have a single looping script (no matter how many boats are in the mission), running on all clients, which looks like this:

Code: [Select]
#top
ROB_boat_deployed = -1
@ ROB_boat_deployed >= 0
ROB_boats = ROB_boats - [ROB_boats select ROB_boat_deployed]
? count ROB_boats > 0 : goto "top"
This script removes the boat at index "ROB_boat_deployed" from the ROB_boats array; that is, the boat that just deployed another boat. Remember; we can't 'publicvariable' arrays. So what we are doing here is just 'publicvariabling' an index (number).


HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:individualising addon vars (scripting question)
« Reply #7 on: 07 Dec 2005, 21:14:22 »
I havent read all this, from a quick scan if you want each addaction to only create 1 boat

eg boat 1 has addaction, running that create's boat 1a
eg boat 2 runs an addaction that creates boat 2a



simply remove the action once it has been run, by placing the following lines in the addaction script

so the system would look something like this

MISSION EDITOR
In the init field of each boat you want to have a "Createvehicle addaction"
(Or if an addon, in its useraction init) place the following

this addaction ["Deploy Boat","Deploy.sqs"]

DEPLOY.SQS
Quote
_boat = _this select 0
_action = _this select 2
_boat removeaction _action
_newboat = "classname" createvehicle _position




if you need to give the createvehicle vehicle a dynamically named variable

then simply use the format command and increment a count

you could also if required add this to an array, count the array and then you could call on this variable by using
_array select  _element
« Last Edit: 07 Dec 2005, 21:22:59 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

ROBINO

  • Guest
Re:individualising addon vars (scripting question)
« Reply #8 on: 07 Dec 2005, 21:52:14 »
@general barron

very interesting - this does, indeed, look like a solution and i will try it possibly tomorrow

however, the only missing thing i can find is a way of running only 1 of your looping scripts on a client. Of course, remembering the way addons work they will try to run instances of every script for every instance of the addon on the map.

lets call your final script "loopcheck.sqs" and we call it from the inititialisation of boat1

i guess i could add a random time delay after which a flag signals that the script is already running - so "loopcheck.sqs" becomes:


Code: [Select]
_starttime = time
_wait = _starttime + (random(4))
@(time == _wait)
?(loopcheckrunning):exit
loopcheckrunning = true

#top
ROB_boat_deployed = -1
@ ROB_boat_deployed >= 0
ROB_boats = ROB_boats - [ROB_boats select ROB_boat_deployed]
? count ROB_boats > 0 : goto "top"

i think that should work - plz correct me if i am talking a load of pants

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:individualising addon vars (scripting question)
« Reply #9 on: 08 Dec 2005, 09:51:01 »
Quote
plz correct me if i am talking a load of pants
Hmm... that's an expression I haven't heard before. I like it though :).

Anyway, your method would work, but there is a better way.

I forgot to mention that you have to initialize the global array, before you can add each boat to it. SOME boat is going to have to be the first boat to add itself to the ROB_boats array, so it will also have to create the array. At the same time, we can kill two birds with one stone, and have that first boat also start up the looping script:

Script run from addon's init EH:

Code: [Select]
? format ["%1", count ROB_boats] == "SCALAR" : ROB_boats = []; [] exec "boat_deploy_monitor.sqs"
ROB_boats = ROB_boats + [_this select 0]
.....

Now, I could be wrong about that first line, unfortunately. "SCALAR" should be what is printed out when you try to 'format' the count of a non-existant variable... but check by using a hint first. Anyways, the idea is, if the ROB_boats array doesn't exist yet (because this is the first boat initialized), then it is initialized, and the looping script is also run.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!