Home   Help Search Login Register  

Author Topic: How to check when a soldier drops his weapon  (Read 2205 times)

0 Members and 1 Guest are viewing this topic.

Butler

  • Guest
How to check when a soldier drops his weapon
« on: 07 May 2004, 02:17:32 »
Hi everyone!

Is there any way you can check when a soldier (player) drops his weapon?
I am (trying) to make a mission where the player gets outnumbered, and beeing told to drop his weapon.
When he drops his M16 the game will notice, and he will be taken as a prisoner.
Hope someone can help me with this thing. Sorry for my English. I am from Norway.
You guys are great :)
 

Offline Jezuro

  • Members
  • *
  • Hookah 4 lyfe!
    • Jezuro's ArmA Workshop
Re:How to check when a soldier drops his weapon
« Reply #1 on: 07 May 2004, 13:23:04 »
There are several ways to check it.

1) You want the player to drop ALL HIS WEAPONS (EVEN HANDGUNS) AND MAGAZINES + ALL EQUIPMENT (BINOCULARS, NV GOGGLES, ETC....) For this, use:

@ count ((weapons player) + (magazines player)) == 0

2) You want the player to drop only HIS WEAPONS (EVEN HANDGUN) AND MAGAZINES:

@ count (magazines player) == 0 && count ((weapons player) - ["NVGoggles","Binocular"]) == 0
I'm not sure with this one...

3)You want the player to drop only HIS WEAPONS AND HANDGUN:

@ count ((weapons player) - ["NVGoggles","Binocular"]) == 0
I'm not sure with this one, too...

4) You want the player to drop only HIS WEAPONS, NOT HANDGUN:

@ PrimaryWeapon player == "" && SecondaryWeapon player = ""

5) You want the player to drop ONLY HIS RIFLE:

@ PrimaryWeapon player == ""

I'm not sure in 2) and 3) because I don't know exactly if you can remove items from an array even if they're not in it. Try it, I can't run OFP right now (I'm in school).
« Last Edit: 07 May 2004, 13:24:05 by Jezuro »
"We are Her salvation, and through Her command we shall live forever. I will not die. Not here. Not now. Never!!!"

Butler

  • Guest
Re:How to check when a soldier drops his weapon
« Reply #2 on: 07 May 2004, 16:53:56 »
Thanks for fast reply!

It worked like a dream. Now i can continue thanks to you.

I owe you a beer   ;D

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: How to check when a soldier drops his weapon
« Reply #3 on: 09 Nov 2007, 23:17:33 »
Hi!

Can you explain me, how I can use this script when I want to do an If-Then Situation? I could not get it working with your explanations (Jezuro)...

I want to have the following situation:

-> AI says to me (Player) to drop the weapons
a) If I drop them, the scripts terminates
b) If I do not drop them, the AI says to me the second warning after some seconds

-> Then after the some seconds the same result,
a) if I have dropped them, script exits
b) If not, the AI shots me down



Would be very glad if you could help, thank you!


Edit:
BTW: Does it also work for Armed Assault?
« Last Edit: 09 Nov 2007, 23:23:25 by Undeceived »
Current project: Black Lands (Arma 3)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to check when a soldier drops his weapon
« Reply #4 on: 10 Nov 2007, 10:02:12 »
The code is equally valid in ArmA as in OFP, as long as you are using SQS, of course (but just use waitUntil { } instead of @ to convert to SQF). I'll assume by If-Then, you actually mean if-then (SQF), not ?: (SQS):

