Jump to content

Recommended Posts

So I’m new to coding in general and thought I’d try out scripting in arma 3, I have written code but it does not do as intended. And I don’t even know if I’m using the right commands, I’m done trying to rack my brain scouring BI script command list and random YouTube videos if anyone know how to achieve this please post it here or reference me to where I can get help.

 

so here’s what I want to do:

1. Give variable name in Eden editor.

2. Get variable name given in Eden editor for reference in script as a “class”.

3. Use variable name “class”  to run a specific script.

 

plot example:

Object (unit) variable name given in editor = Assault 

//in script

code to get the variable name of “This” unit.

code to check if the variable name is equal to a specific class name.

code that executes another code if the check returns true.

 

if you have any insight on how to achieve this or even close to it please reply

Share this post


Link to post
Share on other sites
2 hours ago, Dnote Gaming said:

1. Give variable name in Eden editor.

https://community.bistudio.com/wiki/Eden_Editor:_Object#Attributes

https://community.bistudio.com/wiki/Eden_Editor:_Entity_Attributes#Attribute_Categories

 

2 hours ago, Dnote Gaming said:

2. Get variable name given in Eden editor for reference in script as a “class”.

https://community.bistudio.com/wiki/isKindOf

 

2 hours ago, Dnote Gaming said:

3. Use variable name “class”  to run a specific script. 

https://community.bistudio.com/wiki/if

 

You can use this code on a Trigger or you can use it on init.sqf file inside your mission folder.

 

This is your Scripting Glossary:

https://community.bistudio.com/wiki/Category:Arma_3:_Scripting_Commands

This is your Eden Editor basics:

https://community.bistudio.com/wiki/Category:Eden_Editor

This might give you an intro overview of things:

https://community.bistudio.com/wiki/Initialization_Order

 

You need to read a little bit. See other people's scripts is how I started.

Feel free to ask further questions.

  • Like 1

Share this post


Link to post
Share on other sites

Can I get an example using these commands or could you correct this. I am quit lost on how to implement these properly.

 

//code

_unit = _this select 0;               // would make sure the current unit is selected?

_unit isKindOf “Assault”;        // would tell Arma 3 that this unit’s variable name is Assault?

if (_unit == “Assault”) then {

null = [_unit] execVM “Assault.sqf”;};    // would tell Arma 3 to run this script for the selected unit?

 

Edited by Dnote Gaming
Missed quote

Share this post


Link to post
Share on other sites
1 hour ago, Dnote Gaming said:

_unit = _this select 0;               // would make sure the current unit is selected? 

Depends where/how you run it.

 

1 hour ago, Dnote Gaming said:

_unit isKindOf “Assault”;        // would tell Arma 3 that this unit’s variable name is Assault? 

No, you name the unit's Variable Name on the Editor under Attributes:

3den_attributesMenu.gif

 

 

1 hour ago, Dnote Gaming said:

null = [_unit] execVM “Assault.sqf”;};    // would tell Arma 3 to run this script for the selected unit? 

It would run "for" _unit if _unit is defined properly.

 

1 hour ago, Dnote Gaming said:

Can I get an example using these commands or could you correct this.

If you're running from the unit's Init field e.g. (picture above) you could do:

if (this isKindOf "Man") then {
 this execVM "assault.sqf";
};

See I used "Man" as a class. "Assault" is not a class. A class in this case (isKindOf) would be a type  of vehicle.

 

assault.sqf could look something like:

params [_unit];

//code e.g.
_unit doMove (getMarkerPos "Here");

 

If you want to run this from somewhere else (which you probably do) you could name your unit (Variable Name) and then you can call it from anywhere in the game:

null = soldier1 execVM "assault.sqf";
//assault.sqf
params [_unit];

//code e.g.
if (_unit isKindOf "Man") then {
	_unit doMove (getMarkerPos "Here");
}else{
  	_unit doMove (getMarkerPos "There");
};

 

If you want you can also name your group's Variable Name on the Editor under Attributes.

3den_group_icon.gif

 

Then you could e.g.

null = soldier1 execVM "assault.sqf";
//assault.sqf
params [_unit];

//code e.g.
if (group _unit isEqualtTo "Assault") then {
	_unit doMove (getMarkerPos "Assault Here");
};
if (group _unit isEqualtTo "Defense") then {
	_unit doMove (getMarkerPos "Defend Here");
};

 

  • Like 1

