How do I remove all equipment from a unit in SQF? - sqf

Say I have a unit _unit in Arma 3. How do I remove all its equipment so that the only thing remaining is its uniform?
So far, I have been using
removeAllItemsWithMagazines _unit;
{player removeWeaponGlobal _x} forEach weapons _unit;
removeBackpackGlobal _unit;
removeVest _unit;
but I am not sure this removes everything.
Notice that everything here includes the map, compass, watch and gps.

Here's the Remove existing items section from Arsenal loadout exports:
removeAllWeapons this;
removeAllItems this;
removeAllAssignedItems this;
removeUniform this;
removeVest this;
removeBackpack this;
removeHeadgear this;
removeGoggles this;
So simply delete the removeUniform this; line.

Related

How to change one object into another object?

This is mostly a question about code design. What you see here is a very condensed version of the original code.
An example of the code is:
player.rest();
This makes the player sleep.
I have other methods such as walk, run, talk etc. which all work great. The one that is a problem is polymorph. It changes the player from a human object to another object. The solution I came up with is this:
class main
{
var human:Human = new Human;
var alien:Alien = new Alien;
var cow:Cow = new Cow;
var player = human;
enterframe loop{
//other code
if (player does something)
player.polymorph = "alien";
switch (player.polymorph)
{
case "alien":
player = alien;
break;
case "cow":
player = cow;
break;
//etc
}
player.update();
}
}
I want something that looks like this:
class main
{
var human:Human = new Human;
var alien:Alien = new Alien;
var player = human;
enterframe loop
{
player.polymorph(alien);
}
}
I know my original solution is the wrong way to go about things as it encourages spaghetti code. How could I do it differently? I don't mind a whole rewrite, but need an example to help push me in the right direction. I hope this makes sense and thanks for the help.
If the second one can work, what would the polymorph function look like?
I thought of making a class called player and changing what that extends, but to my knowledge that can't be done? Plus I would like to change the character to something already in game rather than a new object.
One solution to your problem would be using a single class, in this case, your Player class, and a finite state machine. You'd have a Player class, which can be set to different states, such as HUMAN, ALIEN, COW, etc. When a polymorph event occurs you update the Player's state, perhaps by calling an initState() method, and handle the logic for being a human, alien, cow, accordingly in whatever method updates your player.
Assuming the player has an update() method it could contain the following:
switch (state) {
case ALIEN:
// do alien stuff
case COW:
// do cow stuff
case HUMAN:
// do human stuff
}
Next, instead of handling the various polymorph states in a switch statement, your Player class could have a polyMorph method that takes a state as a parameter:
public function polymorph(newState:Int) {
state = newState;
initState(state); // You could even just call the initState method instead, and completely omit the polymorph method
}
Using a finite state machine here would eliminate the need for numerous objects.

Objects within Objects

