Welcome to Tactical Gamer

+ Reply to Thread
Page 2 of 16 FirstFirst 123456789101112 ... LastLast
Results 16 to 30 of 237
Discussion: ArmA - Development / ArmA - Mission Development - The Scripting How-To Thread - Originally Posted by DLBlue I think I read somewhere that the script gets compiled each
  1. #16


    Join Date
    Jun 2009
    Location
    Orlando, FL
    Posts
    68

    Re: The Scripting How-To Thread

    Quote Originally Posted by DLBlue View Post
    I think I read somewhere that the script gets compiled each time its called so theoretically you wouldn't even have to repreview the mission to see a change in the script but I always do it anyways (preview it again).
    Alright, thanks. I saw a short tutorial on some scripting somewhere that said "then restart ArmA2" and I was just like, that can't be right...

  2.  
  3. #17

    AdeptAbyss's Avatar

    Join Date
    Jul 2007
    Location
    Belfast, Northern Ireland, United Kingdom
    Posts
    1,620
    Blog Entries
    2

    Re: The Scripting How-To Thread

    I got a question

    Where do I start :P

    Looking to get into editing, have made a few silly missions where AI run at each other but want to start making some multiplayer maps, where should I start, what should I be reading etc.

    My name: Adept a skilled or proficient person Abyss a deep, immeasurable space, gulf, or cavity
    So I'm a very skilled deep hole :D

  4.  
  5. #18

    Fincuan's Avatar

    Join Date
    Jan 2009
    Location
    Helsinki, Finland
    Posts
    772

    Re: The Scripting How-To Thread

    For starters:
    • Mr. Murray's editing guide - Made for Arma1, but applies pretty well to Arma2 as well. Good guide for the basics.
    • BIS Wiki - good source for pretty much everyting
    • OFPEC - likewise
    • Other peoples missions - to see how stuff is done
    • BIS forums - A zoolike atmosphere, but sometimes you can catch something useful too.

    I don't have links for all of those right now, but you'll find them easily with google.

  6.  

     
  7. #19

    AdeptAbyss's Avatar

    Join Date
    Jul 2007
    Location
    Belfast, Northern Ireland, United Kingdom
    Posts
    1,620
    Blog Entries
    2

    Re: The Scripting How-To Thread

    ok thanks

    My name: Adept a skilled or proficient person Abyss a deep, immeasurable space, gulf, or cavity
    So I'm a very skilled deep hole :D

  8.  
  9. #20

    Sc[ + ]pe's Avatar

    Join Date
    Aug 2007
    Location
    Vancouver, Canada
    Posts
    847

    Re: The Scripting How-To Thread

    You can make sure your script is working while remaining in-game, assuming that the script isn't called on init. It's recompiled each time it's called.

  10.  
  11. #21


    Join Date
    Jun 2007
    Posts
    351

    Re: The Scripting How-To Thread

    Attack dog scripts. Nothing too fancy but it gets the job done,

    Add this to your dog (note you should also joinSilent him to a group):
    Code:
    this addAction ["Sniff for tracks", "sniffTracks.sqf"]; this addAction ["Attack", "dogAttack.sqf", [], 0, false, false];
    Then you need these scripts:

    sniffTracks.sqf
    Code:
    _gen = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    CurrentSniffer = _gen;
    
    _trg = createTrigger["EmptyDetector",getPos _gen]; 
    _trg setTriggerArea[150,150,0,false];
    _trg setTriggerActivation["ANY","PRESENT",true];
    _trg setTriggerStatements["this", "null = [CurrentSniffer, thisList] execVM 'decipherTracks.sqf';", ""]; 
    
    _gen removeAction _id;
    
    sleep 60;
    
    _gen addAction ["Sniff for tracks", "sniffTracks.sqf"];
    if (player == _gen) then
    {
          hint "You can sniff for tracks again.";
    };
    decipherTracks.sqf
    Code:
    _dog = _this select 0;
    _thisList = _this select 1;
    
    
    if (player == _dog) then
    {;
    	_hintText = "Dog Tracks\n";
    	_dogPos = getPos _dog;
    	{
    		if (_x != _dog) then 
    		{
    			_Distance = (getPos _x) distance _dogPos;
    			_xDiff = (getPos _x select 0) - (_dogPos select 0);
    			_yDiff = (getPos _x select 1) - (_dogPos select 1);
    
    			_angle = atan((abs _xDiff) / (abs _yDiff));
    			_xNeg = _xDiff < 0;
    			_yNeg = _yDiff < 0;
    
    			if (_xNeg and _yNeg) then
    			{
    				_angle = 180 + _angle;
    			}
    			else
    			{
    				if (_xNeg and !(_yNeg)) then
    				{
    					_angle = 360 - _angle;
    				}
    				else
    				{
    					if (_yNeg) then
    					{
    						_angle = 180 - _angle;
    					}
    					else
    					{
    						_angle = _angle;
    					};
    				};
    			};
    
    			_Cardinal = "NW";
    			if (_angle >= 340 or _angle < 20) then { _cardinal = "N"; };
    			if (_angle >= 20 and _angle < 70) then { _cardinal = "NE"; };
    			if (_angle >= 70 and _angle < 110) then { _cardinal = "E"; };
    			if (_angle >= 110 and _angle < 160) then { _cardinal = "SE"; };
    			if (_angle >= 160 and _angle < 200) then { _cardinal = "S"; };
    			if (_angle >= 200 and _angle < 250) then { _cardinal = "SW"; };
    			if (_angle >= 250 and _angle < 290) then { _cardinal = "W"; };
    
    			_roughDistance = "Far";
    			if (_Distance < 100) then { _roughDistance = "Medium"; };
    			if (_Distance < 50) then { _roughDistance = "Close"; };
    
    			_side = "Good";
    			if (side _x == resistance) then { _side = "Bad"; };
    		
    			_hintText = format ["%1\n%2 - %3 %4 %5", _hintText, _side, _roughDistance, _cardinal];
    		};
    		
    	} foreach _thisList;		
    	hint _hintText;
    };
    dogAttack.sqf
    Code:
    _gen = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    _trg = createTrigger["EmptyDetector",getPos _gen]; 
    _trg setTriggerArea[5,5,0,false];
    _trg setTriggerActivation["GUER","PRESENT",true];
    _trg setTriggerStatements["this", "null = [thisList] execVM 'dogHit.sqf';", ""]; 
    
    _trg = createTrigger["EmptyDetector",getPos _gen]; 
    _trg setTriggerArea[5,5,0,false];
    _trg setTriggerActivation["CIV","PRESENT",true];
    _trg setTriggerStatements["this", "null = [thisList] execVM 'dogHit.sqf';", ""];
    dogHit.sqf
    Code:
    _thisList = _this select 0;
    
    if (isServer) then
    {
    
    {
    	if (typeOf _x != "Pastor") then
    	{
    		_toHit = round(random 5);
    		if (_toHit == 0) then {_x setHit ["legs", 1];};
      		if (_toHit == 1) then {_x setHit ["arms", 1];};
      		if (_toHit == 2) then {_x setHit ["head", 1];};
      		if (_toHit == 3) then {_x setHit ["body", 1];};
      		if (_toHit == 4) then {_x setHit ["legs", 1];};
      		if (_toHit == 5) then {_x setHit ["legs", 1];};
    	};
    } foreach _thisList;
    
    };
    ---Bellicosity---


  12.  

     
  13. #22

    Zantheus's Avatar

    Join Date
    Feb 2009
    Location
    Toronto, Ontario
    Age
    28
    Posts
    417

    Re: The Scripting How-To Thread

    Quote Originally Posted by Sc[ + ]pe View Post
    Zantheus, your method doesn't work because _enterer_name returns a class value, not a character-specific name. In fact, that's exactly what I tried when I first modified this code!!
    OK I was just taking a stab at it....Like I said I am by NO MEANS a scripter and tbh have never attemped to make a mission even though I wish I could cuz I have some killer ideas

  14.  
  15. #23

    Inkompetent's Avatar

    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    848

    Re: The Scripting How-To Thread

    Quote Originally Posted by DLBlue View Post
    I think I read somewhere that the script gets compiled each time its called so theoretically you wouldn't even have to repreview the mission to see a change in the script but I always do it anyways (preview it again).
    That's only true for addons. Game resources like models, textures, sounds and config-files are loaded into memory at game launch.

    Everything else is recompiled when executed or preprocessed (compiling without executing). For some things (anything that has to do with init.sqf) this means you'll have to Preview again.




  16.  
  17. #24

    nthamma's Avatar

    Join Date
    Jul 2008
    Location
    Houston, Tx
    Age
    23
    Posts
    338

    Re: The Scripting How-To Thread

    I noticed that every time I put in " if (isServer) then {some code};", it does not execute the code on any other machines other than mine. I put the isServer as a condition to execute a createVehicle command and it only created that object on my end but not on the other machine so that person that was on my local server could not see the object that I created. But when I removed isServer, it executed just fine with both machines seeing the object. My question is, I've seen many scripts that use isServer but why use that if it will only execute on the machine that is the server? So if a mission was hosted on a dedicated server, the object that a machine is trying to create would not show up because it will only be executed on the machine that the server is being run on, is that correct? I'm totally confused.


    IN GAME ARMA: |TG-Irr| Lq.Snake


  18.  

     
  19. #25

    dagi's Avatar

    Join Date
    Jun 2009
    Posts
    18

    Re: The Scripting How-To Thread

    isServer is only true if it's the host or [isDedicated] server. So if you want something only to execute on the server, you would use isServer. If you want someone to execute on all machines, then you would not use the isServer statement.

    Xeno wrote this:

    i_am_a_server = false;
    i_am_a_client = false;
    player_initialized = false;
    if (isServer) then {
    i_am_a_server = true;
    if (!isDedicated) then {
    // either we are in SP/editor or in a hosted environment
    i_am_a_client = true;
    [] spawn {
    waitUntil {!isNull player};
    player_initialized = true;
    };
    };
    } else {
    // I'm a client but the player object may not be initialized yet
    i_am_a_client = true;
    [] spawn {
    waitUntil {!isNull player};
    player_initialized = true;
    };
    };

  20.  
  21. #26

    nthamma's Avatar

    Join Date
    Jul 2008
    Location
    Houston, Tx
    Age
    23
    Posts
    338

    Re: The Scripting How-To Thread

    I just tried to host my own dedicated server with one player connected. I put isServer as a condition to execute a createVehicle command which will create an object on the map if the player triggers it by selecting an action in his action menu. However, the object did not show up on his end. Here is what I have:

    Code:
    // init.sqf
    
    if (isServer) then
    {
    endDeployableSand = 0;
    publicVariable "endDeployableSand";
    };
    Code:
    // init_action.sqf
    // this is in the init field of the unit: null = [this, MTVR1] execVM "init_action.sqf"
    // Where MTVR1 is the name of the truck
    
    _target = _this select 0;
    _vehicle = _this select 1;
    _endAction = 0;
    
    while {alive _target} do
    {
    if (((_target distance _vehicle) < 20 && _endAction == 0)) then
    {
    	deploySand1 = _target addAction ["Deploy Sandbag","deploySand.sqf"];
    	_endAction = 1;
    };
    if (((_target distance _vehicle) > 20 && _endAction == 1)) then
    {
    	_target removeAction deploySand1;
    	_endAction = 0;
    };
    };
    Code:
    // deploySand.sqf
    
    _target = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    _directionA = getDir _caller;
    _TARGETY = getPos _caller select 2;
    _DistMagnitude = 1;
    _deploySandZ = _DistMagnitude*cos(_directionA);
    _deploySandX = _DistMagnitude*sin(_directionA);
    
    if (endDeployableSand <= 5) then
    {
    	_caller playMove "AinvPknlMstpSlayWrflDnon_medic";
    	sleep 7;
    	if (isServer) then
    	{
    		SANDBAG = "Land_fort_bagfence_round" createVehicle [(getPos _caller select 0)+_deploySandx, (getPos _caller select 1)+_deploySandZ, _TARGETY];
    		SANDBAG setDir _directionA;
    		endDeployableSand = endDeployableSand + 1;
    	};
    };
    if (endDeployableSand > 5) then
    {
    _caller = "thumbsdown";
    };
    
    if (_caller == "thumbsdown") then
    {
    hint "There Are No More Sandbags In The MTVR";
    };
    Code:
    // retrieveSand.sqf
    // init of truck: this addAction ["Retrieve All Sandbags","retrieveSand.sqf"]
    
    _target = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    _listobjects = nearestobjects [_caller, ["Land_fort_bagfence_round"], 40];
    if (isServer) then
    {
    SANDBAG1 = _listobjects select 0;
    publicVariable "SANDBAG1";
    SANDBAG2 = _listobjects select 1;
    publicVariable "SANDBAG2";
    SANDBAG3 = _listobjects select 2;
    publicVariable "SANDBAG3";
    SANDBAG4 = _listobjects select 3;
    publicVariable "SANDBAG4";
    SANDBAG5 = _listobjects select 4;
    publicVariable "SANDBAG5";
    SANDBAG6 = _listobjects select 5;
    publicVariable "SANDBAG6";
    deleteVehicle SANDBAG1;
    deleteVehicle SANDBAG2;
    deleteVehicle SANDBAG3;
    deleteVehicle SANDBAG4;
    deleteVehicle SANDBAG5;
    deleteVehicle SANDBAG6;
    };
    
    endDeployableSand = 0;


    IN GAME ARMA: |TG-Irr| Lq.Snake


  22.  
  23. #27


    Join Date
    Jun 2007
    Posts
    351

    Re: The Scripting How-To Thread

    init.sqf
    Code:
    if (isServer) then
    {
    	endDeployableSand = 0;
    	publicVariable "endDeployableSand";
    };
    init_action.sqf
    Code:
    _target = _this select 0;
    _vehicle = _this select 1;
    _hasAction = false;
    _deploySand = 0;
    
    if (_target == player) then
    {
    	while {alive _target and alive _vehicle} do
    	{
    		if ((_target distance _vehicle) < 20 and !(_hasAction)) then
    		{	
    			_deploySand = _target addAction ["Deply Sandbag", "deploySand.sqf"];
    			hint "You can now deploy sand";
    			_hasAction = true;
    		};
    	
    		if ((_target distance _vehicle) >= 20 and (_hasAction)) then
    		{
    			hint "You can no longer deploy sand";
    			_target removeAction _deploySand;
    			_hasAction = false;
    		};
    	};
    };
    deploySand.sqf
    Code:
    _target = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    if (endDeployableSand <= 5) then
    {
    	hint "Deploying sand";
    
    	endDeployableSand = endDeployableSand + 1;
    	publicVariable "endDeployableSand";
    
    	_caller playMove "AinvPknlMstpSlayWrflDnon_medic";
    	sleep 7;
    	_directionA = getDir _caller;
    	_TARGETY = getPos _caller select 2;
    	_DistMagnitude = 1;
    	_deploySandZ = _DistMagnitude*cos(_directionA);
    	_deploySandX = _DistMagnitude*sin(_directionA);
    		
    	SANDBAG = "Land_fort_bagfence_round" createVehicle [(getPos _caller select 0)+_deploySandx, (getPos _caller select 1)+_deploySandZ, _TARGETY];
    	SANDBAG setDir _directionA;
    }
    else
    {
    	hint "There are no more sandbags in the MTVR";
    };
    retrieveSand.sqf
    Code:
    _target = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    _listObjects = nearestObjects [_caller, ["Land_fort_bagfence_round"], 40];
    
    endDeployableSand = endDeployableSand - ({_x == _x} count _listObjects);
    publicVariable "endDepolyableSand";
    { deleteVehicle _x } foreach _listObjects;
    ---Bellicosity---


  24.  

     
  25. #28


    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    737

    Re: The Scripting How-To Thread

    Looks familiar hehe.

    Well, I think the general problem you are having is simply that a dedicated server will never be able to run the code to create the sandbag. It is run on an action event (player pressing action in the menu), so, it is already local and only run on that player's machine. No need to worry about tons of sandbags popping up.

  26.  
  27. #29

    Blackdog1's Avatar

    Join Date
    Apr 2008
    Location
    London
    Posts
    2,370

    Re: The Scripting How-To Thread

    I have a fun question... I want a sound to be played from a Vehicle with the driver to be able to actio the sound?

    Any ideas how to do this?

    Ta
    BlackDog1




    "What we do in life... echoes in eternity!"

  28.  
  29. #30

    KoopaTroopa's Avatar

    Join Date
    Nov 2006
    Location
    Clarksville, Tennessee, United States
    Age
    31
    Posts
    2,938

    Re: The Scripting How-To Thread

    This crap is a headache to learn. I have lots of neat mission ideas, but to hell with learning some hieroglyphics to make it happen.
    --------------------------------------------------------------------------------
    Blah blah blah.

  30.  

     

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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


  
 

Back to top