OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: LongstreetCSA on 18 Jun 2006, 14:44:14
-
Hey there!
I'm nearly done with a few things I'm currently working on for the American Civil War Mod - but a few questions still remain: One is I have added a few addaction commands I thought would be nice to have and most of them are done in a way that they change, depending on what "command" you give your squad - f.e.: one is "follow me" for all the troops, if you give this command it is exchanged with a "hold position" command; a few other command are done in the very same manner - I did it that way so one doesn't have a long list of different commands to scroll through, but instead you always have the stuff you need. The only thing that bugs me is, I was unable to find a method to keep the position of all commands always the same f.e. the starting configuration looks something like that:
Order: Follow me
Order: Crouch
Order: Fire at will
Order: Volley
Order: Fix Bayonet
.
.
.
now if you execute the "follow me" command it is exchanged with the "hold position" command but the configuration changes to something like:
Order: Crouch
Order: Fire at will
Order: Volley
Order: Fix Bayonet
Order: Hold Position
.
.
.
and if f.e. you now execute the "fire at will" command, it is exchanged with a "cease fire" command and the configuration changess again to something like this:
Order: Crouch
Order: Volley
Order: Fix Bayonet
Order: Hold Position
Order: Cease fire
.
.
.
What I'm asking now: is there any way to retain the original positioning of the commands added with addaction, so to get rid of the need to search for the right command each time, because the positions keep changing all the time?
Like that:
Order: Follow me
Order: Crouch
Order: Fire at will
Order: Volley
Order: Fix Bayonet
.
.
.
after execution of "Follow me" it should look like this:
Order: Hold position
Order: Crouch
Order: Fire at will
Order: Volley
Order: Fix Bayonet
.
.
.
and not change the "hold position" command to the bottom of the commandl ist.
I hope I've been able to point out everything in a clear manner so you are able to grasp my point and the problem I'm having....
Hope anyone knows how to deal with that (btw. I'm really crap at scripting - it took me a VERY long time to get the things as far as I have them now, and without the help of already existing scripts and borrowing from those I wouldn't have been able to do anything)!
-
only way i could think of would be to remove all the actions and add them back in order.
-
Hey bedges!
Thank you for the answer! I tried to do as you suggested but I was unable to get it to work - I have the strong feeling I'm doing something wrong, so maybe if I post the scripts I use someone more clever than me might be able to figure out what's wrong or how to do what I'm trying to do....
-
hmm. am i right in thinking each of these actions has only two states?
if so it would be pretty simple to define a switch variable for each action, then strip out all the actions, and reapply them according to the switches.
i'll run up a test missionette to let you see.
/more later
-
Hey there! Thank you for still trying to help. I'm going to post the scripts I use, maybe that will help with finding a solution.
The first script that is started is the "OrderCommands.sqs" script, started in the "init"-field of the player:
-------------------OrderCommands.sqs
; Combat Commands Script
_group = _this select 0
_leader = leader _group
_officer = (units _group) select 0
_unit1 = (units _group) select 1
_unit2 = (units _group) select 2
_unit3 = (units _group) select 3
_unit4 = (units _group) select 4
_unit5 = (units _group) select 5
_unit6 = (units _group) select 6
_unit7 = (units _group) select 7
_unit8 = (units _group) select 8
_unit9 = (units _group) select 9
_unit10 = (units _group) select 10
_unit11 = (units _group) select 11
Stopm = true
Standm = true
Ceasem = true
volley = true
;[player] exec "Command\CommandInit1TEST.sqs"
[player] exec "Command\CommandInit1.sqs"
[player] exec "Command\CommandInit2.sqs"
[player] exec "Command\CommandInit3.sqs"
[player] exec "Command\CommandInit4.sqs"
[player] exec "Command\CommandInit5.sqs"
;[player] exec "CommandBayonet\scripts\init.sqs"
;_leader AddAction ["Order: Follow me","lb_scripts\AllFollow.sqs"]
;_leader AddAction ["Order: Hold position","lb_scripts\AllStop.sqs"]
;_leader AddAction ["Order: Crouch","lb_scripts\crouch.sqs"]
;_leader AddAction ["Order: Stand","lb_scripts\stand.sqs"]
;_leader AddAction ["Order: Fire volley","lb_scripts\volley.sqs"]
;_leader AddAction ["Order: Fire at will","lb_scripts\fireatwill.sqs"]
;_leader AddAction ["Order: Cease fire","lb_scripts\hold.sqs"]
;_leader AddAction ["Order: Surrender","lb_scripts\AllSurr.sqs"]
{_x allowfleeing 0} foreach units _group
_group setcombatmode "BLUE"
-----------------------------
the lines starting with ";" are either old stuff from the original script or stuff I put in to try various things. The lines starting with "_leader AddAction....." are those I used before I came up with the idea of changing commands.
The first main script that is started is the "CommandInit1.sqs" script with the following text:
---------------CommandInit1.sqs
Unit = _This Select 0
?(_unit != player) : exit
;_Section = Group _Unit
;_SectionCmdr = Leader _Section
;?_SectionCmdr != Player:exit
;_group = _this select 0
;_leader = leader _group
;_act01 = _this select 2
Stopm = true
#init
;? _Unit != (Leader Group _Unit): Exit
;? (Count Units Group _Unit) == 1: Exit
;? (Count Units _Section == 1) and (_SectionCmdr != Player): Exit
? !alive player : player RemoveAction _act01 , goto "init"
?Stopm : player RemoveAction _act01,_act01 = player AddAction ["Order: Follow me","Command\AllFollow.sqs"],Stopm=false
?Followm :player RemoveAction _act01, _act01= player AddAction ["Order: Hold position","Command\AllStop.sqs"],Followm=false
goto "init"
-------------------------
again the stuff with the ";" at the beginning are code from the original script.
As you can see there are 2 seperate scripts used - one is the "AllFollow.sqs" and the other one is the "AllStop.sqs" with the following text in them:
--------------Allfollow.sqs
_group=_this select 0
;_leader=_this select 1
_leader = leader _group
{_x dofollow player} forEach units _group
Followm=true
Standm=true
comeflag=true
exit
--------------AllStop.sqs
_group=_this select 0
;_leader=_this select 1
_leader = leader _group
{dostop _x; _x allowFleeing 0; _x disableAI "Target"} forEach units _group
Stopm=true
comeflag=false
Exit
-----------------------------
the "comeflag=true" and "comeflag=false" lines used in those two scripts refer to another one that is used to let a "flagbearer" follow the player around without joining him to the group, making this flagbearer stop when the group is stopped and follow when the group is following - that is actually working just fine as it is.
The next script started at the beginning is the "CommandInit2.sqs" with the following stuff in it:
---------------CommandInit2.sqs
_Unit = _This Select 0
?(_unit != player) : exit
;_act2 = _this select 2
Standm = true
#init
? !alive player : player RemoveAction _act2 , goto "init"
?Standm : player RemoveAction _act2,_act2 = player AddAction ["Order: Crouch","Command\crouch.sqs"],Standm=false
?Crouchm :player RemoveAction _act2, _act2= player AddAction ["Order: Stand","Command\stand.sqs"],Crouchm=false
goto "init"
-----------------------
as you can see it is refering to 2 seperate scripts called "crouch.sqs" and "stand.sqs" both with the following text in 'em:
----------crouch.sqs
_squad=_this select 0
_leader=_this select 1
{_x setbehaviour "combat"; _x PlayMove "CombatToCrouch"; _x setunitpos "up"} forEach units _squad
Crouchm=true
exit
-----------------------stand.sqs
_squad=_this select 0
_leader=_this select 1
{_x setUnitPos "UP";_x PlayMove "Combat";_x allowFleeing 0;_x setbehaviour "combat"} forEach units _squad
Standm=true
Exit
-----------------------
the next script in line at the beginning is the "Commandinit3.sqs" script with the following text:
------------CommandInit3.sqs
_Unit = _This Select 0
?(_unit != player) : exit
;_act3 = _this select 2
Ceasem = true
#init
? !alive player : player RemoveAction _act3 , goto "init"
?Ceasem : player RemoveAction _act3,_act3 = player AddAction ["Order: Fire at will","Command\fireatwill.sqs"],Ceasem=false
?fireatwillm : player RemoveAction _act3, _act3= player AddAction ["Order: Cease fire","Command\Cease.sqs"],fireatwillm=false
goto "init"
---------------------
Again it is refering to 2 changing scripts called "fireatwill.sqs" and "cease.sqs" both with the following code in them:
------------fireatwill.sqs
_squad=_this select 0
_leader=_this select 1
Standm=true
{_x setCombatMode "YELLOW"} forEach units _squad
;_squad setCombatMode "YELLOW"
;_x setbehaviour "combat";
fireatwillm=true
exit
----------------cease.sqs
_squad=_this select 0
_leader=_this select 1
{_x setCombatMode "Blue"} forEach units _squad
Ceasem=true
;_squad setCombatMode "BLUE"
;_x setbehaviour "aware";
exit
----------------------
The next command initialised at the beginning is the "CommandInit4.sqs" with the following text in it. As you will see that is NOT a script that is changing but one that is just refering to a single script that is ONLY activated when the groupsize is getting lower than 4 squadmembers, to give the player the chance to surrender to the overwhelming forces and to survive the fight (that is only if he want's to do that...
-------------------------CommandInit4.sqs
_SquadLeader = _this select 0
_group = group _squadLeader
;_act4 = _this select 2
#count
? !alive _SquadLeader : exit
_groupSize = count Units _group
?_groupsize < 4 : surrender=true, goto "init"
goto "count"
#init
? !alive player : player RemoveAction _act4 , goto "init"
?surrender : player RemoveAction _act4,_act4 = player AddAction ["Order: Surrender!","Command\AllSurr.sqs"],surrender=false
;?fireatwillm : player RemoveAction _act4, _act4= player AddAction ["Order: Cease fire","Command\Cease.sqs"],fireatwillm=false
goto "init"
--------------------
it is refering just to the "allsurr.sqs" script:
---------------------allsurr.sqs
_squad=_this select 0
_leader=_this select 1
{_x setCombatMode "BLUE";_x allowFleeing 0} foreach units squad
#Captive
{_x setcaptive TRUE} forEach units _squad
{_x action ["DROP WEAPON", _x, 0, 0, (primaryweapon _x)]} forEach units _squad
~1
? secondaryWeapon _unit == "" : goto "next"
{_x action ["DROP WEAPON", _x, 0, 0, (secondaryweapon _x)]} forEach units _squad
~1
#next
? !(alive _x) : exit
surr1=true
{removeallweapons _x} forEach units _squad
{_x switchmove "FXStandSurUniv"} forEach units _squad
{_unit setunitpos "UP"} forEach units _squad
exit
-------------------
The last script startet at the beginning is the "CommandInit5.sqs", again it is not one of the changing scripts, because the fire volley command works in a way that the group members fire their weapons, reload and then holding their fire, waiting for further commands (that way eliminating the need to put in an extra cease fire command):
---------CommandInit5.sqs
_SquadLeader = _this select 0
_group = group _squadLeader
;_act5 = _this select 2
;_Unit = _This Select 0
;?(_unit != player) : exit
volley = true
#init
? !alive player : player RemoveAction _act5 , goto "init"
?volley : player RemoveAction _act5,_act5 = player AddAction ["Order: Volley","Command\volley.sqs"],volley=false
;?fireatwillm : player RemoveAction _act5, _act5= player AddAction ["Order: Cease fire","Command\Cease.sqs"],fireatwillm=false
goto "init"
--------------------
It is refering to only one script named "volley.sqs" with the following text:
------------volley.sqs
_squad=_this select 0
_leader=_this select 1
Standm=true
Ceasem = true
{_x setUnitPos "UP"; _x PlayMove "Combat"; _x setbehaviour "combat"; _x allowFleeing 0} forEach units _squad
_squad setCombatMode "YELLOW"
~2
_squad setCombatMode "RED"
~4
_squad setCombatMode "BLUE"
exit
-------------------------
That are the scripts I am using - I know there are a lot of lines in there that one doesn't need for starters all those lines with the ";" in front - they should of course be all eliminated to make the scripts work much smoother amd faster. I'm quite certain that many things I have done could be done easier in some way - just that I don't have the slightest clue how - so maybe you can figure it out? Hope you can!
....*gasp* that's my longest forum post EVER! *lol*....
-
well, i dunno about any of that. take a look at the attached missionette for an illustration on how i would keep the actions in order.
[attachment deleted by admin]
-
Just butting in I guess, but this quote
I'm nearly done with a few things I'm currently working on for the American Civil War Mod - but a few questions still remain: One is I have added a few addaction commands I thought would be nice to have and most of them are done in a way that they change, depending on what "command" you give your squad
seems to hint that you are giving actions to custom soldiers in your mod.. (?)
If I'm right may I ask why on earth are you using addAction to do that ???
There's a thing called class userActions which you can use in the config with which you can add actions much less painfully than using the dodgy addAction... And it is meant just for this kind of use...
userAction appear in the action menu in the order you have them in the config (IIRC)...
If I'm wrong and you are adding those actions to say BIS default units then ignore me ;)
-
Hey nice that you join in the discussion - yes you are right I'm trying to give actions to custom soldiers (those for the American Civil War Mod and not the normal ones) in the player squad - like have them all go to crouch position and so on (like IRL during those days when the squadleader gives the command all do as told). I didn't know that there was any other way in giving the player those additional commands for the whole squad, than the "addaction"-way (after all I'm definitely not a pro - but just have ideas and not a clue how to get 'em to work). Didn't know the stuff with this "calss userActions" you did mention - when they are used, are they executed by the whole group? How can it be done? Is it possible to have commands done that way "change" and stay in the same relative position? I really have not the slightest clue how do do it.
-
I hate these situations when a scripting discussion turns into config discussion and becomes sort of off-topic in this part of the forum... ::)
But I'll let the moderators sort this one out.. :P
The simpliest examples of userActions are the "Lower Goggles/Visor" etc. actions, so if you look up for some soldier addon you're bound to find such actions used..
I believe for example the Laser's soldier addons (search at ofp2.info or at BI Forums) have such actions..
So you can take a look at some addon's config to fully understand how they're used...
But basicly you add an action to a unit and once the unit uses that action some command/script is executed or some variable is set...
I'll give an example, it's very basic..
The complexity of setting up the userActions depends completely on what you are trying to achieve..
Default BIS West soldier config
class SoldierWB:Soldier
{
model="MC vojakW2";
hiddenSelections[]={"medic"};
moves="CfgMovesMC";
picture="ivojak";
vehicleClass="Men";
scope=2;
side=1;
accuracy=0.7;
displayName="$STR_DN_SOLDIER";
weapons[]={"M16","Throw","Put"};
magazines[]={"M16","M16","M16","M16","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
cost=40000;
};
Then you add the userAction for it
class SoldierWB:Soldier
{
model="MC vojakW2";
hiddenSelections[]={"medic"};
moves="CfgMovesMC";
picture="ivojak";
vehicleClass="Men";
scope=2;
side=1;
accuracy=0.7;
displayName="$STR_DN_SOLDIER";
weapons[]={"M16","Throw","Put"};
magazines[]={"M16","M16","M16","M16","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
cost=40000;
class UserActions
{
class someuseraction
{
displayName="Blah Blah"; //the name of the action, displayed in the action menu
position="pos driver"; //the place on the model on which the action as "attached" to, can be any named selection..
radius=0.1; // radius around the position (above) inside which the action comes available, in meters..
condition="(vehicle this == this) && somevariable"; //works basicly like trigger's condition field, 'this' refers to the unit
statement="do some stuff"; //works basicly like trigger's on activation field
};
};
};
With multiple actions
class SoldierWB:Soldier
{
model="MC vojakW2";
hiddenSelections[]={"medic"};
moves="CfgMovesMC";
picture="ivojak";
vehicleClass="Men";
scope=2;
side=1;
accuracy=0.7;
displayName="$STR_DN_SOLDIER";
weapons[]={"M16","Throw","Put"};
magazines[]={"M16","M16","M16","M16","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
cost=40000;
class UserActions
{
class someuseraction
{
displayName="Blah Blah";
position="pos driver";
radius=0.1;
condition="(vehicle this == this) && somevariable";
statement="do some stuff";
};
class someuseraction_2
{
displayName="Yada Yada";
position="pos driver";
radius=0.1;
condition="(vehicle this == this) && !(somevariable)";
statement="this exec ""somescript.sqs""";
};
class someuseraction_3
{
displayName="Babble Babble";
position="pos driver";
radius=0.1;
condition="(vehicle this == this) && this hasWeapon "someweapon"";
statement="this exec ""someotherscript.sqs""";
};
};
};
Not the most clear explanation, I know... :-\
-
Hey HareR_Kint!
Thank you for your reply! Sorry I couldn't check out the page and your answer earlier. Problem is I'm a bit confused. Do I have put all of that stuff in the "class userActions" of every soldier I want to control that way? Or do I have to put it just in the config file of the one the player is using? And I quite at a loss to understand that stuff:
displayName="Blah Blah"; //the name of the action, displayed in the action menu
position="pos driver"; //the place on the model on which the action as "attached" to, can
be any named selection..
radius=0.1; // radius around the position (above) inside which the action comes available,
in meters.
condition="(vehicle this == this) && somevariable"; //works basicly like trigger's condition field, 'this'
refers to the unit
statement="do some stuff"; //works basicly like trigger's on activation field
Why do I need a position? Or radius? As I said I'm quite confused. Isn't there a way to explain it better? Or can you suggest some kind of FAQ or testfile for a config dummy like me? I'm awfully sorry that this discussion has jumped from addAction to config stuff - but since I didn't know about the config possibility and since there remains the addAction way to do such stuff (although you pointed out that it's a rather rude way to do it) I guess it's alright for it to remain here, don't you think? I hope you or any pro can show me a way or help me to implement what I'm trying to do into the config like you told me to do. The thing I'm wondering about too is, how it works with your group in the first place and where to put the scripts that you are calling. *confused is*
Well the thing I'm glad about is that you are trying to help ;) thank you for that one!
-
<- Lenghty post warning ->
Do I have put all of that stuff in the "class userActions" of every soldier I want to control that way?
If you don't want it to get too confusing, then yes..
Otherwise, there are other ways..
You know how in the config the soldiers inherit from a parent class, like
class mysoldierclass: SoldierWBwhere the SoldierWB is the parent class (which itself inherits fom yet another parent class) for the mysoldierclass
Now, all the parameters (values/whatever) the parent class includes will be inherited by the child class, in this case the mysoldierclass, and you can then edit those parameters without affecting the parent class..
A simple example:
class SoldierWB:Soldier
{
model="MC vojakW2";
hiddenSelections[]={"medic"};
moves="CfgMovesMC";
vehicleClass="Men";
scope=2;
side=1;
accuracy=0.7;
displayName="$STR_DN_SOLDIER";
weapons[]={"M16","Throw","Put"};
magazines[]={"M16","M16","M16","M16","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
cost=40000;
};
class mysoldierclass: SoldierWB
{
vehicleClass="Mod Men";
displayName="some guy";
};
The mysoldierclass now has all the same parameters as the parent class except for the two bolded parameters..
So, when you add that userAction class into the parent class from where your soldiers inherit from it will be available on all your soldiers and you don't need to copy/paste the same useraction class into all your soldier classes..
Or, you can use the #define..
There are basic #defines in the start of the config, and you can add your own if you will..
Example:
#define my_useractions_def class UserActions \
{ \
class someuseraction \
{ \
displayName="Blah Blah"; \
position="pos driver"; \
radius=0.1; \
condition="(vehicle this == this) && somevariable"; \
statement="do some stuff"; \
}; \
class someuseraction_2 \
{ \
displayName="Yada Yada"; \
position="pos driver"; \
radius=0.1; \
condition="(vehicle this == this) && !(somevariable)"; \
statement="this exec ""somescript.sqs"""; \
}; \
class someuseraction_3 \
{ \
displayName="Babble Babble"; \
position="pos driver"; \
radius=0.1; \
condition="(vehicle this == this) && this hasWeapon "someweapon""; \
statement="this exec ""someotherscript.sqs"""; \
}; \
}; \Now, this is less messy to copy/paste into each soldier class if you wish to do so, but the parent class thingy explained above works with this as well..
But now as you have the define my_userActions_def you only need to add that line in the parent class or in each soldier class
class SoldierWB:Soldier
{
model="MC vojakW2";
hiddenSelections[]={"medic"};
moves="CfgMovesMC";
vehicleClass="Men";
scope=2;
side=1;
accuracy=0.7;
displayName="$STR_DN_SOLDIER";
weapons[]={"M16","Throw","Put"};
magazines[]={"M16","M16","M16","M16","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
cost=40000;
};
class mysoldierclass: SoldierWB
{
vehicleClass="Mod Men";
displayName="some guy";
my_userActions_def
};
class mysoldierclass_2: mysoldierclass
{
vehicleClass="Mod Men";
displayName="some guy 2";
};Now both soldiers, some guy and some guy 2 will have the same actions without needing the copy/paste..
If you want to use the copy/paste into each soldier class, it would be like this
class SoldierWB:Soldier
{
model="MC vojakW2";
hiddenSelections[]={"medic"};
moves="CfgMovesMC";
vehicleClass="Men";
scope=2;
side=1;
accuracy=0.7;
displayName="$STR_DN_SOLDIER";
weapons[]={"M16","Throw","Put"};
magazines[]={"M16","M16","M16","M16","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade","HandGrenade"};
cost=40000;
};
class mysoldierclass: SoldierWB
{
vehicleClass="Mod Men";
displayName="some guy";
my_userActions_def
};
class mysoldierclass_2: mysoldierclass
{
vehicleClass="Mod Men";
displayName="some guy 2";
my_userActions_def
};
Why do I need a position?
As I said, it's named selection on the soldier model..
For example hlava is the soldier's head, and it's that position the action is "attached" to if you choose to use the hlava selection (if named sleections are a mystery, take a look at some basic modelling tutorials (http://www.ofpec.com/ed_depot/the_files/OFPResources/tutorials/BrsSeb.zip) :) )..
If you don't have a position for the userAction it will not appear in the action menu..
This is just how OFP works..
Or radius?
This goes hand in hand with the position..
It's a radius (in meters I think) from the position where the action is available, so using radius=0.1 should keep the action only for the soldier itself and not "leak" it to soldiers coming close..
Or can you suggest some kind of FAQ or testfile for a config dummy like me?
I'm not sure whether there are any FAQs or tutorials for this, but like I said in my earlier post, look for released AddOns that have those extra actions for the soldiers and take a look at those configs..
Although, I could write you a 'real' example myself... ???
how it works with your group
Not exactly sure what you mean..
If you for example want certain action to be available for the leader of the group only you can use something like this in the condition of the userAction (not exactly sure that would work as is, just an example)
condition="((count units) group this)>1 && leader group this == this";this refers to the unit on who the action is attached to..
where to put the scripts that you are calling.
When you are making a mod it depends..
If you are making a total conversion mod you can use the scripts.pbo in the OFP/Dta/ folder, or you can use some addon pbo if you wish..
For example if you have the soldiers as an addon in mymod_soldiers.pbo you can put the scripts in there, for example in a folder called scripts..
Now, to exec a script from there you will use filepath for it, in this case
\mymod_soldiers\scripts\the_script.sqs
So, a 'full' userAction class might look something like this
class userActions
{
class action1
{
displayName="Use the Actrion";
position="hlava";
radius=0.1;
condition="vehicle this == this && ((count units) group this)>1 && leader group this == this";
statement="[this] exec ""\mymod_soldiers\scripts\the_script.sqs""";
};
};
Ok, this messy and insanely long post just probably confuses you more :-[
But I hope this helps even a little bit..
-
Go Kint!
In the good old days I'd've added this to the FAQ. Hrm. Too bad the FAQ is gone. And me being a moderator ^^. Maybe you can write up a tutorialette from this for future reference?
Just spamming. Pardon.
/Wolfrug out.
-
Maybe you can write up a tutorialette from this for future reference?
Worth considering..
At least it would be one messy tutorial :P