SRL Archive - Help and Support

"Prioritising" code.


neG

2007-11-29 07:54:23

I'm having trouble thinking of a way to make something work properly in my script.

I have this procedure here.

[PHP]procedure FixStyle;
var CAtt, CStr, CDef: Integer;
begin
if not LoggedIn then Exit;
begin
CAtt := GetSkillLevel('attack');
CStr := GetSkillLevel('strength');
CDef := GetSkillLevel('defence');
if TargetAttack > CAtt then
begin
WriteLn('Attack below target level.');
SetStyle('att');
Exit;
end;
if TargetStrength > CStr then
begin
WriteLn('Strength below target level.');
SetStyle('str');
Exit;
end;
if TargetDefence > CDef then
begin
WriteLn('Defence below target level.');
SetStyle('def');
Exit;
end;
end;
end;[/PHP]

And I want to make some constants such as


AttackPriority = 2
StrengthPriority = 1
DefencePriority = 3


so that it will excecute the "if TargetStrength > CStr then" first, then the attack part, then finally defense.

Do you understand what I mean? Can anyone help out?

Bobarkinator

2007-11-29 07:58:57

Do you want to prioritize? Or make a weighted random?

ZephyrsFury

2007-11-29 08:00:43

From: neG
I'm having trouble thinking of a way to make something work properly in my script.

I have this procedure here.

[PHP]procedure FixStyle;
var CAtt, CStr, CDef: Integer;
begin
if not LoggedIn then Exit;
begin
CAtt := GetSkillLevel('attack');
CStr := GetSkillLevel('strength');
CDef := GetSkillLevel('defence');
if TargetAttack > CAtt then
begin
WriteLn('Attack below target level.');
SetStyle('att');
Exit;
end;
if TargetStrength > CStr then
begin
WriteLn('Strength below target level.');
SetStyle('str');
Exit;
end;
if TargetDefence > CDef then
begin
WriteLn('Defence below target level.');
SetStyle('def');
Exit;
end;
end;
end;[/PHP]

And I want to make some constants such as


AttackPriority = 2
StrengthPriority = 1
DefencePriority = 3


so that it will excecute the "if TargetStrength > CStr then" first, then the attack part, then finally defense.

Do you understand what I mean? Can anyone help out?


This should work:

procedure FixStyle;
var CAtt, CStr, CDef: Integer;
begin
if not LoggedIn then Exit;
begin
CAtt := GetSkillLevel('attack');
CStr := GetSkillLevel('strength');
CDef := GetSkillLevel('defence');
if TargetAttack > CAtt then
begin
WriteLn('Attack below target level.');
SetStyle('att');
Exit;
end else //End Else
if TargetStrength > CStr then
begin
WriteLn('Strength below target level.');
SetStyle('str');
Exit;
end else
if TargetDefence > CDef then
begin
WriteLn('Defence below target level.');
SetStyle('def');
Exit;
end;
end;
end;

Notice the end elses after each thing. That means that if Att is less than the target lvl it will do attack. But then once the att is greater than the target lvl the first part will be skipped and strength will be done, etc.

Or do you want it so the user can specify the order?

EDIT: Actually I see what you want. Just a sec…

neG

2007-11-29 08:02:52

Well ive already made it so that the user enters what lvls they wish to achive, then the script detects which ones are less than that and trains it until it has reached the target.

But it always goes in the order Attack, Strength, Defence.
So if they set the Target Attack to 80, its probably never going to get round to trainging defence.

Thats why I want prioritising.
so if they go..

PriAttack = 3
PriStrength = 2
PriDefence = 1

It will train defense until the target lvl is reached, then strength, then attack.
Understand?

neG

2007-11-29 08:04:03

From: ZephyrsFury


Or do you want it so the user can specify the order?

EDIT: Actually I see what you want. Just a sec…


Ya, so the user sets it :)

Bobarkinator

2007-11-29 08:19:58

I know what you need, but I have to go. If no one has posted when I get home, I will post it

Narcle