Share this post


Link to post
Share on other sites

So here is what I want to do using Single player respawn from 3den enhanced. Every time a player respawns I want them to get a random weapon from a custom array. I want to use their variable names to determine which weapon array they will get their weapon from.

#WORKS = code is working

#HELP = code is not working

 

 UnitClass.sqf // runs on every respawn 

_unit = _this select 0;

_unit setvariable [“myvariable”, _unit];    // sets the Eden editor given variable name “Assault1”. #WORKS

_class = _unit getVariable “myvariable”; // gets the assigned variable name. #WORKS

hint format [“%1”, _class];  // shows the variable name as a hint. #WORKS

if ( _class == “Assault1”) then {null = [_this] execVM “Assault.sqf”; };  // supposed to run script but does not work. #HELP

 

from the code above I get a generic error in expression, or it just does nothing.

 

Assault.sqf // supposed to get called when if statement return’s true 

_unit = _this select 0;

hint “hello”; // just to visually verify the code is executing. #WORKS

_pWeap = primaryWeapon  _unit;  // supposed to get the primary weapon string name of unit. #HELP

_unit removeWeapon _pWeap; // supposed to remove primary weapon only from given string name.  #HELP

 

the _pWeap keeps giving me “ error primaryWeapon: Type Array. expected object” I don’t know what array it’s getting the unit only has 1(one) primary gun.

 

 

if you notice anything what my codes are missing or could change to make them execute I’d appreciate the feedback.

 

Share this post


Link to post
Share on other sites
1 hour ago, Dnote Gaming said:

if ( _class == “Assault1”) then {null = [_this] execVM “Assault.sqf”; };  // supposed to run script but does not work. #HELP 

You're passing _this, you want _unit:

if ( _class == "Assault1") then {null = [_unit] execVM "Assault.sqf"};  // supposed to run script but does not work. #HELP

 

Share this post


Link to post
Share on other sites
7 hours ago, Dnote Gaming said:

if you have any insight on how to achieve this or even close to it please reply

 

You should say what is your final goal. A variable name is not a class (a class of what?) To do what?

 

4 hours ago, Dnote Gaming said:

So here is what I want to do using Single player respawn from 3den enhanced. Every time a player respawns I want them to get a random weapon from a custom array. I want to use their variable names to determine which weapon array they will get their weapon from.

 

 

I can't say how 3den enhanced works for respawning player in SP (I'm just using unconsciousness in my mod, so player never really dies and the played unit is never null).

But there are different ways. For example, without 3den enhanced mod, you can single respawn like this:

 

in init.sqf, or any where else like init field of the player or even a crate...
 

addMissionEventHandler ["entityKilled",{
   params ["_unit","_corpse"];
   _grp = group _unit;
   _new = _grp createUnit [typeOf _unit,getpos _unit,[],0,"NONE"];
   selectPlayer _new;
   if (leader _grp == _unit) then {
     [_new,_grp] spawn {
      params ["_new","_grp"];
      sleep 0.3;
      _new joinAsSilent [_grp,1];  
      _grp selectLeader _new;
    };
  };
  deleteVehicle _corpse;
 }];

 

That's the very basic, creating same kind of unit but with standard loadout.

If you need same loadout as at start, in init field of the player:


 

plyrLoadout = getUnitLoadout this;
addMissionEventHandler ["entityKilled",{
   params ["_unit","_corpse"];
   _grp = group _unit;
   _new = _grp createUnit [typeOf _unit,getpos _unit,[],0,"NONE"];
   selectPlayer _new;
   _new setUnitLoadout plyrLoadout;
   if (leader _grp == _unit) then {
     [_new,_grp] spawn {
      params ["_new","_grp"];
      sleep 0.3;
      _new joinAsSilent [_grp,1];  
      _grp selectLeader _new;
    };
  };
  deleteVehicle _corpse;
 }];

 

 

Same loadout as at death:

addMissionEventHandler ["entityKilled",{
   params ["_unit","_corpse"];
   _grp = group _unit;
   _ldout = getUnitLoadout _unit;
   _new = _grp createUnit [typeOf _unit,getpos _unit,[],0,"NONE"];
   selectPlayer _new;
   _new setUnitLoadout _ldout;
   if (leader _grp == _unit) then {
     [_new,_grp] spawn {
      params ["_new","_grp"];
      sleep 0.3;
      _new joinAsSilent [_grp,1];  
      _grp selectLeader _new;
    };
  };
  deleteVehicle _corpse;
 }];


 

  • Like 1