Remember, by the way, that although it might seem unnecessary to make the player drop his magazines, that explosive grenades are just magazines with one round of ammunition in them (their weapon is "throw", which you can't drop!).
Code: (takeCaptive.sqf) [Select]
// Unless the player is initially considered a "captive", at least in game terms,
// the AI will shoot him before he has the chance to disarm.
player setCaptive true;

if ((count (magazines player) > 0) or (count ((weapons player) - ["NVGoggles","Binocular"]) > 0)) then
{
    titleText ["Drop your weapons!", "PLAIN DOWN"];
    sleep 15;
   
    if ((count (magazines player) > 0) or (count ((weapons player) - ["NVGoggles","Binocular"]) > 0)) then
    {
        titleText ["I said drop your weapons NOW!", "PLAIN DOWN"];
        sleep 15;

        if ((count (magazines player) > 0) or (count ((weapons player) - ["NVGoggles","Binocular"]) > 0)) then
        {
            titleText ["Drop him lads!", "PLAIN DOWN"];
            player setCaptive false; // Suddenly, the AI will hate the player again and kill him.
        };
    };
};

// If still a captive, then the player must have put down weapons at some point.
if (captive player) then
{
     titleText ["Right, now you come with us.", "PLAIN DOWN"];
    // Make sure you get rid of the weapons at this point to prevent the player from just rearming himself
    // (e.g. by moving to next step in campaign or by deleting them). Alternatively, you might be better
    // having some sort of continual check from this point on and setCaptive true if the player picks up
    // a weapon again.
};

The script doesn't take into account that all the AI could be killed by a 1337 player who didn't want to get captured or that if the player shoots a few enemies then lays down his weapons that they'll not hold a grudge. Either factor may be worth considering in your mission.
« Last Edit: 10 Nov 2007, 23:57:15 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: How to check when a soldier drops his weapon
« Reply #5 on: 10 Nov 2007, 14:52:09 »
ummmm.......emmmmm....if - then is equally valid in sqs as it is in sqf, as far as I can recall.


Planck
I know a little about a lot, and a lot about a little.

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: How to check when a soldier drops his weapon
« Reply #6 on: 10 Nov 2007, 15:48:55 »
Ok, this looks very good, I'll try it with your code, thank you so far!

What I forgot to say is that it isn't a situation between OPFOR and BLUEFOR but between friendly BLUEFOR and Resistance who "got to know each other the first time".  :)
Well, I will give it a try. If I can't do it, I'll just report here once again...  :D

But thx anyway!!!  :clap:
Current project: Black Lands (Arma 3)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to check when a soldier drops his weapon
« Reply #7 on: 10 Nov 2007, 16:05:50 »
@Planck
Oops, you are in fact quite right, as long as you keep the whole if/then/else statement on one line (I've always seen SQS writers clinging desperately to ?: and goto though). That means, in the example I gave, you would convert it to SQS by putting it on two lines (comments would have to use the comment "blah" syntax), which is far from helpful, though quite probably still more readable than an evil nest of ?:s and gotos.

Actually, knowing this makes me very happy, since now I no longer have to keep using the painfully archaic ?: (no else clause; only one statement can be run if true; different syntax to other programming languages that use those operators) when giving SQS examples; yay!

@undeceived
Ah, if the two sides start as friends, then you will have problems, since the player will only become an enemy if the player shoots someone on the other side. I think you'd be better off starting with the sides being enemies and make the player a captive from the very start (this just means that everyone will consider him a friend and not shoot at him, rather than that he is an actual captive). setFriend is an ArmA command, else you may have got some joy with that...
« Last Edit: 10 Nov 2007, 16:19:18 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: How to check when a soldier drops his weapon
« Reply #8 on: 10 Nov 2007, 23:33:30 »
Hi guys

Ok, I tried to adopt the script now that you posted earlier (@ Spooner). But unfortunately it didn't work out the way I wanted... :no:

The script just ran through from top to the bottom executing one line after the other without following the if-commands etc. Finally it just exits. Like if there existed no if-then commands at all.

And I encountered this one error again, I'm not at home right now (can't execute ArmA), so I just remember the |#|... I think it was the one "error in expression", don't know. However, there was a mistake in the script (the way I used it, of course  ;) ).

I also tried it both as .sqs or .sqf, the result was the same.



Edit:

Here is my script, how I used it...


luchswaffennieder.sqf
__________________

if ((count (magazines Luchs) == 0) and (count ((weapons Luchs) - ["NVGoggles","Binocular"]) > 0)) then
{
    titleText ["Drop your weapons!", "PLAIN DOWN"];
    playsound "dropweapon1"
    ~15
   
    if ((count (magazines Luchs) == 0) and (count ((weapons Luchs) - ["NVGoggles","Binocular"]) > 0)) then
    {
        titleText ["I said drop your weapons NOW!", "PLAIN DOWN"];
        playsound "dropweapon2"
        ~15

        if ((count (magazines Luchs) == 0) and (count ((weapons Luchs) - ["NVGoggles","Binocular"]) > 0)) then
        {
            titleText ["Drop him lads!", "PLAIN DOWN"];
            playsound "witz"
            Luchs setCaptive false; // Suddenly, the AI will hate the player again and kill him.
resanf dofire Luchs;
        };
    };
};


if (captive Luchs) then
{
     titleText ["Right, now you come with us.", "PLAIN DOWN"];
     playmusic "sleep2"
resanf setbehaviour "safe"
resisani setbehaviour "safe"
   
};

____________

Ahm... Just tell me one thing, I am remembering right now. It is ok to use the name of the played unit (in this case -> Luchs), isn't it? I don't have to write "Player", do I?
« Last Edit: 10 Nov 2007, 23:40:53 by Undeceived »
Current project: Black Lands (Arma 3)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to check when a soldier drops his weapon
« Reply #9 on: 10 Nov 2007, 23:56:02 »
Er, you can use the specific name luchs, but player always refers to the local player, so it is usually easier than using a specific player object's name and makes the script easier to use in any mission without needing to be changed.

Well, I'm away from my ArmA machine for a few days, so I can't directly test it. However, since you are editing an SQF file, you need to:
- put a ; at the end of every statement.
- use "sleep 15" rather than "~15"

I also made a dumb logical mistake: the three ifs should be (Now changed in the original script, to confuse future readers less ;( ):
Code: [Select]
if ((count (magazines player) > 0) or (count ((weapons player) - ["NVGoggles","Binocular"]) > 0)) then
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: How to check when a soldier drops his weapon
« Reply #10 on: 11 Nov 2007, 19:49:23 »
Yesss! Finally it worked!!

This was a hard nut to crack -> First I tried it with the new code you provided but it didn't work again! Hm...
Then I began to think that this maybe would have nothing to do with the code itself, the mistake had to be elsewhere...

Then, after some minutes searching I finally repared, that I executed the funktion incorrectly! -> [] exec ".......sqf"
Now with execVM it does work!  ::) Aaarrrr!! My mistake.
This was the reason why ArmA just ran through and finished it... (Btw, earlier I put the "~" in just to create a working pause, in my hopelessness  :D )
Damn! So much time... But never mind.
And anyway, good to have a corrected version of the codes ;)

Hey, thank you again! Very good help! See you.
« Last Edit: 11 Nov 2007, 19:51:28 by Undeceived »
Current project: Black Lands (Arma 3)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to check when a soldier drops his weapon
« Reply #11 on: 11 Nov 2007, 21:37:44 »
Ah yes, as usual I added problems by giving SQF answer, though in my defence, I thought that was what you wanted. Nevertheless, working out how to run SQF scripts, even if you don't learn how to write them, is a good thing for anyone wanting to use other people's scripts (though I'd always strongly recommend people to learn SQF rather than SQS).

Note though, that execVM starts the new script as a separate process and immediately returns, unlike exec which runs the whole new script then comes back to where the script was called from, returning a value. If you want to run an SQF script in the same way as exec works on SQS, you can use call compile preprocessFileLineNumbers (more wordy, admittedly ;P).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)