2007-11-29 08:29:42

I think this will work, u just need to change setstyle('') to the full word of att/str/def.


procedure FixStyle;
var
CAtt, CStr, CDef: Integer;
style:string;
begin
if not LoggedIn then Exit;
begin
CAtt := GetSkillLevel('attack');
CStr := GetSkillLevel('strength');
CDef := GetSkillLevel('defence');
if (AttackPriority < StrengthPriority) and
(AttackPriority < DefencePriority) and
(TargetAttack > CAtt) then style:='attack';
if (DefencePriority < StrengthPriority) and
(DefencePriority < AttackPriority) and
(TargetAttack > CDef) then style:='defence';
if (StrengthPriority < AttackPriority) and
(StrengthPriority < DefencePriority) and
(TargetAttack > CStr) then style:='strength';
if (TargetAttack <= CStr) and (TargetAttack <= CDef) and (TargetAttack <= CAtt) then
case random(3) of
1: style:='attack';
2: style:='defence';
3: style:='strength';
end;
begin
WriteLn(Capitalize(style)+' below target level.');
setstyle(style);
exit;
end;
end;
end;

neG

2007-11-29 08:33:34

Awesome! I think that will work!

I may edit out the part where you have if all the levels are > the targets then it will pick a random one. That might mess with peoples pures :) lol.

Thanks so much for your help!
You will be in the credits of the script.

Narcle

2007-11-29 09:44:33

From: neG
Awesome! I think that will work!

I may edit out the part where you have if all the levels are > the targets then it will pick a random one. That might mess with peoples pures :) lol.

Thanks so much for your help!
You will be in the credits of the script.


Yea I know it was just the idea that if all are false that it does something else. I also thought of this when I typed it out to you.

If you need any more help just PM me or msn msg me, fighters are becoming my specialty. :D

-Narcle

nielsie95

2007-11-29 12:39:40


case random(3) of
1: style:='attack';
2: style:='defence';
3: style:='strength';
end;

Random(3) ranges are 0..2 ;)

Narcle

2007-11-29 12:47:36

From: nielsie95

case random(3) of
1: style:='attack';
2: style:='defence';
3: style:='strength';
end;

Random(3) ranges are 0..2 ;)


Yeah yeah… I made it up in like 1 minute give me a break. :P

Santa_Clause

2007-11-29 17:09:48

function GetHighestPriority(Attack, Strength, Defence : Integer) : string;
begin
if Attack < Strength then
if Attack < Defence then
begin
Result := 'Attack';
Exit;
end;

if Strength < Attack then
if Strength < Defence then
begin
Result := 'Strength';
Exit;
end;

if Defence < Attack then
if Defence < Strength then
begin
Result := 'Defence';
Exit;
end;

Result := 'Unavailable';
end;

procedure FixStyle(AttackLevel, StrengthLevel, DefenceLevel : Integer);
LevelAttack := GetSkillLevel('Attack');
LevelStrength := GetSkillLevel('Strength');
LevelDefence := GetSkillLevel('Defence');

Style := GetHighestPriority(AttackPriority, StrengthPriority, DefencePriority);
case Lowercase(Style) of
'attack' : if TargetAttack > LevelAttack then
begin
SetStyle('Attack');
WriteLn('Set Combat Mode To Attack');
Exit;
end;

'strength' : if TargetStrength > LevelStrength then
begin
SetStyle('Strength');
WriteLn('Set Combat Mode To Strength');
Exit;
end;

'defence' : if TargetDefence > LevelDefence then
begin
SetStyle('Defence');
WriteLn('Set Combat Mode To Defence');
Exit;
end;

'unavailable' : case Random(3) of
0 : begin
SetStyle('Attack');
WriteLn('Set Combat Mode To Attack');
end;

1 : begin
SetStyle('Strength');
WriteLn('Set Combat Mode To Strength');
end;

2 : begin
SetStyle('Defence');
WriteLn('Set Combat Mode To Strength');
end;
end;
end;
end;

Mine's long…:o