Skip to content

GetLevelByClass()

ZephiriusZephirius Member Posts: 411
edited July 2022 in Builders - Scripting
Trying to figure out what's wrong with the structure of this script. It won't isoloate by class?
void main()
{
object oPC = GetClickingObject();
if (!GetIsPC(oPC)) return;

if ((GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC)>0)||
    (GetLevelByClass(CLASS_TYPE_DRUID, oPC)>0)||
    (GetLevelByClass(CLASS_TYPE_RANGER, oPC)>0))
    {
         // do cool stuff here
    }
}

Not sure why I can't single out the different classes...
Post edited by Zephirius on

Comments

  • meaglynmeaglyn Member Posts: 149
    That script won't do anything either way so how do you know? :)

    GetLevelByClass returns 0 for no or invalid class so you can just do
    if (GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC)
        || GetLevelByClass(CLASS_TYPE_DRUID, oPC)
        || GetLevelByClass(CLASS_TYPE_RANGER, oPC))
        {
            ...
    
    which is a bit simpler (personally I prefer the operator on that side so it's easier to see...). But what you have should "do cool stuff" if oPC has at least one level on one of those classes.

    Is it running from an event that has a ClickingObject? That is, is oPC valid?
  • ZephiriusZephirius Member Posts: 411
    I ended up having to use object oPC = GetPlaceableLastClickedBy(); - then it works fine
Sign In or Register to comment.