Author Topic: Comparing a local race string  (Read 520 times)

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Comparing a local race string
« on: August 22, 2011, 09:08:40 pm »


               I want a NPC to take a certain action based on a PC's race. The NPC has a local race variable, sRace.  The if script line for a race comparison might be

if ( GetRacialType(oPC) == RACIAL_TYPE_DWARF )

so what is the proper syntax for inserting the sRace variable in this if statement? (The string has been previously defined, of course).

Thanks!
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Comparing a local race string
« Reply #1 on: August 22, 2011, 09:31:31 pm »


               If you want to retrieve the race from sRace instead of from GetRacialType(), it would be:

if(sRace == RACIAL_TYPE_DWARF)

But is it what you're trying to do?

Kato
               
               

               


                     Modifié par Kato_Yang, 22 août 2011 - 08:32 .
                     
                  


            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Comparing a local race string
« Reply #2 on: August 22, 2011, 09:46:03 pm »


               Yup...

string sRace = GetRacialType(oPC);

if (sRace == RACIAL_TYPE_DWARF)
{
// Do Dwarf Stuff
}

else if (sRace == RACIAL_TYPE_ELF)
{
// Do Elf Stuff
}

else if ....
               
               

               
            

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Comparing a local race string
« Reply #3 on: August 23, 2011, 03:46:21 am »


               I have different racial towns and I want to use a common conversation that will do two different things based on whether the NPC is the same race as the PC. I did not want to create a special script to handle this, as I already have the scripts to perform the actions I have in mind.

The NPC would have a local variable of sRace. What I want is a conditional that if sRace = PC race then one action is taken, and if they are not equal then a different action is taken.

So what I'm trying to get at is

if ( GetRacialType(oPC) == RACIAL_TYPE_sRace )
               
               

               


                     Modifié par Badwater, 23 août 2011 - 03:59 .
                     
                  


            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Comparing a local race string
« Reply #4 on: August 23, 2011, 06:44:18 am »


               If I understand correctly sRace may be 'dwarf' 'elf' etc, right?

GetRacialType(oPC) returns an int so you can't compare it with string. You need a function that will convert your string to int, ie:
int MyRace(string sRace)
{
   if sRace == "dwarf" return RACIAL_TYPE_DWARF;
   else if sRace == "elf" return RACIAL_TYPE_ELF;
...

or you could just set sRace on PC in OnEnter event and than compare strings.
               
               

               
            

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Comparing a local race string
« Reply #5 on: August 23, 2011, 07:01:57 am »


               Argh. This is why I hate scripting. I know what I want, I just don't know how to get to it.

If I'm reading the above correctly, then I'm still not at a place where I have a conditional in conversation where the PC's race compares to the NPCs race or it doesn't. I guess it really doesn't matter whether it's comparing an integer or a string, I just want a local variable on the NPC where I can simply compare and the conversation goes in one direction or it goes in the other.
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Comparing a local race string
« Reply #6 on: August 23, 2011, 07:12:40 am »


               Ok, lets say you placed local strings on your NPCs. If you use MyRace function the code for conversation conditional should look like this:


int iNPCRace = MyRace(GetLocalString(oNPC, "NameOfVar"));
if(GetRacialType(oPC) == iNPCRace)

               
               

               


                     Modifié par Alex Warren, 23 août 2011 - 06:15 .
                     
                  


            

Legacy_Badwater

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Comparing a local race string
« Reply #7 on: August 23, 2011, 07:38:50 am »


               Thanks AW. I will give that a shot and see how badly I can screw it up. '<img'>
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Comparing a local race string
« Reply #8 on: August 23, 2011, 07:57:36 am »


               Something like this, if the other doesn't work for you, maybe?

int StartingConditional()
{
return (GetRacialType (GetPCSpeaker() ) == GetRacialType (GetLastSpeaker() ) );
}
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Comparing a local race string
« Reply #9 on: August 23, 2011, 02:58:19 pm »


               You cant compare an integer with a string.
RACIAL_TYPE_* is a integer.

Even if your sRace is "RACIAL_TYPE_DWARF" it will not match RACIAL_TYPE_DWARF that is outside quotation ("") marks, because the engine treats it as a number.

If you compare wrong types of variables the script shouldn't even compile.

if(sRace == "asdf") {}
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Comparing a local race string
« Reply #10 on: August 23, 2011, 04:48:57 pm »


               <Tossing in two coppers...>

Badwater wrote...

I have different racial towns and I want to use a common conversation that will do two different things based on whether the NPC is the same race as the PC. I did not want to create a special script to handle this, as I already have the scripts to perform the actions I have in mind.

The NPC would have a local variable of sRace. What I want is a conditional that if sRace = PC race then one action is taken, and if they are not equal then a different action is taken.

So what I'm trying to get at is

if ( GetRacialType(oPC) == RACIAL_TYPE_sRace )


You might just grab the NPC racial type:

if ( GetRacialType(oPC) == GetRacialType(OBJECT_SELF) ) ...

<...and stealing four>
               
               

               


                     Modifié par Rolo Kipp, 23 août 2011 - 03:51 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Comparing a local race string
« Reply #11 on: August 23, 2011, 10:58:24 pm »


               return Get2DAString("racailtypes","Constant",GetRacialType(oPC)) == sRace;
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Comparing a local race string
« Reply #12 on: August 23, 2011, 11:32:25 pm »


               <looking decidedly puzzled..>

If he just wants to compare PCs race to NPCs, why would you even mess with strings? Wouldn't

{
if ( GetRacialType(oPC) == GetRacialType(OBJECT_SELF) ) return TRUE;
return FALSE;
}

give him the conditional he wants without worrying about a variable on the NPC or pulling a string out of the 2da?

Not capping or anything. Really want to know.

<...but interested>
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Comparing a local race string
« Reply #13 on: August 24, 2011, 12:44:13 am »


               @Rolo Kipp:  Yes, but he seem to be fighting against that answer.   It is what he need to do, in my opionion also.   But if he really want to put the Lable for the constant into a local var  and check against that. *shrugs*  you might as well pull the lable out of the 2da.  They shure dont exsist in the engine anywhere.  So either redefine them,  Kind of defeats the perpose of them being constant.  Or get there deffinitions from the only place you can.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Comparing a local race string
« Reply #14 on: August 24, 2011, 12:47:20 am »


               <wipes persperishun...>

Ahhh, thank you. Thought I was missing something... again :-P

<...er, persp... *sweat* from his brow>