PDA

View Full Version : incorporating banking and the player form



fady
03-08-2015, 12:58 AM
So, I've been trying to learn how the player form works and learning how to incorporate it in my scripts. This is my first question so far.


comboBoxLabels := ['Bank Type', 'Bank Preset'];
comboBoxDefaults := ['BANK_BOOTH', 'BANK_BUTTON_PRESET_2'];

setLength(comboBoxItems, length(comboBoxLabels));
comboBoxItems[0] := ['BANK_NPC_BLUE', 'BANK_NPC_GREY', 'BANK_NPC_GREEN', 'BANK_NPC_DRAYNOR', 'BANK_BOOTH', 'BANK_GE', 'BANK_CHEST_SW', 'BANK_CHEST_SHANTAY', 'BANK_CHEST_DUEL', 'BANK_CHEST_CW', 'BANK_CHEST_GROTTO', 'BANK_TABLE_BURTHORPE', 'BANK_CHEST_LUMBRIDGE', 'BANK_CHEST_PRIFDDINAS', 'BANK_CHEST_BARB_OUTPOST'];
comboBoxItems[1] := ['BANK_BUTTON_PRESET_1', 'BANK_BUTTON_PRESET_2'];


I want to incorporate those into lines like bankscreen.open(whichever bank is picked), and bankScreen.clickButton(whichever preset is picked). I looked around in other scripts to see what other people were doing for it, and saw multiple ways which it was done. most of them (using one way or the other) convert the result into numbers (0-13) for banks, which I now know correspond to the banks in the order they are listed in the include, or it is done manually where it converts 'BANK_BOOTH'to BANK_BOOTH, and the same thing was done with presets except the numbers were (3-4). I know that the form is supposed to work with custom records, as the scripts that I've looked at have done. I was just wondering if there was a way to convert it automatically, like there is strToInt, but to remove the ' '.

3Garrett3
03-09-2015, 08:34 PM
fady; I don't think there is a way to do it automatically. strToInt would probably throw an error because you're turning a string into a constant which is assigned an integer. You might be able to parse out the text and throw it into a case statement, but it would probably be more effort than making a big case statement like you've seen in the other scripts.

My Recommendation:


//global variables
var
bankConst : Integer;

//inside function
case boxItem of
'BANK_NPC_BLUE': bankConst := BANK_NPC_BLUE;
//etc...
end;


Not very descriptive code but you seem to know what I mean if I understand your description properly.

The random spit-balling idea:


str := between(boxItem, '_', '_'); // Should look between the first two _ in the string
case str of:
'NPC':
begin
//some sort of string manipulation to grab the last portion of each string (probably another case statement)
end;
'CHEST':
//etc.
end;


The more code I write for that idea the worse it seems. Just go with the first idea and pretend I didn't even mention another idea ;)

fady
03-09-2015, 09:09 PM
fady; I don't think there is a way to do it automatically. strToInt would probably throw an error because you're turning a string into a constant which is assigned an integer. You might be able to parse out the text and throw it into a case statement, but it would probably be more effort than making a big case statement like you've seen in the other scripts.

My Recommendation:


//global variables
var
bankConst : Integer;

//inside function
case boxItem of
'BANK_NPC_BLUE': bankConst := BANK_NPC_BLUE;
//etc...
end;


Not very descriptive code but you seem to know what I mean if I understand your description properly.

The random spit-balling idea:


str := between(boxItem, '_', '_'); // Should look between the first two _ in the string
case str of:
'NPC':
begin
//some sort of string manipulation to grab the last portion of each string (probably another case statement)
end;
'CHEST':
//etc.
end;


The more code I write for that idea the worse it seems. Just go with the first idea and pretend I didn't even mention another idea ;)

Thanks for responding, I'll use case statements then! The second option seems too complicated lol

Thomas
04-19-2015, 07:16 AM
I also had trouble with this. Ashaman assigned his to the numbers of the bankers, but someone else told me that was bad practice as those constants could change.

How did you end up doing it?

The Mayor
04-19-2015, 07:25 AM
I also had trouble with this. Ashaman assigned his to the numbers of the bankers, but someone else told me that was bad practice as those constants could change.

How did you end up doing it?

The case statement Garrett posted is probably the easiest way to do it.

Thomas
04-19-2015, 09:26 AM
The case statement Garrett posted is probably the easiest way to do it.


Yes, probably, but couldn't the banking procedures be changed to also accept strings? I wouldn't know tbh?
I always found it rather weird it accepts integers that seem more like a string to me.
But like you've said before; the banking include is rather messy.

The Mayor
04-19-2015, 10:28 AM
Yes, probably, but couldn't the banking procedures be changed to also accept strings? I wouldn't know tbh?
I always found it rather weird it accepts integers that seem more like a string to me.
But like you've said before; the banking include is rather messy.

Yea it could use strings, but integers are easier to work with when using arrays.

Thomas
04-19-2015, 10:42 AM
Yea it could use strings, but integers are easier to work with when using arrays.

You think you might be able to add it whenever you update the banking include?
I dont need banking location in the playerform myself, but suppose some ppl using my scripts would like it..

Olly
04-19-2015, 05:17 PM
Meh, I don't see the issue with a case statement what so ever nothing wrong with it, certainly no need to add banking overloads to accept strings..

But if you want a piece of wizardy here it is:

const
BANK_CHEST_SHANTAY = 7;

const
playerform_selection = 'BANK_CHEST_SHANTAY';

var
bankType: Integer;

begin
Writeln(GetGlobal(playerform_selection)); // 7 !

{
// or
bankScreen.open(GetGlobal(playerform_selection));
// or
bankType := GetGlobal(playerform_selection);
}
end.

Thomas
04-20-2015, 09:47 AM
Meh, I don't see the issue with a case statement what so ever nothing wrong with it, certainly no need to add banking overloads to accept strings..

But if you want a piece of wizardy here it is:

const
BANK_CHEST_SHANTAY = 7;

const
playerform_selection = 'BANK_CHEST_SHANTAY';

var
bankType: Integer;

begin
Writeln(GetGlobal(playerform_selection)); // 7 !

{
// or
bankScreen.open(GetGlobal(playerform_selection));
// or
bankType := GetGlobal(playerform_selection);
}
end.

That is some serious magic right there! Thanks!

writeLn(players[currentPlayer].strings[SPF_BANK]);
writeLn(GetGlobal(players[currentPlayer].strings[SPF_BANK]));

BANK_CHEST_BARB_OUTPOST
14

Pr0n