Share this post


Link to post
Share on other sites

@pierremgi I don’t want the same full loadout I want a different primary weapon on respawn.

Also the 3den enhanced single player respawn  uses the same unconsciousnesses as the killed state.
My problem is  I can’t get my if statement to check the new state of _class.

the hints command works and shows  Assault1, but then when I reach the if statement to check if _class = Assault1 it says Generic error in expression.

what am I missing for my if statement? Or am I writing the wrong code?

Share this post


Link to post
Share on other sites
8 hours ago, RCA3 said:

You're passing _this, you want _unit:


if ( _class == "Assault1") then {null = [_unit] execVM "Assault.sqf"};  // supposed to run script but does not work. #HELP

 

I changed it to {null = [ _unit] execVM “Assault.sqf”};  and still nothing, also I removed that command and just put a simple hint command and it still won’t work. I don’t think the if command checks the _class or recognizes the string “Assault1”.

do I need to declare Assault1 as something first before I use it in the if statement? it’s really just a filter so that only the unit with the variable  name Assault1 will access the Assault.sqf script.

Share this post


Link to post
Share on other sites

I don't know if "Assault1" is a workable class (not in vanilla) but perhaps you created it for specific units. (I doubt)

In this case, in debut console, pointing at the unit, typeOf cursorObject should return "Assault1".

So, in your code, say _unit is defined :

if (typeOf _unit == "Assault1") then [_unit] execVM "Assault.sqf"};  // should work

 

In fact, if I read above, you make confusion between class which are stringed type of unit/vehicle/object  and the variable name. If you named Assault1 your unit (and there can't be 2 units with the same name), you can write:

if (_unit == Assault1) then {...}; // without quote for variable name

 

As wrote above, for a player, respawning in SP means unconsciousness or "entityKilled" MEH management (my post above).

If want want to trigger a sqf at first kind of respawn (unconsciousness), You can test (where you want):
 

[] spawn {
  while {true} do {
    waitUntil {sleep 1; lifeState player == "incapacitated"};
    waitUntil {sleep 0.3; lifeState player != "incapacitated"};
    [player] execVM "Assault.sqf"
  };
};

 

If, for a reason I don't know, player can have different available classes of unit, you can use a condition as my first code here. Sorry, I can't help without a clear view of your settings and scenario.

  • Like 1

Share this post


Link to post
Share on other sites

 

4 hours ago, pierremgi said:

You should say what is your final goal. A variable name is not a class (a class of what?) To do what?

 

38 minutes ago, pierremgi said:

I don't know if "Assault1" is a workable class (not in vanilla) but perhaps you created it for specific units. (I doubt)



The OP is using the word "class" in the abstract sense, defining an ad-hoc "unit class" entirely through SQF and then calling the appropriate "methods" based on that.

 

I wrote an SQF library to do this a few years ago but it's showing its age because SQF didn't have hashmaps back then.  I use the technique in all my scripts, though.

Sorry I don't have just the class code as an up-to-date release somewhere and it's probably a lot more complicated than this particular scenario, anyway.

  • Like 1

Share this post


Link to post
Share on other sites

Hashmap is a good idea... for a lot of data. You need to use keys and get command, but I'm sure you know that. If you need more help, share what you are doing exactly in editor, then the code for respawn. Have fun!

Share this post


Link to post
Share on other sites

I had to open 3den Enhanced but the respawn returns _this which refers to the unit (Variable Name given in editor) that died. The name remains the same throughout, no need to rename the unit or get the name in any special manner, it's always _this.

 

So forget UnitClass.sqf and just type on the respawn code field:

if (_this isEqualTo Assault1) then{
  //code
};

That's it!

If your code is to execVM “Assault.sqf” you can run:

//code
_this execVM "Assault.sqf";

In Assault.sqf:

params [_unit];

//code
private _pweapon = primaryWeapon _unit;
hint str _pweapon;

PierreMGI's solutions are also valid if you don't want to use 3Den Enhanced respawn method.

Thanks for chiming in @pierremgi and @dwringer!

 

Spoiler

Did I mention I hate respawn?

 

Edited by RCA3
  • Thanks 1

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

×