Jump to content
Sign in to follow this  
Dragster

Trying to learn basic scripting need help

Recommended Posts

ok im just trying to learn how to use sqf scripting

trying to make a script and it dont work can some look at this and tell me what i have done wrong.

i just made this script to try and understand basic scripting

man1 are gonna shoot man2 when he gets closer than 50 meters

the problem I have are that man 1 shoots man2 both if he are closer than 50meter and farther away than 50 meters. what have i done wronge?

if { man1 distance man2 <50} then

{

man1 doFire man2

};

Share this post


Link to post
Share on other sites

Are they on same side or civilians? If they are enemies, obviously they are going to shoot as soon as they detect.

Share this post


Link to post
Share on other sites

Aside from shk said your brackets are also messed up. Conditions are wrapped in square, not curly brackets.

if (man1 distance man2 <50) then
{
   man1 doFire man2
};

Share this post


Link to post
Share on other sites

Well, technically conditions are wrapped in neither curly nor square brackets. They're wrapped in parentheses.

Share this post


Link to post
Share on other sites

Thanks for the help it works now. And i forgot to say it was two bluefore soldiers. will try to give more details next time i need help:). Are not gonna use the script for anything just trying to understand scripting.

Share this post


Link to post
Share on other sites

Ok im trying a little diffrent script now and cant get it to work

_unit = _This select 0;

_unitpos = _this select 1;

if (_unit distance _unitpos >50) then

{

_unit doMove position _unitPos

};

Cant get it to work _unit will not move to _unitpos

im using call { [a1,player] execVM "domove.sqf"; }

with radio alfa in a trigger to activate the sqf script

I get it to work if i use

_unit = _This select 0;

_unitpos = _this select 1;

_unit doMove position _unitPos;

I added the distance stuff just to see how it would work.

im just trying to get A1 to move to me as player when im 50 meters away from him

again im not going to use it for anything im just trying to under stand sqf scripting and any help would be nice

Share this post


Link to post
Share on other sites
Ok im trying a little diffrent script now and cant get it to work

_unit = _This select 0;

_unitpos = _this select 1;

if (_unit distance _unitpos >50) then

{

_unit doMove position _unitPos

};

Cant get it to work _unit will not move to _unitpos

im using call { [a1,player] execVM "domove.sqf"; }

with radio alfa in a trigger to activate the sqf script

I get it to work if i use

_unit = _This select 0;

_unitpos = _this select 1;

_unit doMove position _unitPos;

I added the distance stuff just to see how it would work.

im just trying to get A1 to move to me as player when im 50 meters away from him

again im not going to use it for anything im just trying to under stand sqf scripting and any help would be nice

Ive in the past had issues with using position command, not sure why maybe it was my context, never looked into it as getPos wich is basically the same works juts fine.

also position (wich on biki is same as getPos) should refer to an object or unit not another position.

Also i tend to use (getPos _unit) instead of getPos _unit

() around makes that be one argument, for example

floor(random (count(units group)))

(units group) returns an array of all units in that group

(count(units _group)) returns the count for array

(random (count(units group))) returns a random number from the count

floor(random (count(units group))) selects the closest whole number downwards from the random number ( if random is 5.34 it would return 5)

notice no ( infront of floor, also note that all seperate arguments are enclosed in ()) or (())) etc depending.

For a proper working of your script with different alternatives

// make unit move to player position when player is within 50 meters.
// execute with: _null = [unitname] execVM "scriptname.sqf"

_unit = _this select 0;

// this will only check at time of script executed, if distance is avbove 50 it will just sckip down to loop part.
if (player distance (getPos _unit) < 50) then {
_unit domove (getPos player);
};

// loop part. will run 1 time every 1 seconds from //start to // repeat until distance between player and _unit is less than 50. note > instead of <

while {player distance (getPos _unit) > 50} do {
//start
sleep 1;
};// repeat

// here is another way wich we will use as final condition.
// script will pause here and wait until the said condition is true, in this case if player distance to _unit is less than 50 then its true.
waituntil {player distance (getPos _unit) < 50};

// now final move the _unit.
_unit domove (getPos player);

//script will exit here on its own.
// note all the above is not required but describes their different uses.

EDIT: here its asumed that player is the target destination, you can simply change that by adding

_unit2 = _this select 1;

and replace player with _unit2

and in execute line use [unitname, unitothername]

but i assumed you understood that :)

Edited by Demonized
some typos as well

Share this post


Link to post
Share on other sites

not to hop off subject but another usefull way to learn scripts is to download templates on armaholic and look at there scripts used there. useually some very good examples.

Share this post


Link to post
Share on other sites

thanks demobized you post helped alot not just with the script but helped me understand a few things i had missed wich was more important for me than the script. Thanks alot

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×