Aller au contenu

Photo

Giving items depending on class not working


  • Veuillez vous connecter pour répondre
11 réponses à ce sujet

#1
Dylmani555

Dylmani555
  • Members
  • 48 messages
Here's my code:
 
if (GetclassByPosition(1, oPC)) == class_TYPE_BARBARIAN(
        string sArmour = "hidearmour";
        string sWeapon = "battleaxe";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_BARD(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_CLERIC(
        string sArmour = "plainrobe";
        string sWeapon = "mace";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_DRUID(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_FIGHTER(
        string sArmour = "heavyleather";
        string sWeapon = "longsword";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_MONK(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_PALADIN(
        string sArmour = "chainmail";
        string sWeapon = "longsword";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_RANGER(
        string sArmour = "leatherarmour";
        string sWeapon = "longsword";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_ROGUE(
        string sArmour = "paddedcloth";
        string sWeapon = "dagger";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_SORCEROR(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_WIZARD(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    CreateItemOnObject(sArmour, oPC);
    CreateItemOnObject(sWeapon, oPC);
    CreateItemOnObject(medicinalherb, oPC);
    CreateItemOnObject(medicinalherb, oPC);
    CreateItemOnObject(medicinalherb, oPC);
}
Here's my problem, I get the error of "UNKNOWN STATE IN THE COMPILER" on the first line of this snippet, also whenever I enter, regardless of my class, I am given a plainrobe and a staff.

Whats going wrong? the variable names for the classes were taken directly from Lexicon.:crying:

#2
Dylmani555

Dylmani555
  • Members
  • 48 messages
By the way all of the caps in the class words are fine, it's just this forum is messed up and always puts it in no caps

#3
Dylmani555

Dylmani555
  • Members
  • 48 messages
Also, in case it's like some compilers where it shows the error on the line AFTER the line that is wrong, heres the line above this code snippet:
GiveGoldToCreature(oPC, 100);
thats right though isn't it?

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
if (GetclassByPosition(1, oPC)[color="#ff0000"])[/color] == class_TYPE_BARBARIAN[color="#ff0000"]([/color]
        string sArmour = "hidearmour";
        string sWeapon = "battleaxe";
)


Should be:

if (GetclassByPosition(1, oPC) == class_TYPE_BARBARIAN[color="#99cc00"])[/color]
[color="#99cc00"]{[/color]
        string sArmour = "hidearmour";
        string sWeapon = "battleaxe";
    [color="#99cc00"]}[/color]

;)

#5
Dylmani555

Dylmani555
  • Members
  • 48 messages
failure of epic proportions, thanks GhostOfGod, I'll fix that on all 12 or so If statements

#6
Dylmani555

Dylmani555
  • Members
  • 48 messages
damn, I did that.. but the error remains...

#7
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Did you also notice the change from parentheses to the curley brackets?

#8
Alex Warren

Alex Warren
  • Members
  • 179 messages
I think you should also declare your string variables before all 'if' statements:

string sArmour, sWeapon;
int nclass = GetclassByPosition(1, oPC);
if (nclass == class_TYPE_BARBARIAN)
{
sArmour = "hidearmour";
sWeapon = "battleaxe";
}
else if(nclass == class_TYPE_BARD)
{
sArmour = "plainrobe";
sWeapon = "staff";
}
etc.

#9
WhiZard

WhiZard
  • Members
  • 1 204 messages

Alex Warren wrote...

I think you should also declare your string variables before all 'if' statements:

string sArmour, sWeapon;
int nclass = GetclassByPosition(1, oPC);
if (nclass == class_TYPE_BARBARIAN)
{
sArmour = "hidearmour";
sWeapon = "battleaxe";
}
else if(nclass == class_TYPE_BARD)
{
sArmour = "plainrobe";
sWeapon = "staff";
}
etc.


I bet you nailed that one.  NWScript does allow for a variable name to be used multiple times,

e.g.

void main()
{
string sVar = "10";
if(TRUE)
  {
  string sVar = "5";
  SendMessageToPC(OBJECT_SELF, sVar);
  }
SendMessageToPC(OBJECT_SELF, sVar);
}

would send the messages of "5" and then "10".  The declaration inside the braces of the if clause {}overides the outside declaration only within those braces.

#10
Dylmani555

Dylmani555
  • Members
  • 48 messages
I thkn I know what it is, in the if statement, the second parenthises after the oPC variable.. I didn't remove it :P

#11
Dylmani555

Dylmani555
  • Members
  • 48 messages
Also I mis-spelt Sorcerer as Sorceror :P

#12
Dylmani555

Dylmani555
  • Members
  • 48 messages
Yup it all works now, thanks guys :)