Author Topic: Get PC User?  (Read 445 times)

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« on: April 27, 2012, 06:21:43 pm »


                Just wondering how/if there is a way to get the PC using the object running a script, eg a placeable can be used, and when used the PC using it is assigned to oPC, so that certain checks can be made. I was considering using the get closest creature thing but this is designed to be a multiplayer PW so i don't want one player to use the placeable and it affect a different one (If one PC is stood ontop of the Placable and another one slightly further away uses it)

So what should I do?
Any help is much appreciated.'=]'
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Get PC User?
« Reply #1 on: April 27, 2012, 06:44:44 pm »


               // Get the last object that used the placeable object that is calling this function.
// * Returns OBJECT_INVALID if it is called by something other than a placeable or
//   a door.
object GetLastUsedBy();
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #2 on: April 27, 2012, 06:46:53 pm »


               Ahah, I didn't notice that function, thanks. '=]'
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Get PC User?
« Reply #3 on: April 27, 2012, 06:49:48 pm »


               XD
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #4 on: April 27, 2012, 07:15:58 pm »


               Also, GetRacialType and GetclassByPosition, what type of variable do they return? because I've tried string, object and int and it's none of them, do i need to declare it a constant by putting const before it?
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Get PC User?
« Reply #5 on: April 27, 2012, 07:27:14 pm »


               Both functions return ints (row number in racialtype.2da/classes.2da). They are commonly used with RACIAL_TYPE_* and class_TYPE_* constants, ie:
if(GetRacialType(oPC) == RACIAL_TYPE_ELF)
if(GetclassByPosition(1, oPC) == class_TYPE_DRUID)
etc.
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #6 on: April 27, 2012, 07:44:16 pm »


               Yeah, it's just I'm trying to make this portal not work for Half orcs or half elves, or red dragon disciples or purple dragon knights, because they are not allowed on the map I'm making, due to the lore behind the map.
Okay thanks for the help '<img'> I think it should work now.
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #7 on: April 27, 2012, 07:50:11 pm »


               Oh also, both of these:
class_TYPE_DRAGON_DISCIPLE
class_TYPE_DRAGONDISCIPLE
exist as class type constants, so which would a PC Red dragon disciple use? I assume it would be DRAGON_DISCIPLE as that is the format used for all other classes(Underscore between each word) but I'm not sure.. the same applies to Dwarven defender, although I'm not using that one at the moment.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Get PC User?
« Reply #8 on: April 27, 2012, 09:08:30 pm »


               They are actually the same number so you can use either one. I'm not sure why there are 2 of several. Probably got re-added with another include script/library in one of the expansions.
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #9 on: April 27, 2012, 09:21:26 pm »


               Ah okay.. Hmm.. if my portal calls ActionJumpToLocation(lPortal); Will it jump the portal to "lPortal" or the PC User?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Get PC User?
« Reply #10 on: April 27, 2012, 10:11:48 pm »


               If you want the PC user to be the one jumping to location you would need to assign that command to thePC user:

void main()
{
    object oPortalUser = GetLastUsedBy();
    location lLocation;//= whatever;
    AssignCommand(oPortalUser, ActionJumpToLocation(lLocation));
}


If you tried it without the assign command nothing would happen since it would be the portal trying to jump and the portal can't do any jumping.
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #11 on: April 27, 2012, 10:16:05 pm »


               Right thanks, well i already have GetLastUsedBy assigned to object oPC (of course) so I'l just do that...
okay last thing, this is my script so far:

void main()
{
    effect eRedLight = EffectVisualEffect(VFX_FNF_PWKILL);
    effect eBluLight = EffectVisualEffect(VFX_FNF_TIME_STOP);
    int iRace, iRDD, iPDK, i;
    object oPC = GetLastUsedBy();
    if (GetRacialType(oPC) == RACIAL_TYPE_HALFELF || RACIAL_TYPE_HALFORC)
    {
        SendMessageToPC(oPC, "Sorry your race is not allowed on this map. (Do not use Half-Orc or Half-Elf)");
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eRedLight, oPC);
        iRace = 1;
    }
    else
    {
        i=0;
        for (i=0; i<4; i++)
        {

            if(GetclassByPosition(i, oPC) == class_TYPE_DRAGON_DISCIPLE)
            {
                SendMessageToPC(oPC, "Sorry Red Dragon Disciples are not allowed on this map");
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eRedLight, oPC);
                iRDD = 1;
            }
            else
            {
                if(GetclassByPosition(i, oPC) == class_TYPE_PURPLE_DRAGON_KNIGHT)
                {
                    SendMessageToPC(oPC, "Sorry Purple Dragon Knights are not allowed on this map");
                    ApplyEffectToObject(DURATION_TYPE_INSTANT, eRedLight, oPC);
                    iPDK = 1;
                }
            }

        }
    }
    if(iRace = 0)
    {
        if(iRDD = 0)
        {
            if(iPDK = 0)
            {
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eBluLight, oPC);
                object oPortal = GetWaypointByTag("portal");
                location lPortal = GetLocation(oPortal);
                AssignCommand(oPC, ActionJumpToLocation(lPortal));
           }
        }
    }
}
A bit messy I know, but here's my slight dilemma: I created a human dragon disciple to test it out, and it still only displayed the incorrect race message.
               
               

               


                     Modifié par Dylmani555, 27 avril 2012 - 09:17 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Get PC User?
« Reply #12 on: April 27, 2012, 10:46:56 pm »


               When doing multiple tests in an "if" you need to separate it out like so:

if (GetRacialType(oPC) == RACIAL_TYPE_HALFELF ||
    GetRacialType(oPC) == RACIAL_TYPE_HALFORC)
               
               

               


                     Modifié par GhostOfGod, 27 avril 2012 - 09:47 .
                     
                  


            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Get PC User?
