Home   Help Search Login Register  

Author Topic: Radioman and leader distance should make radio work but doesn't.  (Read 3082 times)

0 Members and 1 Guest are viewing this topic.

Offline Zarele

  • Members
  • *
  • I'm a llama!
Busting my bananas on this one:

I created a radio operator and a leader both to be players. I want to start a script if the leader is close to the the radioman. Further I want to make the map show to the radioman when he is close to the leader. This is what I have so far:

Code: [Select]
#check

if ("LaserBatteries" in magazines player) then {showRadio true} else {showRadio false}
if ("LaserBatteries" in magazines player) then {enableradio true} else {enableradio false}

if ("Binocular" in weapons player) then {showMap true} else {showMap false}

if ("LaserDesignator" in weapons player)then {goto "radiocal"} else {goto "check"}
if ("LaserDesignator" in weapons player)then {enableradio true} else {enableradio false}
goto "check"

#radiocal

_radioman= player
_leader= Leader group player

?(_radioman distance _leader) <2: goto "startcal"


goto "radiocal"

#startcal

?((_radioman distance _leader)<2 && ("Binocular" in weapons _leader)) then {showMap true} else {showMap false}
_Leader exec "radiocal.sqs"


goto "check"



Where did I make an mistake?
« Last Edit: 29 May 2008, 12:54:49 by Zarele »

Offline Cheetah

  • Former Staff
  • ****
Can you tell us what error is being generated?

Not sure if you can use 'if' 'then' in a .sqs script. Maybe you'll have to use the ? () : action method.
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Rommel92

  • Members
  • *
Code: [Select]
if ((_radioman distance _leader)<2 && ("Binocular" in weapons _leader)) then {showMap true} else {showMap false}

Stick to one format of if statements, your mix and matching lol.

Yes IF statements work in SQS, check Warfare, whole things riddled with em.  :good:

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Most code considered SQF-only will work in SQS, but SQS has no notion of a multi-line command, so they often look ugly forced onto a single line. Still, they work (if/then/else, switch, etc), but I would try to follow either a standard SQS or SQF format, because a lot of people understand SQS and a lot of people understand SQF, but not many know both well and everyone will be confused if you use both at once ;P Really, if you are just learning, learn SQF and ignore SQS (SQS is ever so slightly easier for simple scripts, but a nightmare for anything more complex, which includes most "useful" scripts).

I'm pretty sure you aren't able to use goto from within an if statement, but you can within an ? statement, so  some of your gotos will never happen. If in doubt, don't mix SQF (if) and SQS (goto) like this:
Code: [Select]
if ("LaserDesignator" in weapons player)then {goto "radiocal"} else {goto "check"}
if ("LaserDesignator" in weapons player)then {enableradio true} else {enableradio false}

Even if you convert that, properly, into SQS:
Code: [Select]
? "LaserDesignator" in weapons player ? goto "radiocal" : goto "check"
? "LaserDesignator" in weapons player ? enableradio true : enableradio false
You have the problem that the second line would never be run, since the first line always jumps (uses goto) before the script gets to that latter line. Fix this by just reversing the order of these two lines.

There are a number of other odd things (logical and syntactic errors) going on in the script, so I'm not entirely sure how to fix it (as someone above said, it helps to tell us what the error is, even if, as I suspect, the script is just "not doing anything"). One reason the script might go to hell is that, although it continually loops, there aren't any sleep statements in it, so that it will grind away continuously and give you about 1 frame per second, if you are lucky.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Zarele

  • Members
  • *
  • I'm a llama!
Okay I changed a couple of stuf like adding a wait line and hint lines so I know what is going on but I doesnt even go there

Code: [Select]
#check
~10
if ("LaserBatteries" in magazines player) then {showRadio true} else {showRadio false}
if ("LaserBatteries" in magazines player) then {enableradio true} else {enableradio false}

if ("Binocular" in weapons player) then {showMap true} else {showMap false}


if ("LaserDesignator" in weapons player)then {enableradio true} else {enableradio false}
if ("LaserDesignator" in weapons player)then {goto "radiocal"} else {goto "check"}

hint "check"
goto "check"

#radiocal

_radioman= player
_leader= Leader group player

?(_radioman distance _leader)<2: goto "startcal"

~3
hint "radiocal"
goto "radiocal"

#startcal

?("Binocular" in weapons _leader) then {_radioman showMap true} else {_radioman showMap false}
_leader exec "radiocal.sqs"

~3
hint "starcal"
goto "check"

