Results 1 to 7 of 7

Thread: Please correct my script so I may learn

Hybrid View

  1. #1

    Please correct my script so I may learn (Airdrop)

    Hi, I'm new to advanced scripting usually sticking to simple statements in trigger on act sections. I like to use placed units as opposed to createvehicle for realism. IN this case a C-130 on standby for players call for air drop. It turns engines on, gets its waypoints (the players position) and than when it is within 30 meters of player it drops its cargo. Eventually id like to get the script to the point where based on the radio trigger called a different script is called within the script. A goto "Ammo1" goto "ammo2" scenario but I am nowhere close to that level yet. So here is my script, not working at the moment. Please look at it and let me know what im doing right and wrong. This is the best way for me to learn. Correction. Thank you in advance to anyone who takes the time.

    start = this select 0;
    end = this select 1;

    if (fog < 5) then {player sidechat "Echo 1-1, aerial resupply is inbound! Ensure DZ is clear of enemy forces.";select 0} else {player sidechat "Weather is Echo 1-1 aerial ressupply is a nogo.";select 1};


    start = sleep 8;
    _distance = drop distance player;

    drop setfuel 1;
    way1 = (group drop) addWaypoint [position player, 0];
    way1 setWaypointType "SAD";
    way1 setWaypointBehaviour "COMBAT";
    way1 setWaypointCombatMode "RED";
    way1 setWaypointSpeed "NORMAL";
    way2 = (group pilot) addWaypoint [getMarkerPos "HELI", 0];
    way2 setWaypointType "GETOUT";
    way2 setWaypointBehaviour "AWARE";
    way2 setWaypointCombatMode "YELLOW";
    way2 setWaypointSpeed "NORMAL";
    way3 = (group pilot) addWaypoint [getMarkerPos "HOLD",0];
    way3 setWaypointType "CYCLE";
    way3 setWaypointBehaviour "AWARE";
    way3 setWaypointCombatMode "YELLOW";
    way3 setWaypointSpeed "NORMAL";

    if (_distance < 30) then {_para = "ParachuteMediumWest_EP1" createVehicle [0,0,0];
    _para (getpos drop select 2) - 20];
    _ammo1 = "USOrdnanceBox" createVehicle _pos;
    _ammo1 attachTo [_para, [0,0,-1.6]];
    sleep 1.0;
    WaitUntil{(getpos _ammo1 select 2) < 0.01};
    detach ammo1;


    end = exit;
    Last edited by CombatComm; Apr 5 2012 at 05:41.

  2. #2
    Master Gunnery Sergeant Rydygier's Avatar
    Join Date
    Aug 22 2011
    Location
    Poland, Pomerania
    Posts
    1,067
    Still there are problems: not defined _pos variable and incomprehensible to me usage of "start" and "end" global variables

    PHP Code:
    start _this select 0;//why this variable "start" is global (without _))? Will be used outside this script? 
    end _this select 1;//lack of "_"

    if (fog 5then //maximum fog is 1, as far, as I know maybe you want 0.5 here?
        
    {
        
    player sidechat "Echo 1-1, aerial resupply is inbound! Ensure DZ is clear of enemy forces."
        

    else 
        {
        
    player sidechat "Weather is Echo 1-1 aerial ressupply is a nogo."
        
    };//deleted "selects". Don't know, why they was here, but select is not used that way


    start sleep 8;//What this should do? 8- second pause? then only "sleep 8;" should be here. To what refer "start" and end "variables"? (Try rather to name yours global variables in more distinctive, unique way eg CC_Start instead of Start, cause some other script or addons may to use global variable of same name when this name is too common)
    _distance CC_drop distance player;//"drop" is name reserved as some particle effect command, so change was required; added by me below "waitUntil" loop makes this line redundant - may be deleted

    CC_drop setfuel 1;
    _way1 = (group CC_dropaddWaypoint [position player0];
    _way1 setWaypointType "SAD";
    _way1 setWaypointBehaviour "COMBAT";
    _way1 setWaypointCombatMode "RED";
    _way1 setWaypointSpeed "NORMAL";//such waypoint (SAD&COMBAT&RED) will make CC_drop vehicle behavior very "militant", so its behavior will be hardest to control and to predict. This is, what you want? I think, better eg MOVE&SAFE&GREEN or something like that; Assumed, that way1 is not used by other scripts, so may be local, so added "_"

    (group CC_dropsetCurrentWaypoint _way1//possibly redundant, but will do not harm

    _way2 = (group CC_pilotaddWaypoint [getMarkerPos "HELI"0];
    _way2 setWaypointType "GETOUT";
    _way2 setWaypointBehaviour "AWARE";
    _way2 setWaypointCombatMode "YELLOW";
    _way2 setWaypointSpeed "NORMAL";

    _way3 = (group CC_pilotaddWaypoint [getMarkerPos "HOLD",0];
    _way3 setWaypointType "CYCLE";
    _way3 setWaypointBehaviour "AWARE";
    _way3 setWaypointCombatMode "YELLOW";
    _way3 setWaypointSpeed "NORMAL";

    waituntil
        
    {
        
    sleep 0.1;//to make script a little lighter
        
    _distance CC_drop distance player;
        (
    _distance 30)
        };
    //_distance variable was previously defined only once, so was never changed since then, so this waituntil loop is needed for cyclically (10 times per second) refresh of its value and condition check.

    _para "ParachuteMediumWest_EP1" createVehicle [0,0,0];//when _distance < 30, loop is ended and next lines are executed

    _para setpos [(getpos CC_dropselect 0,(getpos CC_dropselect 1,((getpos CC_dropselect 2) - 20];//I'm not sure, but probably this is code, that do, what you want here. Probably some brackets are redundant here, but makes code clearer, at least to me   
    _ammo1 "USOrdnanceBox" createVehicle _pos;// _pos variable not defined, should be earlier line like _pos = getPos something;
    _ammo1 attachTo [_para, [0,0,-1.6]];
    sleep 1.0;

    WaitUntil
        
    {
        
    sleep 0.1;
        ((
    getpos _ammo1select 2) < 0.2
        
    };//sleep added, some bigger height in condition setted, cause sometimes height of object on the ground may be very slightly bigger than 0

    detach _ammo1;//lack of "_"

    end = exit;//what this should do? "exit" is a command, that is ignored in sqf. if this should to end script, just delete this line. Script will end here anyway. 
    Maybe also create bookmark at this page:

    http://community.bistudio.com/wiki/C...Commands_ArmA2

    Is very useful...

    Also, to check, why yours script is not working, try to find yours RPT file and use it often:

    Where is my RPT file

  3. #3
    Master Gunnery Sergeant twirly's Avatar
    Join Date
    Sep 13 2010
    Location
    Gods Own (NZ)
    Posts
    1,302
    You need to understand how to structure your scripts. Your script doesn't make too much sense. For instance here's how you would check the distance between your aircraft and the player.

    You need to loop the script over and over until a specific condition or set of conditions is met. Here's two different ways....

    Code:
    _distance = 9999;
    
    while {_distance > 30} do {
    	
    	//don't use "drop"...it's a reserved keyword
    	_distance = dropveh distance player;
    	 
    	 sleep 0.5;	//check every half second
    	 
     };
    
    do your parachute stuff here....
    or...

    Code:
     waituntil {sleep 0.5; dropveh distance player < 30};
    
    do your parachute stuff here....
    There's lots of other stuff wrong as well. I suggests you search the forums for "airdrop" and read a shitload of other peoples code and it will eventually make more and more sense. There's lots of questions about airdrops already answered.

    The Sticky threads at the top of the Forum has links to a lot of useful stuff as well.

    It's all about searching for your answers.

    "Learn by doing!" - Quoted from a post by Imutep

    OUTERRA - OUTERRA - OUTERRA - OUTERRA - BLOWMIND!

  4. #4
    Staff Sergeant CombatComm's Avatar
    Join Date
    Aug 4 2009
    Location
    Travis AFB, CA
    Posts
    385
    Author of the Thread
    Thank you both for taking the time. Ok so Im sure both of you were confused haha, preatty terrible first attempt. Rydgier, let me explain what I was trying to do with select/goto. I was hoping their was a way to do something like where whether the "then or else" is true than the script skips to a certain block of code, within the same script. Like the goto command I guess?? And than understand the loop system. Which I think I understand a little better from yalls help. The main thing is I wanted to if fog was too heavy the script to exit and the player would be forced to try again later if the fog has cleared up. Thats why I tried to send the script to exit in the "else" statement. I know im probably not making much more sense. I know commands and quite a few statements. I guess my main concern now is, like you said, learning to structure and loop my scripts. I need to be able to effectively and cleanly (not kill me CPU) check for conditions throughout the mission or after certain things happen. And than for more complicated scripts use variables and complicated scripts like attachto. If you all could continue to help me understand the select 0,1,2,3 thing and how or if that is used to select certain blocks of codes based on the output of conditions that would be awesome.

  5. #5
    You'll get the hang of it persistence is key if you're self learning.

    Quote Originally Posted by CombatComm View Post
    ...
    If you all could continue to help me understand the select 0,1,2,3 thing and how or if that is used to select certain blocks of codes based on the output of conditions that would be awesome.
    select stuff... well those must be arrays, selecting elements inside arrays.

    Arrays hold indexed elements:
    The number after a "select" represent the index of the element you want to make reference to. The first element is always "0".
    The expression before a "select" is the array you want to select data from.
    Elements within an array may be of any valid type o data (ie objects, numbers, strings of text, etc...). You can create and mix these types of data in the same array.

    In regards to loops and code structure you may check this.

    I would also suggest to keep this reference always side-by-side during your efforts. If you're looking for something new make a keyword search on that page, there are plenty of small examples there to help you through.

  6. #6
    Master Gunnery Sergeant Rydygier's Avatar
    Join Date
    Aug 22 2011
    Location
    Poland, Pomerania
    Posts
    1,067
    Quote Originally Posted by CombatComm View Post
    Rydgier, let me explain what I was trying to do with select/goto. I was hoping their was a way to do something like where whether the "then or else" is true than the script skips to a certain block of code, within the same script. Like the goto command I guess?? And than understand the loop system. Which I think I understand a little better from yalls help. The main thing is I wanted to if fog was too heavy the script to exit and the player would be forced to try again later if the fog has cleared up. Thats why I tried to send the script to exit in the "else" statement. I know im probably not making much more sense. I know commands and quite a few statements. I guess my main concern now is, like you said, learning to structure and loop my scripts. I need to be able to effectively and cleanly (not kill me CPU) check for conditions throughout the mission or after certain things happen. And than for more complicated scripts use variables and complicated scripts like attachto. If you all could continue to help me understand the select 0,1,2,3 thing and how or if that is used to select certain blocks of codes based on the output of conditions that would be awesome.
    Ah yes, now I understand. You tried to use select for sqs style GOTO loops. I liked this loops too, but this is, I afraid, song of the past, as all sqs syntax (good as introduction into scripting for some people however). There isn't such "GOTO" loops in sqf... Well there is something somewhat similar, but it isn't exactly the same (never used by me):

    ScopeName
    breakTo
    breakOut

    still there are other, usually better methods instead to do same thing.

    (inside spoiler more detailed info about scopes and _this select usage, please to correct me if anyone knows something, that I do not know)

    Spoiler:


    So, my example of yours code now will look like this:

    PHP Code:

    if (fog >= 0.5exitwith 
        
    {
        
    player sidechat "Weather is Echo 1-1 aerial ressupply is a nogo."
        
    }; //this makes, that script will exit main scope (script itself) with such message when fog is 50% or more 

    player sidechat "Echo 1-1, aerial resupply is inbound! Ensure DZ is clear of enemy forces."// this message will appear and next lines will be executed only, if fog will be < 0.5, so script will not exit earlier. 

    sleep 8;

    CC_drop setfuel 1;
    _way1 = (group CC_dropaddWaypoint [position player0];
    _way1 setWaypointType "MOVE";
    _way1 setWaypointBehaviour "CARELESS";
    _way1 setWaypointCombatMode "GREEN";
    _way1 setWaypointSpeed "NORMAL";//changed to MOVE&CARELESS&GREEN, so plane named "CC_drop"  shouldn't to engage in any combat or, hopefully, any other interacion or action beacuse of noticed enemy presence, so should to go, where is needed regardless of situation

    (group CC_dropsetCurrentWaypoint _way1//possibly redundant, but will do not harm

    _way2 = (group CC_pilotaddWaypoint [getMarkerPos "HELI"0];
    _way2 setWaypointType "GETOUT";
    _way2 setWaypointBehaviour "AWARE";
    _way2 setWaypointCombatMode "YELLOW";
    _way2 setWaypointSpeed "NORMAL";

    _way3 = (group CC_pilotaddWaypoint [getMarkerPos "HOLD",0];
    _way3 setWaypointType "CYCLE";
    _way3 setWaypointBehaviour "AWARE";
    _way3 setWaypointCombatMode "YELLOW";
    _way3 setWaypointSpeed "NORMAL";

    WaitUntil
        
    {
        
    sleep 0.1;
        
    _distance CC_drop distance player;
        (
    _distance 30)
        };

    _para "ParachuteMediumWest_EP1" createVehicle [0,0,0];

    _para setpos [(getPos CC_dropselect 0,(getPos CC_dropselect 1,((getPos CC_dropselect 2) - 20];   
    _ammo1 "USOrdnanceBox" createVehicle (getPos _para);//my proposition instead of undefined _pos. 
    _ammo1 attachTo [_para, [0,0,-1.6]];
    sleep 1.0;

    WaitUntil
        
    {
        
    sleep 0.1;
        ((
    getpos _ammo1select 2) < 0.2
        
    };

    detach _ammo1
    Last edited by Rydygier; Apr 6 2012 at 11:13.

  7. #7
    Master Gunnery Sergeant twirly's Avatar
    Join Date
    Sep 13 2010
    Location
    Gods Own (NZ)
    Posts
    1,302
    Some useful links for you....

    http://www.armaholic.com/page.php?id=9220

    and most important.... Mr. Murray's Editing Guide.

    http://www.armaholic.com/page.php?id=4847

    With Mr Murray's Editing Guide there are a lot of .sqs examples. This is the old way of writing code.... but the guide still applies big time!

    Don't use .sqs... use .sqf. It's much quicker and you can do more.

    EDIT: ...also... when posting in here don't post your question like one big block. It's too hard to read.... many people will simply skip it! Use short paragraphs and separate them with empty lines.
    Last edited by twirly; Apr 6 2012 at 03:45. Reason: Added stuff

Similar Threads

  1. addWeapon script (adds correct magazines automatically)
    By Celery in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 15
    Last Post: Oct 27 2011, 23:25
  2. Where do all of you learn how to script?
    By tlwhite0311 in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 23
    Last Post: Mar 3 2011, 00:18
  3. correct script wording to unlock several vehicles with one trigger
    By keimosabe in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 2
    Last Post: Feb 3 2010, 19:38
  4. Correct and error free script of creating thousand enemies ?
    By Maltti in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 10
    Last Post: Oct 5 2009, 18:37
  5. Learn about Posting!
    By 6thStorm in forum OFFTOPIC
    Replies: 5
    Last Post: Sep 8 2007, 00:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •