Page 1 of 1

return if problem

Posted: Fri Sep 05, 2008 5:54 pm
by Gigabyte
Ive been making a booster script boost skills for each class. Rather than getting a player having to click all the skills he wishes.

Code: Select all

/////////////////
// Boost Script
use uo;
use cfgfile;
use os;
use util;
include "include/client";
include "include/objtype";
include "include/utility";
include "include/attributes";

program boost ( who )


/*if(GetObjProperty( who, "Boosted"))
	SendSysMessage( who, "You have already chosen a class. If this is an error, Plaese Page a GM member!");
return;
else
	SendSysMessage( who, "Choose your characters Specific Class");
	Setobjproperty( who, "Boosted", 1 );
endif*/

var input;

var choicelayout :=
    {
    "noclose",
    "nodispose",
    "nomove", 
    "page 0",
    "resizepic 10 10 3600 300 250",
    "text 30 30 1200 0",
    "button 30 70 2103 2104 1 0 1",
    "text 45 65 500 1",
    "button 30 95 2103 2104 1 0 2",
    "text 45 90 500 2",
    "button 30 120 2103 2104 1 0 3",
    "text 45 115 500 3",
    "button 30 145 2103 2104 1 0 4",
    "text 45 140 500 4",
    "button 30 170 2103 2104 1 0 5",
    "text 45 165 500 5",
    "button 30 195 2103 2104 1 0 6",
    "text 45 190 500 6", 
    "button 30 220 2103 2104 1 0 7",
    "text 45 215 500 7"     
    };

     var choicedata :=
    {
    "bard",
    "crafter",
    "mage",
    "power player",
    "ranger",
    "warrior",
    "thief"
    };
     var name :=
     {
     "Please select your 'Class' to Rule ZHA:",
    "Bard",
    "Crafter",
    "Mage",
    "Power Player",
    "Ranger",
    "Warrior",
    "Thief"
    };
   
  
    input := SendDialogGump( who, choicelayout, name);
var choice;
foreach key in choice
	choice:= key;
endforeach
    
	var output;
	case( choice[0] )
		1: output:=choicedata[1];
    		2: output:=choicedata[2];
		3: output:=choicedata[3];
		4: output:=choicedata[4];
		5: output:=choicedata[5];
		6: output:=choicedata[6];
		7: output:=choicedata[7];
endcase

if("bard")

	SetAttributeBaseValue(who, ATTRIBUTEID_TASTEID	, 90 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_PROVOCATION	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_PEACEMAKING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_MUSICIANSHIP	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_HERDING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_ENTICEMENT	, 95 * 10);	
	SetAttributeBaseValue(who, ATTRIBUTEID_CARTOGRAPHY	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_BEGGING	, 100 * 10);
endif
if("crafter")
	
	SetAttributeBaseValue(who, ATTRIBUTEID_ARMSLORE	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_BLACKSMITHY	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_BOWCRAFT	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_CARPENTRY	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_LUMBERJACKING	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_MINING	, 100 * 10);	
	SetAttributeBaseValue(who, ATTRIBUTEID_TAILORING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_TINKERING	, 80 * 10);
  
endif
if("mage")
	
	SetAttributeBaseValue(who, ATTRIBUTEID_ALCHEMY	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_EVALINT	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_INSCRIPTION	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_ITEMID	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_MAGERY	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_MEDITATION	, 80 * 10);	
	SetAttributeBaseValue(who, ATTRIBUTEID_MAGICRESISTANCE	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_SPIRITSPEAK	, 100 * 10);

endif
if("power player")
// Another way is running if crafter, mage etc
// Set all skills to #

	SendSysMessage( who, "All yours skills are now at 80" );
	SetAttributeBaseValue(who, ATTRIBUTEID_FORENSICS	, 80 * 10);

endif
if("ranger")
	
	SetAttributeBaseValue(who, ATTRIBUTEID_ANIMALLORE	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_ARCHERY	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_TAMING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_CAMPING	, 70 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_COOKING	, 105 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_FISHING	, 100 * 10);	
	SetAttributeBaseValue(who, ATTRIBUTEID_TRACKING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_VETERINARY	, 90 * 10);
endif
if("warrior")

	SetAttributeBaseValue(who, ATTRIBUTEID_ANATOMY	, 100 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_HEALING	, 100 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_MACEFIGHTING	,  100 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_PARRY	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_SWORDSMANSHIP	, 100 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_TACTICS	, 80 * 10);	
	SetAttributeBaseValue(who, ATTRIBUTEID_WRESTLING	, 90 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_FENCING	, 100 * 10);

endif
if("thief")

	SetAttributeBaseValue(who, ATTRIBUTEID_DETECTINGHIDDEN	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_LOCKPICKING	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_HIDING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_REMOVETRAP	, 95 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_SNOOPING	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_STEALING	, 80 * 10);	
	SetAttributeBaseValue(who, ATTRIBUTEID_STEALTH	, 80 * 10);
	SetAttributeBaseValue(who, ATTRIBUTEID_POISONING	, 100 * 10);

endif

    SetAttributeBaseValue(who, ATTRIBUTEID_DEXTERITY	, 95 * 10);
    SetAttributeBaseValue(who, ATTRIBUTEID_INTELLIGENCE, 95 * 10);
    SetAttributeBaseValue(who, ATTRIBUTEID_STRENGTH, 95 * 10);
    DoRecalcVitals(who);
    SetHp(who, GetMaxHp(who));
    SetMana(who, GetMaxMana(who));
    SetStamina(who, GetMaxStamina(who));


endprogram
The problem atm is its boosting all if statement skills.
My scripting knowledge is limited but a fast learner. but this had got me stumped.

Thanks if anyone can help me.

Re: return if problem

Posted: Fri Sep 05, 2008 7:00 pm
by Austin
youre missing break; statements after each case

Code: Select all

case( choice[0] )
      1: output:=choicedata[1];
          2: output:=choicedata[2];
      3: output:=choicedata[3];
      4: output:=choicedata[4];
      5: output:=choicedata[5];
      6: output:=choicedata[6];
      7: output:=choicedata[7];
Your if statements will always be true, as theyre not comparing anything

if("bard")

should be something like if ( output == "bard" ) or what ever it is youre trying to compare.

Re: return if problem

Posted: Sat Sep 06, 2008 2:50 am
by ncrsn
Break; is a neat way to do it, but not always necessary.

Code: Select all

case (0)
   0: print("0");
   1: print("1");
endcase
Only prints "0".

If, on the other hand, one don't have anything in the block, break is required, as without it..

Code: Select all

case (0)
   0: // Do nothing, wrong way
   1: print("1");
endcase
Will print "1".

To sum it up, then.

Code: Select all

case (0)
    0: // Do nothing, correct way
        break;
    1: print("1");
endcase
Will print nothing.

Re: return if problem

Posted: Sat Sep 06, 2008 6:39 am
by Yukiko
Basically your 'if' statements need a variable to compare to the quoted string.

So if your character chose Bard as her class and the choice is stored in the variable classchosen then the 'if statement would read:

if(classchosen == "Bard")
thus you are testing the value of the variable against another value and now POL can evaluate that to either True (1) or False (0).

When you use:

if("Bard")
It is just like saying:
if(25)
POL will always evaluate those as true since there is something greater than zero inside the parenthesis.

Hope that helps.

Re: return if problem

Posted: Sat Sep 06, 2008 10:37 am
by Luth
Austin wrote:youre missing break; statements after each case
This threw me for the longest time learning eScript. It seems that switch-statement fall-through (or in this language, case-statement fall-through) is only allowed when the prior entry has no executable code, as ncrsn said.

Code: Select all

case(i)
  -1:
  0:  DoFunc();
  1:  DoNextFunc();
endcase

-- is the same as --
case(i)
  -1:
  0: DoFunc();
      break;
  1:  DoNextFunc();
      break;
... and coming from a C-language, that confused the hell out of me. >_<

Re: return if problem

Posted: Sat Sep 06, 2008 9:15 pm
by CWO
I love that way in eScript too. In fact, I just love the way case statements are done in eScript altogether. They're more of a hassle in Delphi.

Re: return if problem

Posted: Sun Sep 07, 2008 12:27 am
by Yukiko
I want to second CWOs comment about eScript's 'case' versus Delphi's or in my case Lazarus'.

It has been ages since I used Pascal and I was surprised to find that I cannot pass a string through a case conditional in Pascal, only ordinal types are allowed. I obviously must have forgotten that in the years since I did any programming in Pascal.

So thank you to Eric and anyone else responsible for that nicety.

I seem to have understood the no code oddity in eScript case statements, most likely from examples I've seen where several values are supposed to perform the same task as in:

Code: Select all

var z := 0;

{Do someting where we get a new value for 'z'}

case(z)
       0:
       1:
       2: Do_The_Same_Thing_For_All_Values_From_0_through_2();
       3: PerformAction();
       4: PerformAnotherAction();
endcase
In any case I do like eScript a lot.
*grins*