Well like you said It does nothing but maybee I want to many things in one script:
- I only want players who have a laserbattery/laserdesignator to be able to use the radio
- I want to give the group leader the abillety to call air/art/ support "but" only if he is close to the radioman (the one carrying the laszerdesignator, whoever that is)
-I only want players who have a binocular be able to see the map "but" when another player is near a binoc carrying player he chould also see a map (or have an action added to see it)

So I can't use names placed in the editor because anybody can grab the binoc and "radio's" from dead body's and anybody can bome leader if the other dies

Hope this explains it better.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
As I said, the line:
Code: [Select]
if ("LaserDesignator" in weapons player)then {goto "radiocal"} else {goto "check"}

Will never ever do anything, since you can't use goto (SQS only) inside an if/then/else (SQF on multiple lines or on a single line of SQS, but only allows SQF within the { } ). Neither of the gotos, in then or else, will have an effect, so that you'll just loop around the check loop forever. Thus, all you should see is the hint "check" every 10 seconds (and enabling/disabling the map/radio based on equipment). You can use goto (SQS) inside a ?: (SQS), thusly:
Code: [Select]
? "LaserDesignator" in weapons player ? goto "radiocal" : goto "check"

It is good that you've explained exactly what you wanted to achieve, since it makes it much easier to correct your original script. I think I would struggle to fix your script using SQS, so here is an SQF solution, which I hope that you can understand.

The showRadio command only hides or shows the radio on the map screen, but doesn't add or remove the individual radio trigger texts. Thus, you also need to enable and disable the individual radio messages, otherwise you can use 0-0-1 to activate the radio without needing the walkie-talkie graphic.

Code: (mapAndRadio.sqf) [Select]
// Run this script from init.sqf or init.sqs with:
//   execVM "mapAndRadio.sqf"
//
// You will also need an ALPHA radio trigger placed in the editor.

// Make sure that everything is disabled by default as soon as possible in the mission.
enableRadio false;
showRadio false;
showMap false;
1 setRadioMsg "null";

while { true } do
{
  // Enable radio if player has laser marker and batteries.
  if (("Laserbatteries" in (magazines player)) and (player hasWeapon "LaserDesignator")) then
  {
    enableRadio true;
    showRadio true;
    1 setRadioMsg "Rain of Death";
  }
  else
  {
    enableRadio false;
    showRadio false;
    1 setRadioMsg "null";
  };
   
  // Enable map if player has binocs.
  if (player hasWeapon "Binocular") then
  {
     showMap true; 
  }
  else
  {
    // Disable my map (unless near a friendly binocs-carrier within 5m, then re-enable the map).
    showMap false;

    _nearMen = nearestObjects [player, ["Man"], 5];

    {
      if ((playerSide == (side _x)) and (alive _x) and (_x hasWeapon "Binocular")) exitWith
      {
        showMap true;
      };
    } forEach _nearMen;
  };

  sleep 3;
};
« Last Edit: 30 May 2008, 23:06:06 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Zarele

  • Members
  • *
  • I'm a llama!
THX that sqf works great.

But I don't understand alot of it. The thing I wanted to change in the sqf is the
Code: [Select]
if (("Laserbatteries" in (magazines player)) and (player hasWeapon "LaserDesignator")) then
So that you only need the battery to use the radio. I deleted the part behind the "and" and the and ofcourse but this resulted in error.

I want to reserve the laserdesignator for the radioman but he (or the leader) get acces to a bunch of scripts that others can have acces to.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
I think you are asking for this:
Code: [Select]
if ("Laserbatteries" in (magazines player)) then

I assume you weren't matching up, and deleting, the brackets correctly. It actually helps to use a text editor that understands SQF so that it matches them for you (I'm very lazy and use one all the time ;P).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Zarele

  • Members
  • *
  • I'm a llama!
Yes thats what I ment. Witch program is good? Atm I'm using "arma edit" by chris anderson

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
I use the same editor I have been using for years, Crimson Editor, for which I have made my own syntax files so it understands ArmA scripts. ArmA Edit was designed specifically for use with SQS/SQF however, so I'm sure it is perfectly good for you or anyone else who doesn't already have an editor that they are already used to.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Rommel92

  • Members
  • *
Any chance you could share those syntax files with us? Looks promising.  :)

EDIT: (Post not worthy of a post)

Reply to Spooners Following Post.

*Breathes in Deeply.*... (Lets rock and roll!  :D)
« Last Edit: 02 Jun 2008, 21:48:28 by Rommel92 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Well, since there is already ArmA Edit and equivalent syntax files for a couple of other editors (jedit and Ultraedit), I'm not sure that you really need them! Still, I had intended to upload them since the more choice the better, but just forgot. I'll see if I can remember next time I'm home (don't hold your breath ;P).
« Last Edit: 04 Jun 2008, 18:44:17 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)