« Reply #13 on: April 27, 2012, 10:56:04 pm »


               Well I made them completely seperate if statements.. and now, if I am not one of those 2 races or classes, nothing happens at all... Although thank you for that advice. It will help me in the future.. how many times can i do that in one if statement? could I make all 4 checks with 1 if statement by putting:
if(GetRacialType(oPC) != RACIAL_TYPE_HALFELF ||
  GetRacialType(oPC) != RACIAL_TYPE_HALFORC ||
  GetclassByPosition(1, oPC) != class_TYPE_DRAGONDISCIPLE ||
  GetclassByPosition(2, oPC) != class_TYPE_DRAGONDISCIPLE ||
  GetclassByPosition(3, oPC) != class_TYPE_DRAGONDISCIPLE ||
  GetclassByPosition(1, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT ||
  GetclassByPosition(2, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT ||
  GetclassByPosition(3, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT)
  {
      //Teleport script here
  }
? Or would that not work?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get PC User?
« Reply #14 on: April 28, 2012, 08:34:22 am »


               

Dylmani555 wrote...

Well I made them completely seperate if statements.. and now, if I am not one of those 2 races or classes, nothing happens at all... Although thank you for that advice. It will help me in the future.. how many times can i do that in one if statement? could I make all 4 checks with 1 if statement by putting:
if(GetRacialType(oPC) != RACIAL_TYPE_HALFELF ||
GetRacialType(oPC) != RACIAL_TYPE_HALFORC ||
GetclassByPosition(1, oPC) != class_TYPE_DRAGONDISCIPLE ||
GetclassByPosition(2, oPC) != class_TYPE_DRAGONDISCIPLE ||
GetclassByPosition(3, oPC) != class_TYPE_DRAGONDISCIPLE ||
GetclassByPosition(1, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT ||
GetclassByPosition(2, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT ||
GetclassByPosition(3, oPC) != class_TYPE_PURPLE_DRAGON_KNIGHT)
{
//Teleport script here
}
? Or would that not work?


Will not work.
Let me explain what is going on.   The 'if' statment takes a expression that evaluates down to a single integer.  So yes since it is an expression you can make it as complex and with as many operators as you like.   Now if the expression evalulates to 0 (zero)  it the expression is FALSE.  if the expression evalulates to anything other then 0 the expression is concidered to be true.   


Now lets just look at the first part of your expression.  

GetRacialType(oPC) != RACIAL_TYPE_HALFELF ||
GetRacialType(oPC) != RACIAL_TYPE_HALFORC

The || ( logical OR operator)  has lower precedence then the != ( Not Equal Operator). Therefore  the NotEqualOperators (!=) will be evalulated before the Logical OR's ( || ).   Just like in normal math  addition ( + ) has lower precedence then  multiplucation (*)  where multication take place befor additions. 
The equation 
3*4 + 2*2   would have the multication take place first to get 
=12 + 4, then the addition would take place to get a result of
=16. 

We have the same basic principle here the operators are just different.  Instead of the + and * operators  you are using the != and || operators.   

lets look closer at the parts.

 The != operator compairs the right and left for equality and Evaluates to the  inverse, That is 0 if they are equal and 1 if they are not.

The Logical OR Operator ( || )  compairs the Right and the Left  and evalulates to  Zero ( FALSE) if both the right and left of the operator is FALSE ( 0 ) .   If either side is True ( Not zero) the operation evalulates out to be TRUE ( 1 )   

GetRacialType(oPC)  is a function that evalulates to an intenger that is the index into racialtypes.2da that represents the Race that the object oPC is.   Functions also have a higher precedence then both the  Logical OR operator ( || ) and the Not Equal Operator ( != ) . Therefore it will be evalulated before both of them. 

the constants  RACIAL_TYPE_HALFELF and  RACIAL_TYPE_HALFORC  are Lables that represent indexes into racialtypes.2da. This is just like Pi in math where Pi is a lable that represents the number 3.14.  In this case we have  RACIAL_TYPE_HALFELF which is the number 4 ( line 4 in racialtypes.2da is  half elf) and  RACIAL_TYPE_HALFORC which is the number 5 ( five being the line for half- orc). 
 

now looking at the first part of your expression  
 
we have: 

GetRacialType(oPC) != RACIAL_TYPE_HALFELF || GetRacialType(oPC) != RACIAL_TYPE_HALFORC

we evalulate out the functions first.  since we do not know what it is we will just give it a lable and call it nRace for now.  we can also replace the constants with there actual values, The lables a actualy replaced with there valules befor the script is even ran.  They are replaced with the valules when the script is compiled.     

nRace != 4 || nRace != 5  

The next thing to be evalulated will be the != operators.    lets assume that the race of oPC was human (line 6 in RactialTypes.2da.  we would get. 

6 != 4 || 6  != 5   // well 6 is not equal to 4 or 5 so both evalulate out to be TRUE or (1).
1 ||  1                // Same thing as saying  TRUE || TRUE  since at least one of them is True  (Not Zero)   the || operator  evalulates to be TRUE. 
 

Ok lets say that nRace was 4 ( HalfElf) 
4 != 4 || 4 != 5  // in this case  4 != 4  evalulates to FALSE(0) since they are equal and 4 !=5 evalulates to TRUE(1)
 0 || 1          // since one of them is True ( Not Zero)  the || operator evalulates to TRUE. 
TRUE(1) 

So basicly there is no number that can be retrived by GetRacialType(oPC) that will be able to evalulate as FALSE  to  being  Not Equal to both 4 and 5.  Therefore your expression will always evalulate as TRUE reguardless of what race oPC is.