-
07-16-2009, 01:08 PM #16
- Join Date
- Jun 2009
- Location
- Orlando, FL
- Posts
- 68
-
07-16-2009, 04:16 PM #17
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

-
07-16-2009, 04:38 PM #18
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.
-
07-16-2009, 05:16 PM #19
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

-
07-16-2009, 05:43 PM #20
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.
-
07-16-2009, 07:59 PM #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):
Then you need these scripts:Code:this addAction ["Sniff for tracks", "sniffTracks.sqf"]; this addAction ["Attack", "dogAttack.sqf", [], 0, false, false];
sniffTracks.sqf
decipherTracks.sqfCode:_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."; };
dogAttack.sqfCode:_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; };
dogHit.sqfCode:_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';", ""];
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---

-
07-16-2009, 08:36 PM #22
-
07-16-2009, 10:27 PM #23
Re: The Scripting How-To Thread
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.




-
07-17-2009, 12:58 PM #24
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
-
07-17-2009, 01:48 PM #25
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;
};
};
-
07-17-2009, 02:16 PM #26
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
-
07-17-2009, 03:32 PM #27
- Join Date
- Jun 2007
- Posts
- 351
Re: The Scripting How-To Thread
init.sqf
init_action.sqfCode:if (isServer) then { endDeployableSand = 0; publicVariable "endDeployableSand"; };
deploySand.sqfCode:_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; }; }; };
retrieveSand.sqfCode:_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"; };
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---

-
07-17-2009, 08:53 PM #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.
-
07-18-2009, 02:43 AM #29
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?
TaBlackDog1





"What we do in life... echoes in eternity!"
-
07-18-2009, 05:06 AM #30
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.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)




Reply With Quote


Bookmarks