OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Delta on 24 Nov 2007, 21:44:31
-
Hi,
I'm ashamed. :confused:
I'm stuck on a simple .SQF loop script guys.
I need to add an action to the player whenever he has a weapon.
If he drops the weapon the action must then dissapear as well.
If he later picks up the weapon,then the option must reappear also. :scratch:
I have a single run version working,but as I say it needs to be running all the time the player is alive (thus convertion from .sqs to .sqf is needed)
while {alive player} DO
{
if (player hasweapon "M16") then
{
MNU = player addaction ["Attach Bayonette","bayonette.sqf"];
}
else
{
player removeaction MNU
};
};
I get an } related error, and if I add the 'sleep' command I get one about that too.
I'm going crazy trying to get the desired result in .sqf format!
Can anyone help me out?
-
I switched your code sample too CODE. :P
I also spaced out your routine so it was easier to read.
I think your missing a ;
player removeaction MNU;
It really helps to craft your code so you can see errors like this. I miss a ; all the time. :D
-
Thanks Hoz,
I still seem to have the same problems unfortunately.
while {alive player} DO
{
if (player hasweapon "M16") then
{
MNU = player addaction ["Attach Bayonette","bayonette.sqf"];
}
else
{
player removeaction MNU;
};
sleep 0.5;
};
-
I don't think there's such a weapon as "M16" in ArmA, the proper name for the old M16A2 is, simply "M16A2". For the newer M16A4, it's "M16A4" :D
Otherwise, I don't really see anything wrong with it. :-/ Sure you're exec-vm'ing it and such properly, and that the addaction's script exists?
Wolfrug out.
-
Hi,cheers wolfrug. :scratch:
Otherwise, I don't really see anything wrong with it. :-/ Sure you're exec-vm'ing it and such properly, and that the addaction's script exists?
Wolfrug out.
Its the exec vm bit I messed up.
Sheesh! :confused:
-
Hi Ladies and Gentlemen,
Yes that's right "M16" is not an ArmA weapon but OFP.
You must check your execution command of the script. You can't launch a .sqf script like a .sqs by a simple exec.
Something like player exec myscript.sqf makes ArmA to execute it like a .sqs then all specific .sqf commands and syntax will return errors.
A good execution will be
script = [ ] execVM "myscript.sqf"
where arguments will be passed through the [] if needed.
or
whatever = [ ] execVM "myscript.sqf"
firstnameofyourgirlfriend = [ ] execVM "myscript.sqf" :-*
Otherwise try this:
private ["_compWeap","_loop","_MNU"];
//make list of bayonette compatible weapons
_compWeap = ["M16A2","M16A2GL","M16A4","M16A4_ACG","M16A4_ACG_GL","M16A4GL","M4","M4A1GL","M4A1","M4AIM","M4GL"];
//now the loop
for [{_loop=0},{_loop<1 or alive player},{_loop=_loop}] do
{
if ((primaryweapon player) in _compWeap and (vehicle player)==player) then
}
_MNU = player addaction ["Attach Bayonette","bayonette.sqf"];
}
else
{
player removeaction _MNU;
};
sleep 0.5;
};
I've changed the loop "while" by a loop "for" because loops "while" are limited to 10,000 rounds until the loop exit by itself. In your case with sleep 0.5 sec makes 5,000 sec (~ 1h30). I replaced MNU by _MNU because here's no reason to create a global variable.
I put all M16 and M4 weapon versions in the _compWeap array but i'm not sure if the versions having grenade launcher allow a bayonette down the muzzle in reality. Could be dangerous ... :scratch:
PrimaryWeapon doesn't return the current active weapon (in hands) but what's loaded in 1st slot. Then if your soldier is not supposed to attach a bayonette on a handgun may be you should start your bayonette.sqf by:
player selectWeapon (primaryweapon player);
That's just couple of ideas ... ;)