Jump to content

lappihuan

Member
  • Content Count

    567
  • Joined

  • Last visited

  • Medals

Posts posted by lappihuan


  1. Well i think it's rather your incompetence of giving exact infromation for a lot of people who are trying to help you...

    When your script is not working it's most likely a error in your script and that has nothing to do with BI, so calm down and then people might help you to solve your problem.

    E: I see where your problem could be:

    _enemyairarray = [0,1];
    _enemyairtype = _enemyairarray select (floor (random (count _enemyairarray)));
    

    Count will return "2", so floor random can return 0,1 and 2. But in your script only _enemyairtype 0 and 1 are defined.

    Most likley your script will end after the checks if (_enemyairtype == x) because _enemyairtype is 2.

    better use BIS_fnc_selectRandom to avoid this.

    Now tell me, what has BI to do with this? :j:


  2. Hi Mad_Cheese,

    Nice idea with the dog! Not sure if you solved your problem already, if not probably this will help:

    http://forums.bistudio.com/showthread.php?160330-Scripting-Discussion-%28dev-branch%29&p=2679302&viewfull=1#post2679302

    As far as i understood you're still having problems with setVectorDirAndUp from the dog. Try to use the function rotateAroundOwnAxisX ( or if you want other rotations: rotateAroundOwnAxisY, rotateAroundOwnAxisZ ) to adjust your dog how you want.

    Hope the Roundhouse-bite-ninja-problem is history now ;)

    Enjoy it!


  3. While i was creating a mod, i had some troubles using the setVectorDirAndUp command. Once understood i tought, why can't we do it more userfriendly? I saw in several forums, that i'm not the onlyone who's thinking like this. I asked my brother and showed him the sqf basics. He wrote now 3 diffrent ways to rotate an object. By simply giving the function an object and the rotation angle in degrees around the axis you want. Basically the function just fill in the vector dir and up in the setVectorDirAndUp command. Probably its possible to add it to the BIS functions or even rewrite them in a command. This functions are free to use by anyone (including BI as template for a command or function), as long as you give credit (to "bapedibupa").

    I think they're pretty useful!

    rotateObject

    /*
    Rotate an object around each axis
    By bapedibupa
    
    Parameters: [object, [x,y,z]]
    Returns: nothing
    
    Rotates an object, giving it the specified rotation angle around each axis, in degrees.
    
    The rotation is about the world coordinates. When the object you want to rotate is attached to another object, it rotates relative to this coordinates (it doesent rotates around the axis from the rotating object).
    
    A positive number rotates the object in positive axis rotation. Negative numbers in the other direction.
    Positive axis rotation means when you take your right hand, make a fist and spread out your thumb, make sure that the thumb is heading in positive axis direction: Your other fingers show you now the positive rotation around this axis.
    
    Default value [0,0,0] make the object face straight north.
    If you want to face it straight west so you want it to turn 90° in positive axis rotation around Z. Your array parameters should look like this [0,0,90].
    If you want to face it straight east so you want it to turn 90° in negative axis rotation around Z. Your array parameters should look like this [0,0,-90].
    All axis work in the same way. Sure you can do this with the setDir command, but not in 3D.
    
    You also can combine a rotation around X, Y and Z. But then you need a good visual thinkimg or the trial and error methode ;) Note, that the object rotates first around X, then Y and in the end Z.
    
    This function is useful when you want to place an object on the map or on a attached object in the direction you want. If you use it in combination with attachTo use first the attachTo command an then this function.
    
    If you want to use this function just to look which parameters you should fill in the setVectorDirAndUp command (whenever you use it), just uncomment the hintSilent in the end and you can see the parameters in the game.
    
    Example: [object[45,0,-90]] call rotateObject; // rotates 45° back and 90° right (east).
    */
    
    rotateObject = {
    _object = _this select 0;
    _rotations = _this select 1;
    
    _aroundX = _rotations select 0;
    _aroundY = _rotations select 1;
    _aroundZ = _rotations select 2;
    
    // set default values
    _dirX = 0;
    _dirY = 1;
    _dirZ = 0;
    
    _upX = 0;
    _upY = 0;
    _upZ = 1;
    
    // rotate around X
    if (_aroundX != 0) then {
    	_dirY = cos _aroundX;
    	_dirZ = sin _aroundX;
    
    	_upY = -sin _aroundX;
    	_upZ = cos _aroundX;
    };
    
    // rotate around Y
    if (_aroundY != 0) then {
    	_dirX = _dirZ * sin _aroundY;
    	_dirZ = _dirZ * cos _aroundY;
    
    	_upX = _upZ * sin _aroundY;
    	_upZ = _upZ * cos _aroundY;
    };
    
    // rotate around Z
    if (_aroundZ != 0) then {
    	_dirXTemp = _dirX;
    	_dirX = (_dirY * -sin _aroundZ) + (_dirXTemp* cos _aroundZ);
    	_dirY = (_dirY * cos _aroundZ) + (_dirXTemp * sin _aroundZ);
    
    	_upXTemp = _upX;
    	_upX = (_upY * -sin _aroundZ) + (_upXTemp * cos _aroundZ);
    	_upY = (_upY * cos _aroundZ) + (_upXTemp * sin _aroundZ);
    };
    
    // round
    _dirX = [_dirX,3] call BIS_fnc_cutDecimals;
    _dirY = [_dirY,3] call BIS_fnc_cutDecimals;
    _dirZ = [_dirZ,3] call BIS_fnc_cutDecimals;
    
    _upX = [_upX,3] call BIS_fnc_cutDecimals;
    _upY = [_upY,3] call BIS_fnc_cutDecimals;
    _upZ = [_upZ,3] call BIS_fnc_cutDecimals;
    
    // set vector dir and up
    _dir = [_dirX,_dirY,_dirZ];
    _up = [_upX,_upY,_upZ];
    
    //hintSilent format ["dir: %1 up: %2",_dir,_up];
    
    _object setVectorDirAndUp [_dir,_up];
    };
    

    rotateObjectX

    rotateObjectY

    rotateObjectZ

    /*
    Rotate object in x,y,z
    By bapedibupa
    
    Parameters: [object,angle]
    Returns: nothing
    
    Rotates an object, giving it the specified rotation angle around a choosen axis, in degrees.
    
    The rotation is about the world coordinates. When the object you want to rotate is attached to another object, it rotates relative to this coordinates (it doesent rotates around the axis from the rotating object).
    
    A positive number rotates the object in positive axis rotation. Negative numbers in the other direction.
    Positive axis rotation means when you take your right hand, make a fist and spread out your thumb, make sure that the thumb is heading in positive axis direction: Your other fingers show you now the positive rotation around this axis.
    
    All 3 functions rotate the object relative to its previous direction. You also can combine all 3 functions togheter by calling one funtion after the other. You even can use the same function twice whenever needed.
    
    If you use the functions in combination with attachTo use first the attachTo command an then this functions.
    
    Never Use setDir after one of this funtions, it resets previous direction.
    
    Example:	[object, 45] call rotateObjectX;	// the object turn 45° back
    		[object, -90] call rotateObjectZ;	// the object turn 90° right (east), but still hanging 45°back
    
    
    */
    
    
    rotateObjectX = {
    // find object and rotation angle
    _object = _this select 0;
    _angle = _this select 1;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // split into x,y,z
    _dirX = _dir select 0;
    _dirY = _dir select 1;
    _dirZ = _dir select 2;
    
    _upX = _up select 0;
    _upY = _up select 1;
    _upZ = _up select 2;
    
    // calculate new values
    _dirYTemp = _dirY;
    _dirY = (_dirZ * -sin _angle) + (_dirYTemp * cos _angle);
    _dirZ = (_dirZ * cos _angle) + (_dirYTemp * sin _angle);
    
    _upYTemp = _upY;
    _upY = (_upZ * -sin _angle) + (_upYTemp * cos _angle);
    _upZ = (_upZ * cos _angle) + (_upYTemp * -sin _angle);
    
    // set vetor dir and up
    _object setVectorDirAndUp [[_dirX,_dirY,_dirZ],[_upX,_upY,_upZ]];
    };
    
    
    rotateObjectY = {
    // find object and rotation angle
    _object = _this select 0;
    _angle = _this select 1;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // split into x,y,z
    _dirX = _dir select 0;
    _dirY = _dir select 1;
    _dirZ = _dir select 2;
    
    _upX = _up select 0;
    _upY = _up select 1;
    _upZ = _up select 2;
    
    // calculate new values
    _dirXTemp = _dirX;
    _dirX = (_dirZ * sin _angle) + (_dirXTemp * cos _angle);
    _dirZ = (_dirZ * cos _angle) + (_dirXTemp * -sin _angle);
    
    _upXTemp = _upX;
    _upX = (_upZ * sin _angle) + (_upXTemp * cos _angle);
    _upZ = (_upZ * cos _angle) + (_upXTemp * -sin _angle);
    
    // set vetor dir and up
    _object setVectorDirAndUp [[_dirX,_dirY,_dirZ],[_upX,_upY,_upZ]];
    };
    
    
    rotateObjectZ = {
    // find object and rotation angle
    _object = _this select 0;
    _angle = _this select 1;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // split into x,y,z
    _dirX = _dir select 0;
    _dirY = _dir select 1;
    _dirZ = _dir select 2;
    
    _upX = _up select 0;
    _upY = _up select 1;
    _upZ = _up select 2;
    
    // calculate new values
    _dirXTemp = _dirX;
    _dirX = (_dirY * -sin _angle) + (_dirXTemp * cos _angle);
    _dirY = (_dirY * cos _angle) + (_dirXTemp * sin _angle);
    
    _upXTemp = _upX;
    _upX = (_upY * -sin _angle) + (_upXTemp * cos _angle);
    _upY = (_upY * cos _angle) + (_upXTemp * sin _angle);
    
    // set vetor dir and up
    _object setVectorDirAndUp [[_dirX,_dirY,_dirZ],[_upX,_upY,_upZ]];
    };
    
    
    /*
    // Problem with rotateObject is, you can't just type in x as axis. for now is x=1,y=2,z=3. you can type in "x" but then you need to change the cases to "x", "y", "z" ....
    rotateObject = {
    // find object, axis and rotation angle
    _object = _this select 0;
    _axis = _this select 1;
    _angle = _this select 2;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // split into x,y,z
    _dirX = _dir select 0;
    _dirY = _dir select 1;
    _dirZ = _dir select 2;
    
    _upX = _up select 0;
    _upY = _up select 1;
    _upZ = _up select 2;
    
    // set temporary variables
    _dirXTemp = _dirX;
    _dirYTemp = _dirY;
    
    _upXTemp = _upX;
    _upYTemp = _upY;
    
    // calculate new values
    switch (_axis) do {
        case 1: {
       		_dirY = (_dirZ * -sin _angle) + (_dirYTemp * cos _angle);
    		_dirZ = (_dirZ * cos _angle) + (_dirYTemp * sin _angle);
    
    		_upY = (_upZ * -sin _angle) + (_upYTemp * cos _angle);
    		_upZ = (_upZ * cos _angle) + (_upYTemp * -sin _angle);
        };
        case 2: {
    		_dirX = (_dirZ * sin _angle) + (_dirXTemp * cos _angle);
    		_dirZ = (_dirZ * cos _angle) + (_dirXTemp * -sin _angle);
    
    		_upX = (_upZ * sin _angle) + (_upXTemp * cos _angle);
    		_upZ = (_upZ * cos _angle) + (_upXTemp * -sin _angle);
        };
        case 3: {
    		_dirX = (_dirY * -sin _angle) + (_dirXTemp * cos _angle);
    		_dirY = (_dirY * cos _angle) + (_dirXTemp * sin _angle);
    
    		_upX = (_upY * -sin _angle) + (_upXTemp * cos _angle);
    		_upY = (_upY * cos _angle) + (_upXTemp * sin _angle);
        };
    
        default {
         	hintSilent "this is not a axis";
        };
    };
    
    
    
    // set vetor dir and up
    _object setVectorDirAndUp [[_dirX,_dirY,_dirZ],[_upX,_upY,_upZ]];
    };
    */
    

    rotateAroundOwnAxisX

    rotateAroundOwnAxisY

    rotateAroundOwnAxisZ

    /*
    Rotate object around own x,y,z axis
    By bapedibupa
    
    Parameters: [object,angle]
    Returns: nothing
    
    Rotates an object, giving it the specified rotation angle around his own axis, in degrees.
    
    The rotation is about the coordinates from the object.
    
    A positive number rotates the object in positive axis rotation. Negative numbers in the other direction.
    Positive axis rotation means when you take your right hand, make a fist and spread out your thumb, make sure that the thumb is heading in positive axis direction: Your other fingers show you now the positive rotation around this axis.
    
    All 3 functions rotate the object relative to its previous direction. You also can combine all 3 functions togheter by calling one funtion after the other. You even can use the same function twice whenever needed.
    
    If you use the functions in combination with attachTo use first the attachTo command an then this functions.
    
    Never Use setDir after one of this funtions, it resets previous direction.
    
    Example:	[object, 45] call rotateAroundOwnAxisX;		// the object turn 45° back
    		[object, -90] call rotateAroundOwnAxisZ;	// the object turn 90° clockwise, but still looking north and 45° back
    
    
    */
    
    rotateAroundOwnAxisX = {
    // find object and rotation angle
    _object = _this select 0;
    _angle = _this select 1;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // find x-axis
    _axis = [_dir,_up] call BIS_fnc_crossProduct;
    
    // split into x,y,z
    _dirXTemp = _dir select 0;
    _dirYTemp = _dir select 1;
    _dirZTemp = _dir select 2;
    
    _upXTemp = _up select 0;
    _upYTemp = _up select 1;
    _upZTemp = _up select 2;
    
    _axisX = _axis select 0;
    _axisY = _axis select 1;
    _axisZ = _axis select 2;
    
    // set cos and sin
    _cos = cos _angle;
    _sin = sin _angle;
    
    // calculate new vector dir
    _dirX = _dirXTemp*(_axisX*_axisX*(1-_cos)+_cos) + _dirYTemp*(_axisX*_axisY*(1-_cos)-_axisZ*_sin) + _dirZTemp*(_axisX*_axisZ*(1-_cos)+_axisY*_sin);
    _dirY = _dirXTemp*(_axisY*_axisX*(1-_cos)+_axisZ*_sin) + _dirYTemp*(_axisY*_axisY*(1-_cos)+_cos) + _dirZTemp*(_axisY*_axisZ*(1-_cos)-_axisX*_sin);
    _dirZ = _dirXTemp*(_axisY*_axisX*(1-_cos)-_axisY*_sin) + _dirYTemp*(_axisZ*_axisY*(1-_cos)+_axisX*_sin) + _dirZTemp*(_axisZ*_axisZ*(1-_cos)+_cos);
    
    // calculate new vector up
    _upX = _upXTemp*(_axisX*_axisX*(1-_cos)+_cos) + _upYTemp*(_axisX*_axisY*(1-_cos)-_axisZ*_sin) + _upZTemp*(_axisX*_axisZ*(1-_cos)+_axisY*_sin);
    _upY = _upXTemp*(_axisY*_axisX*(1-_cos)+_axisZ*_sin) + _upYTemp*(_axisY*_axisY*(1-_cos)+_cos) + _upZTemp*(_axisY*_axisZ*(1-_cos)-_axisX*_sin);
    _upZ = _upXTemp*(_axisZ*_axisX*(1-_cos)-_axisY*_sin) + _upYTemp*(_axisZ*_axisY*(1-_cos)+_axisX*_sin) + _upZTemp*(_axisZ*_axisZ*(1-_cos)+_cos);
    
    // set vetor dir and up
    _object setVectorDirAndUp [[_dirX,_dirY,_dirZ],[_upX,_upY,_upZ]];
    };
    
    rotateAroundOwnAxisY = {
    // find object and rotation angle
    _object = _this select 0;
    _angle = _this select 1;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // split into x,y,z
    _dirX = _dir select 0;
    _dirY = _dir select 1;
    _dirZ = _dir select 2;
    
    _upXTemp = _up select 0;
    _upYTemp = _up select 1;
    _upZTemp = _up select 2;
    
    // set cos and sin
    _cos = cos _angle;
    _sin = sin _angle;
    
    
    // calculate new vector up
    _upX = _upXTemp*(_dirX*_dirX*(1-_cos)+_cos) + _upYTemp*(_dirX*_dirY*(1-_cos)-_dirZ*_sin) + _upZTemp*(_dirX*_dirZ*(1-_cos)+_dirY*_sin);
    _upY = _upXTemp*(_dirY*_dirX*(1-_cos)+_dirZ*_sin) + _upYTemp*(_dirY*_dirY*(1-_cos)+_cos) + _upZTemp*(_dirY*_dirZ*(1-_cos)-_dirX*_sin);
    _upZ = _upXTemp*(_dirZ*_dirX*(1-_cos)-_dirY*_sin) + _upYTemp*(_dirZ*_dirY*(1-_cos)+_dirX*_sin) + _upZTemp*(_dirZ*_dirZ*(1-_cos)+_cos);
    
    // set vetor dir and up
    _object setVectorDirAndUp [_dir,[_upX,_upY,_upZ]];
    };
    
    rotateAroundOwnAxisZ = {
    // find object and rotation angle
    _object = _this select 0;
    _angle = _this select 1;
    
    // get current vector dir and up
    _dir = vectorDir _object;
    _up = vectorUp _object;
    
    // split into x,y,z
    _dirXTemp = _dir select 0;
    _dirYTemp = _dir select 1;
    _dirZTemp = _dir select 2;
    
    _upX = _up select 0;
    _upY = _up select 1;
    _upZ = _up select 2;
    
    // set cos and sin
    _cos = cos _angle;
    _sin = sin _angle;
    
    
    // calculate new vector dir
    _dirX = _dirXTemp*(_upX*_upX*(1-_cos)+_cos) + _dirYTemp*(_upX*_upY*(1-_cos)-_upZ*_sin) + _dirZTemp*(_upX*_upZ*(1-_cos)+_upY*_sin);
    _dirY = _dirXTemp*(_upY*_upX*(1-_cos)+_upZ*_sin) + _dirYTemp*(_upY*_upY*(1-_cos)+_cos) + _dirZTemp*(_upY*_upZ*(1-_cos)-_upX*_sin);
    _dirZ = _dirXTemp*(_upZ*_upX*(1-_cos)-_upY*_sin) + _dirYTemp*(_upZ*_upY*(1-_cos)+_upX*_sin) + _dirZTemp*(_upZ*_upZ*(1-_cos)+_cos);
    
    // set vetor dir and up
    _object setVectorDirAndUp [[_dirX,_dirY,_dirZ],_up];
    };
    

    best regards

    Lappihuan, bapedibupa

    • Like 2
    • Thanks 1

  4. I'm working on a Mod that i would like to make it execute in every mission that gets startet as long as the Addon is activated.

    I added all Functions to the Function Library. Now i wonder how i can call my "myModInitFunction" on every mission start?

    Is there a missionStart EH in the EventHandler Class that i need to add my function or where do i need to call it?

    best Regards

    Lappihuan

    Edit:

    Found the solution (thx to kju) here. preInit or postInit would be the parameters to use.


  5. Could you maybe add a autocompletition like emmet for sqf?

    "myTag.fnc.addSomeStuff" + Tab

    will result in:

    myTag_fnc_addSomeStuff =
    {
    private*<cursor will be here>
    
    };
    

    then you can add after the private* your number of private vars like 7 (private*7)

    will resulte in:

    myTag_fnc_addSomeStuff =
    {
    private["<cursor here>","","","","","",""]
    
    };
    

    same for other things like a switch case use like swich.myVar*5 + Tab

    will result in:

    switch (myVar) do {
    case <cursor here>: { }; 
    case 2: { }; 
    case 3: { };
    case 4: { };
    case 5: { };
    default { }; 
    };
    

    such things would be extremly awsome :cool:

×