Home   Help Search Login Register  

Author Topic: Joining the highest ranking officer  (Read 1522 times)

0 Members and 1 Guest are viewing this topic.

Offline SPhoenix

  • Members
  • *
  • Team BAC
    • BAC Clan Site
Joining the highest ranking officer
« on: 12 Jan 2008, 15:36:50 »
Hi everybody!

I'm currently making a PvP mission where each team has to recover a guy.
I want this last guy to join the highest ranking officer on the side who first captured the base where he's kept.
I made a small script for this:

_HighestRankW1 = leader groupW1;
_RankLW1 = rank _HighestRankW1;
_HighestRankW2 = leader groupW2;
_RankLW2 = rank _HighestRankW2;
_HighestRankW3 = leader groupW3;
_RankLW3 = rank _HighestRankW3;
_HighestRankW4 = leader groupW4;
_RankLW4 = rank _HighestRankW4;

switch (_RankLW1) do {case "PRIVATE": {_RankLW1 = 1}; case "CORPORAL": {_RankLW1 = 2}; case "SERGEANT": {_RankLW1 = 3}; case "LIEUTENANT": {_RankLW1 = 4}; case "CAPTAIN": {_RankLW1 = 4};} 
switch (_RankLW2) do {case "PRIVATE": {_RankLW2 = 1}; case "CORPORAL": {_RankLW2 = 2}; case "SERGEANT": {_RankLW2 = 3}; case "LIEUTENANT": {_RankLW2 = 4}; case "CAPTAIN": {_RankLW2 = 4};}
switch (_RankLW3) do {case "PRIVATE": {_RankLW3 = 1}; case "CORPORAL": {_RankLW3 = 2}; case "SERGEANT": {_RankLW3 = 3}; case "LIEUTENANT": {_RankLW3 = 4}; case "CAPTAIN": {_RankLW3 = 4};}
switch (_RankLW4) do {case "PRIVATE": {_RankLW4 = 1}; case "CORPORAL": {_RankLW4 = 2}; case "SERGEANT": {_RankLW4 = 3}; case "LIEUTENANT": {_RankLW4 = 4}; case "CAPTAIN": {_RankLW4 = 4};}

_HighestRankWest = (_RankLW1 max _RankLW2) max (_RankLW3 max _RankLW4);

switch (_HighestRankWest) do {case _RankLW1 : {_JOIN = leader groupW1}; case _RankLW2 : {_JOIN = leader groupW2}; case _RankLW3 : {_JOIN = leader groupW3}; case _RankLW4 : {_JOIN = leader groupW4};}

[Prince] join _JOIN;

As you have guessed, there are groups, groupW1 to groupW4;
This is the west side only - I have another script for the east side.
I don't understand; when I test the script, everything runs well, putting hints everywhere shows me the Prince actually joins a group - but it's not me, if I get myself as the only Captain on the side.
Any ideas?
Thank you very much!

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Joining the highest ranking officer
« Reply #1 on: 12 Jan 2008, 16:08:50 »
Hi there!

Humm. That looks mighty complicated. When it comes to situations like these, that have no overt error messages but you're still not getting the desired result, what you should try for is using a lot of hints to debug it piece by piece. Also, you have to make sure that you're not messing up the switch...do's by giving them things they don't understand (for instance one of the leaders having a rank that's none of the 5 that it can detect, in which case the rank wouldn't be turned into a number).

Anyway, use sleeps + hints to make sure each part works as it's supposed to. If not, you might i.e. have to invest in some more local variables, use private to make sure variables are being properly defined/aren't overwriting eachother, and some other tricks here and there. Anyway, try this:

Code: [Select]
_HighestRankW1 = leader groupW1;
_RankLW1 = rank _HighestRankW1;
_HighestRankW2 = leader groupW2;
_RankLW2 = rank _HighestRankW2;
_HighestRankW3 = leader groupW3;
_RankLW3 = rank _HighestRankW3;
_HighestRankW4 = leader groupW4;
_RankLW4 = rank _HighestRankW4;
sleep 1;
//To make sure the _HighestRankWX variable is getting defined properly. Should return the "Private", "Corporal" etc strings.
hint format ["%1, %2, %3, %4", _RankLW1, _RankLW2, _RankLW3, _RankLW4];

switch (_RankLW1) do {case "PRIVATE": {_RankLW1 = 1}; case "CORPORAL": {_RankLW1 = 2}; case "SERGEANT": {_RankLW1 = 3}; case "LIEUTENANT": {_RankLW1 = 4}; case "CAPTAIN": {_RankLW1 = 4};}
switch (_RankLW2) do {case "PRIVATE": {_RankLW2 = 1}; case "CORPORAL": {_RankLW2 = 2}; case "SERGEANT": {_RankLW2 = 3}; case "LIEUTENANT": {_RankLW2 = 4}; case "CAPTAIN": {_RankLW2 = 4};}
switch (_RankLW3) do {case "PRIVATE": {_RankLW3 = 1}; case "CORPORAL": {_RankLW3 = 2}; case "SERGEANT": {_RankLW3 = 3}; case "LIEUTENANT": {_RankLW3 = 4}; case "CAPTAIN": {_RankLW3 = 4};}
switch (_RankLW4) do {case "PRIVATE": {_RankLW4 = 1}; case "CORPORAL": {_RankLW4 = 2}; case "SERGEANT": {_RankLW4 = 3}; case "LIEUTENANT": {_RankLW4 = 4}; case "CAPTAIN": {_RankLW4 = 4};}
sleep 1;
//To see if they've properly changed the strings into numbers (should return i.e. 1, 2, 3, 4...)
hint format ["%1, %2, %3, %4", _RankLW1, _RankLW2, _RankLW3, _RankLW4];
_HighestRankWest = (_RankLW1 max _RankLW2) max (_RankLW3 max _RankLW4);
sleep 1;
//To make sure _HighestRankWest works as it's supposed to
hint format ["%1", _HighestRankWest];
switch (_HighestRankWest) do {case _RankLW1 : {_JOIN = leader groupW1}; case _RankLW2 : {_JOIN = leader groupW2}; case _RankLW3 : {_JOIN = leader groupW3}; case _RankLW4 : {_JOIN = leader groupW4};}
sleep 1;
//To find out who Join turned out to be.
hint format ["%1", _JOIN];
[Prince] join _JOIN;

Some things I noted:

Lt. and Cpt. are both given the number 4 as their maximum : so if you have another Lt. in the group, he's equally possible to be the one getting the Prince.

In the final check, you only check for numbers...so in the case of more than one "3" for instance, it'll be the lucky group who's first that'll get the Prince. But I'm guessing that's not a problem. :)

Anyway, try it with the hints to see where it is that things go wrong.

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline SPhoenix

  • Members
  • *
  • Team BAC
    • BAC Clan Site
Re: Joining the highest ranking officer
« Reply #2 on: 12 Jan 2008, 17:56:42 »
Wooh, didn't see that Capt Lieutenant issue.
Thanks!

I'm going to try the script rightaway.

Note that I've already tried putting hints everywhere and that didn't help, as in the script exited properly with going through all the stages.

Offline SPhoenix

  • Members
  • *
  • Team BAC
    • BAC Clan Site
Re: Joining the highest ranking officer
« Reply #3 on: 13 Jan 2008, 15:44:48 »
After many tries, I've resolved the problem:
You need to define the variables before.  >:(

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Joining the highest ranking officer
« Reply #4 on: 13 Jan 2008, 15:52:05 »
Good thing you got things solved, but please do not post consecutively.
At least a couple of days should pass before 'replying to yourself', so if you have something to add to your post modify it instead.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.