I have an object in my Library called Bottle. Bottle is made up of "Glass" and "Cap" instances. There are two more symbols in my library called Cap, and Glass.
When I click on the cap of Bottle, it says that this object is of class Cap, and when I click on the glass, it says it is of type Glass. Each one of these objects has base class flash.display.MovieClip.
However, in my code when I do:
var bottleOnStage:Bottle = new Bottle();
addChild(bottleOnStage);
var newColor:uint = 0x00ff00;
var newColorTransform:ColorTransform = new ColorTransform();
newColorTransform.color = newColor;
bottleOnStage.Glass.transform.colorTransform = newColorTransform;
I get this error:
TypeError: Error #1010: A term is undefined and has no properties. at MethodInfo-1()
Am I accessing the Glass property wrong? Is it because I haven't created an instance of Glass? I am confused on how objects within objects work in Flash.
EDIT
var cap:Cap;
var glass:Glass;
Above is what is in my Bottle.as file. In my Main.as file I have:
var bottleOnStage:Bottle = new Bottle();
bottleOnStage.cap = new Cap();
bottleOnStage.glass = new Glass();
addChild(bottleOnStage);
var newColor:uint = 0x00ff00;
var newColorTransform:ColorTransform = new ColorTransform();
newColorTransform.color = newColor;
bottleOnStage.glass.transform.colorTransform = newColorTransform;
When I run this code, no changes occur to the "glass" portion of the bottle. Why is this? I know that it is this line; I have traced and debugged all of the other lines, and the colors I am tracing are correct, etc. When I add "cap" and "bottle" to "bottleOnStage" using addChild, I get a duplicate of these two symbols, so this is apparently not the way. Basically, how do I modify "cap" and "glass" on stage?
It looks like your are confusing Classes with instances. Instance names cannot have the same name as a Class name (in the same scope).
Glass is your class. If you have variable with the name of "Glass" inside your bottle class, you need to rename it so it isn't ambiguous with your class name Glass.
bottleOnStage.glassInstanceName.transform.colorTransform = newColorTransform;
As a tip, to avoid this situation best practice is always make your instance names begin with a lower case letter, and always make your Class names begin with an upper case letter. (That also helps with code highlighting in most coding applications as well as here in Stack Overflow - notice how your uppercase items are hightlighted?)
As far as your error goes, you likely don't have an actual object in your variable yet.
Doing the following:
var myGlass:Glass;
Doesn't actually make an object (the value is null), it's just defining a placeholder for one. You need to instantiate using the new keyword in order to create an actual object.
var myGlass:Glass = new Glass();
Now you'll have an object in that variable.
EDIT
To address your edit, sounds like your probably want to something like this:
package {
public class Bottle extends Sprite {
public var cap:Cap;
public var glass:Glass;
//this is a constructor function (same name as the class), it gets run when you instantiate with the new keyword. so calling `new Bottle()` will run this method:
public function Bottle():void {
cap = new Cap();
glass = new Glass();
addChild(cap); //you want these to be children of this bottle, not Main
addChild(glass);
}
}
}
This keeps everything encapsulated and adds the cap and glass as children of the bottle. So bottle is a child of main, and cap and glass are children or bottle.
Whats is the name of the Glass attribute in the bottle?
if you have for example:
public class Bottle {
public var glass : Glass;
}
You can access the glass with:
var bottle : Bottle = new Bottle();
bottle.glass = new Glass();
Glass is the class. bottle.glass is the attribute "glass" of the class Bottle.
Hope it helps.

Mootools and object.__proto__

Object.each, Object.keys, ... doesn't work fine when I try to use with an object that is a class attribute, check this example:
var map = {a: 1, b: []}; // simple object
var SomeClass = new Class({'map': map}); // class attribute
var sc = new SomeClass();
With a simple object, everything works ok
console.log(map.hasOwnProperty('a')); // true
console.log(map.hasOwnProperty('b')); // true
console.log(Object.keys(map)); // ['a', 'b']
But with sc.map, does not work with scalar values (int, boolean, string)
console.log(sc.map.hasOwnProperty('a')); // expected: true, returns: false
console.log(sc.map.hasOwnProperty('b')); // expected: true, returns: true
console.log(Object.keys(sc.map)); // expected: ['a', 'b'], returns: [b]
I realize it is beacuse sc.map has a __proto__ property
console.log(map.__proto__); // expected: empty Object
console.log(sc.map.__proto__); // expected: the "map" Object
I think it is a recent issue, because I have a huge bunch of code and some things stopped working because of this. I don't want to change all my code to fix this problem, i guess some patch for mootools is needed.
wow. so source code, https://github.com/mootools/mootools-core/blob/master/Source/Class/Class.js#L85, much merge: https://github.com/mootools/mootools-core/blob/master/Source/Core/Core.js#L348-L369
want derefrence. excellent.
var map = {a: 1, b: []}; // simple object
var SomeClass = new Class({'map': map}); // class attribute
var sc = new SomeClass();
console.log(sc.map.b.length);
map.b.push('doge');
console.log(sc.map.b.length); // 0
console.log(map.b.length); // 1
map.a = 'doge';
console.log(sc.map.a); // 1
in seriousness, not a recent change at all, any non-primitives are being copied in, don't panic. it is a good thing. You probably don't want a prototype for your object that can change because of something it references outside.
now. that being said, it's weird where a ends up from. http://jsfiddle.net/mMURe/2/ - I agree this is not ideal and is somewhat unexpected. filing an issue on GH, though don't hold your breath. if it's a recent change, it will be related to browser changes. Same code breaks in 1.3.2 and mootools 1.4.5 is quite old now and unchanged. The issue I filed on your behalf is here: https://github.com/mootools/mootools-core/issues/2544 - feel free to elaborate and add more usecases of where this is actually useful (I still don't like passing objects into prototypes)
But if you need to have your object have the map object by reference and avoid the merge, you can just put the reference in your constructor method instead:
var map = {a:1},
foo = new Class({
initialize: function(){
this.map = map;
}
});
var bar = new foo();
map.a++;
console.log(bar.map.a); // 2
but if you absolutely must break the norm and know the side effects, then you can.
var map = {a: 1, b: []}; // simple object
var SomeClass = new Class(); // class attribute
// avoid the derefrence rush, go prototypal manually
SomeClass.prototype.map = map;
var instance = new SomeClass,
other = new SomeClass;
console.log(instance.map.a); // 1
map.a++;
console.log(instance.map.a); // 2
// but also:
console.log(other.map.a); // 2
remember, MooTools Class is just constructor creation sugar that takes the pain away from having to do repetitive and non-terse actions. it still is javascript under the hood and you can use classic prototypal patterns on top.
I just encountered this issue as well. To avoid it I used Object.clone(). Object.clone() returns a normal object rather than a class object, so it does not have the __proto__ property, and everything should run fine. In the example you gave above, I would do this:
var scMap = Object.clone(sc.map);
console.log(scMap.hasOwnProperty('a'));
console.log(scMap.hasOwnProperty('b'));
console.log(Object.keys(scMap));
Hope this helps.

