Home   Help Search Login Register  

Author Topic: Weapon block  (Read 4428 times)

0 Members and 1 Guest are viewing this topic.

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Weapon block
« on: 08 May 2009, 15:31:04 »
Im mission that I am working on player have to choose one of 11 classes. Anyway, I cant see sense when all players use ATs or something. I am going to put blockade on classes. But I have opportunities how to do that:
1. If class is free - you can take it.
2. If not - you get proper message on teamchat.

I thought about using command similar to this:
Code: [Select]
!(_west hasweapon "M16A4") >4
But it seems not to work. I believe it is connected with this script, but I dont know how to use it.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon block
« Reply #1 on: 08 May 2009, 22:23:08 »
Code: (true if up to 4 players have an M16A4) [Select]
if (({ _x hasweapon "M16A4" } count players) <= 4) then
{
};
Where "players" is a list of all the players that you have made yourself, perhaps from a WEST DETECTED trigger.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Weapon block
« Reply #2 on: 09 May 2009, 16:07:00 »
OK, now how to implement it into a script? Damn it, sorry for my lack of knowledge  :o

So, with eg. M136 I should:

Code: [Select]
if (({ _x hasweapon "M136" } count players) <= 2) then goto "neg"

_unit = _this select 1


removeAllWeapons _unit

_unit sidechat "I TOOK LIGHT ANTI-TANK CLASS"
_unit addMagazine "30Rnd_556x45_Stanag"
_unit addMagazine "30Rnd_556x45_Stanag"
_unit addMagazine "30Rnd_556x45_Stanag"
_unit addMagazine "30Rnd_556x45_Stanag"
_unit addWeapon "M16A4"
_unit selectWeapon "M16A4"
_unit addMagazine "M136"
_unit addWeapon "M136"
_unit addWeapon "Binocular"
_unit addWeapon "NVGoggles"

#neg
_unit groupchat "CLASSES ARE IN USE. CHOOSE OTHER CLASS"
removeallweapons _unit

Exit

EDIT: Seems not working.
« Last Edit: 09 May 2009, 16:12:48 by SaS TrooP »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon block
« Reply #3 on: 10 May 2009, 03:55:00 »
"Seems not working." is not a useful thing to say when asking for help. I can see why your script doesn't work and what the error messages would be, but you have to assume that most people don't have that knowledge or the time to make a demo mission just to find out what goes wrong when you try to run the script. Explaining whether nothing happens, the wrong thing happens or you get an error (and pasting the error from the arma.rpt file) can really help us work out where you are going wrong...

