Aller au contenu

Photo

Get PC User?


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

#1
Dylmani555

Dylmani555
  • Members
  • 48 messages
 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.=]

#2
Alex Warren

Alex Warren
  • Members
  • 179 messages
// 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();

#3
Dylmani555

Dylmani555
  • Members
  • 48 messages
Ahah, I didn't notice that function, thanks. =]

#4
Alex Warren

Alex Warren
  • Members
  • 179 messages
XD

#5
Dylmani555

Dylmani555
  • Members
  • 48 messages
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?

#6
Alex Warren

Alex Warren
  • Members
  • 179 messages
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.

#7
Dylmani555

Dylmani555
  • Members
  • 48 messages
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 :D I think it should work now.

#8
Dylmani555

Dylmani555
  • Members
  • 48 messages
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.

#9
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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.

#10
Dylmani555

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

#11
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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.

#12
Dylmani555

Dylmani555
  • Members
  • 48 messages
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 .


#13
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#14
Dylmani555

Dylmani555
  • Members
  • 48 messages
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?

#15
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.  

    

 

#16
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Dylmani555 wrote...

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 :D I think it should work now.



Ok there  is a better function then the GetclassBy Position that you are currently using.  It is the GetLevelByclass function.  With it you will only need to check if the level returned is greater then 0 to know if the have taken the calss ot not.   That with what we learned above and your If statment can be rewritten as.  

if(
  GetRacialType(oPC)  ==  RACIAL_TYPE_HALFELF ||
  GetRacialType(oPC)  ==  RACIAL_TYPE_HALFORC ||
  GetLevelByclass(class_TYPE_DRAGONDISCIPLE, oPC) > 0   ||
  GetLevelByclass(class_TYPE_DRAGONDISCIPLE , oPC) > 0 ||
  )
  {
     // TRUE Case meaning one of the cases above was true. 
    // You did not want to transport this PC so do nothing.   
  }   
  else
{
    // False clause.   oPC wan not any of the checks above.  
   // This guy is safe to teleport.



As another option you can invert the return of the expression above by using the Not(!) operator.  You would just need to soround the entire expression with parentheses and apply the Not.   
!(expression)  

In that case you would have:

if(
    ! (     
       GetRacialType(oPC)  ==  RACIAL_TYPE_HALFELF ||
       GetRacialType(oPC)  ==  RACIAL_TYPE_HALFORC ||
       GetLevelByclass(class_TYPE_DRAGONDISCIPLE, oPC) > 0   ||
       GetLevelByclass(class_TYPE_DRAGONDISCIPLE , oPC) > 0 ||
     )
  )
  {
      // True Case the PC as not any of the casses above. 
     //  Safe to transport.
  }

Modifié par Lightfoot8, 28 avril 2012 - 07:55 .


#17
Dylmani555

Dylmani555
  • Members
  • 48 messages
Wow... Lightfoot.. you are a god among men! I do recall having used the GetLevelByclass function before, but did not think to use it here. Thank you for your help :D I appreciate it greatly.
Although I think it would be
if(
! (
GetRacialType(oPC) == RACIAL_TYPE_HALFELF ||
GetRacialType(oPC) == RACIAL_TYPE_HALFORC ||
GetLevelByclass(class_TYPE_DRAGONDISCIPLE, oPC) > 0 ||
GetLevelByclass(class_TYPE_PURPLE_DRAGON_KNIGHT , oPC) > 0
)
)
{
// True Case the PC as not any of the casses above.
// Safe to transport.
}

rather than

if(
! (
GetRacialType(oPC) == RACIAL_TYPE_HALFELF ||
GetRacialType(oPC) == RACIAL_TYPE_HALFORC ||
GetLevelByclass(class_TYPE_DRAGONDISCIPLE, oPC) > 0 ||
GetLevelByclass(class_TYPE_DRAGONDISCIPLE , oPC) > 0 ||
)
)
{
// True Case the PC as not any of the casses above.
// Safe to transport.
}

Modifié par Dylmani555, 28 avril 2012 - 07:53 .


#18
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Dylmani555 wrote...

Although I think it would be...

Image IPB

Modifié par Lightfoot8, 28 avril 2012 - 09:11 .