Drag and clone MovieClip in AS3

I have a toolbar with some cars on the left of the window, and I want to click on one element and drag it to the board creating a clone of it, but I can't do it.
My app looks like this:
Cars on the left are my desired dragged.
My source code is:
public class Car extends MovieClip
{
// imports...
var newcar:Car;
public function Car(){
addListeners();
}
private function addListeners():void{
this.addEventListener(MouseEvent.MOUSE_DOWN,clone);
}
private function clone(e:MouseEvent):void{
// Clone the object
newcar = new dibujo();
newcar.graphics.copyFrom(this.graphics);
newcar.x = this.x;
this.parent.addChild(newcar);
// Asign new events to recently created mc
newcar.addEventListener(MouseEvent.MOUSE_OVER,dragCar);
newcar.addEventListener(MouseEvent.MOUSE_UP,dropCar);
}
private function dragCar(e:MouseEvent):void{
this.startDrag();
}
private function dropCar(e:MouseEvent):void{
this.stopDrag();
}
}
The red car and the truck use my own basic class called 'Car'.
Thanks in advance! I hope someone can help me.
And what is not working?
Main problem I see is, that you create new car, but you don't add it to the display list. In your clone function, you need something like
this.parent.addChild(newcar);
edit:
So as I said in comments, problem is, tah property graphics is read only, so you can't change it.
If your cars are instaces of classes that extend your Car (if they are not, you can easily make them), you can use this:
replace
newcar = new dibujo(); //I think you menat new Car() here
with
newcar = new e.target.constructor;
this should finally make it work.
You will then encounter problem with dragging - it never stops. But solution is simple, add this line to your stopDrag function:
e.target.removeEventListener(MouseEvent.MOUSE_MOVE, dragCar);

Elements not adding to JList

For some reason, I can't add anything to my JList. The JList is visible but simply shows white - nothing can be selected.
List list;
DefaultListModel listModel;
//...
list = new JList();
list.setBounds(220,20,150,200);
listModel = new DefaultListModel();
listModel.addElement("ONE");
panel.add(list);
Am I missing something?
The JList is not using the listModel.
One way is to initialize the JList by specifying a ListModel to use:
DefaultListModel listModel = ...
JList list = new JList(listModel);
Then, performing changes to the listModel (such as calling addElement) will cause the changes to appear on the JList.
For more information on using JLists, the How to Use Lists lesson from The Java Tutorials is a good source.
You never set the list's model to the ListModel you've constructed.