You were not clear in your original post whether you use SQS or SQF, so I answered in SQF (Everyone should be using SQF in this day and age, because SQS is long obsolete; I'd encourage all new learners to disregard SQS and just learn SQF instead). As far as I'm aware, you can't mix if/then with gotos, so you should use ?: if you are using SQS. The top of your script should be:
Code: [Select]
_unit = _this select 1

; Make sure no more than 2 people are given an M136:
? ({ _x hasweapon "M136" } count players) > 2 : goto "neg"
I'll recommend SPON Kits script to make managing equipment loadouts easier, though it won't directly help you get your logical issues sorted (and although it doesn't limit kits in any way, as you require).
« Last Edit: 10 May 2009, 03:57:43 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Weapon block
« Reply #4 on: 10 May 2009, 18:16:24 »
OK, seems working, but I need some friends to test it :)

Anyway, how should it look at .sqf file? I eamn whole script. In fact, I am still stuck on OFP scripting files :|

PS: I checked your Kit system. Looks interesting, in other missions I may try it, but Its bit unusable here.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon block
« Reply #5 on: 10 May 2009, 18:50:22 »
Don't know if this is any clearer for you, but it reads a lot more clear for me without the messy goto:
Code: (SQF version) [Select]
#define MAX_M136_ALLOWED 2

_unit = _this select 1;

// Make sure no more than 2 people are given an M136:
if (({ _x hasweapon "M136" } count players) > MAX_M136_ALLOWED) then
{
_unit sideChat "CLASSES ARE IN USE. CHOOSE OTHER CLASS";
}
else
{
removeAllWeapons _unit;

_unit sideChat "I TOOK LIGHT ANTI-TANK CLASS";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addWeapon "M16A4";
_unit selectWeapon "M16A4";
_unit addMagazine "M136";
_unit addWeapon "M136";
_unit addWeapon "Binocular";
_unit addWeapon "NVGoggles";
};

SPON Kits would be useful for you, but I'm not sure learning how to use it and adapting it for this style of limitation would be worth the effort for you. I've put in a request (to myself) that it support limits in the future though.
« Last Edit: 10 May 2009, 19:06:23 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Weapon block
« Reply #6 on: 10 May 2009, 22:16:44 »
Code: [Select]
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////

_unit = _this select 1;

#define MAX_M136_ALLOWED 1

// Make sure no more than 2 people are given an M136:
if (({ _x hasweapon "M136" } count players) > MAX_M136_ALLOWED) then
{
_unit groupChat "CLASSES ARE IN USE. CHOOSE OTHER CLASS";
}
else
{
removeAllWeapons _unit;

_unit sideChat "I TOOK LIGHT ANTI-TANK CLASS";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addWeapon "M16A4";
_unit selectWeapon "M16A4";
_unit addMagazine "M136";
_unit addWeapon "M136";
_unit addWeapon "Binocular";
_unit addWeapon "NVGoggles";
};

For test purpose just max 1 AT allowed.
I start the script from ammo box init:

Code: [Select]
this addaction ["CLASS LIGHT ANTI-TANK","usmc_at.sqf"];
Trouble is that now there is no reaction. In some way game... does not read the script? No error message, just nothing. I checked for script or single letter error, but nothing happens.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon block
« Reply #7 on: 11 May 2009, 03:50:45 »
I would suspect that you didn't set up the players array (remember, I said, "Where players is a list of all the players that you have made yourself, perhaps from a WEST DETECTED trigger."). Since you didn't mention this again, you may have missed this. I don't know about your mission, so I can't tell you exactly the best way to do this.

Best is probably actually to do this, rather than using the trigger I suggested (which wouldn't work in a number of situations, depending on what type of mission you have made):
* Name each player soldiers p1, p2, p3, p4, etc.
* Replace the occurrences of players in the script with [p1, p2, p3, p4] (or whatever, based on the number of players in your mission).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Weapon block
« Reply #8 on: 11 May 2009, 19:24:54 »
Code: [Select]
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////

_unit = _this select 1;

#define MAX_M136_ALLOWED 1

// Make sure no more than 2 people are given an M136:
if (({ _x hasweapon "M136" } count [usa1,usa2,usa3,usa4,usa5,usa6,usa7,usa8,usa9,usa10,usa11,usa12,usa13,usa14,usa15,usa16]) > MAX_M136_ALLOWED) then
{
_unit groupChat "CLASSES ARE IN USE. CHOOSE OTHER CLASS";
}
else
{
removeAllWeapons _unit;

_unit sideChat "I TOOK LIGHT ANTI-TANK CLASS";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addWeapon "M16A4";
_unit selectWeapon "M16A4";
_unit addMagazine "M136";
_unit addWeapon "M136";
_unit addWeapon "Binocular";
_unit addWeapon "NVGoggles";
};

Hah, now it works, but:
1.
Code: [Select]
#define MAX_M136_ALLOWED 1That means only 1 M146 is alowed. I still had to take 2 of them to block the kit.
2. How it works when some players are disabled. You know, ussually you dont leave AIs staying in the base on their own. Will it work property?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon block
« Reply #9 on: 12 May 2009, 15:29:12 »
1. Should be '>= MAX_M136_ALLOWED'. Sorry, my fault.
2. Your mission should have 'disabledAI = true;' in the description.ext, to prevent the AI from standing around when you aren't playing them.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Weapon block
« Reply #10 on: 12 May 2009, 17:36:43 »
But what you mean exactly?

Code: [Select]
_unit = _this select 1;

#define >= MAX_M136_ALLOWED 1

// Make sure no more than 2 people are given an M136:
if (({ _x hasweapon "M136" } count [usa1,usa2,usa3,usa4,usa5,usa6,usa7,usa8,usa9,usa10,usa11,usa12,usa13,usa14,usa15,usa16]) > MAX_M136_ALLOWED) then
{
_unit groupChat "CLASSES ARE IN USE. CHOOSE OTHER CLASS";
}
else
{
removeAllWeapons _unit;

_unit sideChat "I TOOK LIGHT ANTI-TANK CLASS";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addMagazine "30Rnd_556x45_Stanag";
_unit addWeapon "M16A4";
_unit selectWeapon "M16A4";
_unit addMagazine "M136";
_unit addWeapon "M136";
_unit addWeapon "Binocular";
_unit addWeapon "NVGoggles";
};

I tried with '', but now game is one step back - addaction on crates stopped working again :|

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon block
« Reply #11 on: 12 May 2009, 20:37:22 »
Sorry, I meant that it should be:
Code: [Select]
if (({ _x hasweapon "M136" } count [usa1,usa2,usa3,usa4,usa5,usa6,usa7,usa8,usa9,usa10,usa11,usa12,usa13,usa14,usa15,usa16]) >= MAX_M136_ALLOWED) then
rather than just '>'. The #define statement was fine.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Weapon block
« Reply #12 on: 12 May 2009, 21:39:11 »
Ahhh, my fault :)
I did not checked if it works on fragment behind all units.

Well, probably I have to thank you again. I learned few basics, I am also gonna read Cheetah SQF Tutorial. Trouble is if I can use it in practice ;/

But I have plenty of questions yet so...

EDIT: OK< hope its last problem:

Code: [Select]
_unit = _this select 1;

#define MAX_STRELA_ALLOWED 1

if (({ _x hasweapon "Strela" } count [rus1,rus2,rus3,rus4,rus5,rus6,rus7,rus8,rus9,rus10,rus11,rus12,rus13,rus14,rus15,rus16]) >= MAX_STRELA_ALLOWED) then
{
_unit groupChat "CLASSES ARE IN USE. CHOOSE OTHER CLASS";
}
else
{
removeAllWeapons _unit;

_unit sidechat "I TOOK ANTI-AIR CLASS"
_unit addMagazine "STRELA"
_unit addMagazine "STRELA"
_unit addWeapon "STRELA"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addMagazine "8Rnd_9x18_Makarov"
_unit addWeapon "Makarov"
_unit addWeapon "Binocular"
_unit addWeapon "NVGoggles"

Exit

In-game info says that something is with line 15. Can you say what trouble is? Probably something with '{'
« Last Edit: 13 May 2009, 17:22:11 by SaS TrooP »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Weapon block
« Reply #13 on: 14 May 2009, 00:23:53 »
Probably the missing semi-colons from the end of lines.


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

Offline Rommel92

  • Members
  • *
Re: Weapon block
« Reply #14 on: 24 May 2009, 02:07:18 »
Code: [Select]
_unit = _this select 1;

#define NEW_WEAP "Strela"
#define NEW_WEAP_MAG "Strela"
#define MAX_WEAP_ALLOWED 1
#define UNITS_ARRAY [rus1,rus2,rus3,rus4,rus5,rus6,rus7,rus8,rus9,rus10,rus11,rus12,rus13,rus14,rus15,rus16]
#define UNIT_CLASS "AA"

/*
  NEW_WEAP is the weapon you are checking against and adding
  NEW_WEAP_MAG is the weapons magazines that you will be adding
  MAX_WEAP_ALLOWED is the weapons maximum amount in UNITS_ARRAY
  UNITS_ARRAY is the array of units you've placed and are checking against.
*/

if (({ _x hasweapon NEW_WEAP } count UNITS_ARRAY) >= MAX_WEAP_ALLOWED) then
{
_unit groupchat format["%1, MAXIMUM COUNT OF %2 CLASS. CHOOSE ANOTHER", name _unit, UNIT_CLASS];
}
else
{
removeAllWeapons _unit;

/*
Everything below this line was Missing semi - column (;)
I also added the macro from above to make modification easier.
If this is launched via an action, actions are local and hence the other players would not see the sidechat anyway.
*/
_unit groupchat format["%1, TAKING %2 CLASS", name _unit,  UNIT_CLASS];
_unit addMagazine NEW_WEAP_MAG;
_unit addMagazine NEW_WEAP_MAG;
_unit addWeapon NEW_WEAP;

_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addMagazine "8Rnd_9x18_Makarov";
_unit addWeapon "Makarov";

_unit addWeapon "Binocular";
_unit addWeapon "NVGoggles";
};

nil;

/*
The 'exit' command does not work in SQF format style scripts, if you wish to exit the current scope (frame of reference, current curly brackets) use
if (<BOOL STATEMENT) exitwith {<ANY STATEMENTS>}
You also forgot the closing bracket at line 46.
Nil returned; although may not be needed for actions.
*/
« Last Edit: 24 May 2009, 02:24:17 by Rommel92 »