Author Topic: GetFirstFactionMember, GetFirstPC or GetNearestCreature?  (Read 439 times)

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« on: September 27, 2011, 03:39:23 am »


                Hi all,

In the process of coding an as fast, as clean as possible custom xp system, I'm wondering wich approach would be the most cpu-friendly, knowing that the distance of party members does not count as long as they're in the same area as the killer(or victim):

- Loop through all party members and check if the area matches the killer's. (using GetFirstFactionMember)
- Loop through all PCs on server and check if they're in same party and same area as the killer. (using GetFirstPC)
- Loop through all PCs in killer's area and check if they're in party. (using GetNearestCreature)

Any thoughts?

Thank you!

Kato
               
               

               


                     Modifié par Kato_Yang, 27 septembre 2011 - 03:04 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #1 on: September 27, 2011, 04:52:17 am »


               GetFirstFactionMember has the setting to only return PCs, meaning that you only have to check if the area matches then.
 With GetFirstPC you'd have to check both area and if they're faction equals.

 In theory, one less operation should mean that checking by faction is marginally faster.
 I can't see GetNearestCreature being in any way efficient when compared to the other two, since it would have to build the object list first, by checking every applicable creature in the area and doing comparative distance checks, and the other two checks should be working off already generated object lists.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #2 on: September 27, 2011, 06:48:46 am »


               I think by you knocking out distance checks would probably increase performance quite a bit...

A Loop is a loop, so you really aren't going to increase performance substantially there, no matter which loop you decide on using...

The CR Check Thing would probably be the most important thing to pull off, so, in case you need it, here is a function you may want to use....

//////////////////////////////////////////////////////////////////////////
// GetLevelByXP(object oTarget)

// This Function will return the PC's Level based upon the XP
// I Made this incase someone wanted to find out how many levels
// the PC was based upon the XP..
//Added Functions for Higher Grounds Legendary Leveler..

int GetLevelByXP(object oTarget)
{
int i = 1; //No matter what return level 1!
int nXP = GetXP(oTarget);
int nCurrentXP = nXP;

if(nXP<=999) //They are IN FACT Level 1 (There is no Level 0!)
{ i = 1; }
else if(nXP >= 1000 && nXP <=2999) // level 2
{ i = 2; }
else if(nXP >= 3000 && nXP <=5999) // level 3
{ i = 3; }
else if(nXP >= 6000 && nXP <=9999) // level 4
{ i = 4; }
else if(nXP >= 10000 && nXP <=14999) // level 5
{ i = 5; }
else if(nXP >= 15000 && nXP <=20999) // level 6
{ i = 6; }
else if(nXP >= 21000 && nXP <=27999) // level 7
{ i = 7; }
else if(nXP >= 28000 && nXP <=35999) // level 8
{ i = 8; }
else if(nXP >= 36000 && nXP <=44999) // level 9
{ i = 9; }
else if(nXP >= 45000 && nXP <=54999) // level 10
{ i = 10; }
else if(nXP >= 55000 && nXP <=65999) // level 11
{ i = 11; }
else if(nXP >= 66000 && nXP <=77999) // level 12
{ i = 12; }
else if(nXP >= 78000 && nXP <=90999) // level 13
{ i = 13; }
else if(nXP >= 91000 && nXP <=104999) // level 14
{ i = 14; }
else if(nXP >= 105000 && nXP <=119999) // level 15
{ i = 15; }
else if(nXP >= 120000 && nXP <=135999) // level 16
{ i = 16; }
else if(nXP >= 136000 && nXP <=152999) // level 17
{ i = 17; }
else if(nXP >= 153000 && nXP <=170999) // level 18
{ i = 18; }
else if(nXP >= 171000 && nXP <=189999) // level 19
{ i = 19; }
else if(nXP >= 190000 && nXP <=209999) // level 20
{ i = 20; }
else if(nXP >= 210000 && nXP <=230999) // level 21
{ i = 21; }
else if(nXP >= 231000 && nXP <=262999) // level 22
{ i = 22; }
else if(nXP >= 263000 && nXP <=275999) // level 23
{ i = 23; }
else if(nXP >= 276000 && nXP <=299999) // level 24
{ i = 24; }
else if(nXP >= 300000 && nXP <=324999) // level 25
{ i = 25; }
else if(nXP >= 325000 && nXP <=350999) // level 26
{ i = 26; }
else if(nXP >= 351000 && nXP <=377999) // level 27
{ i = 27; }
else if(nXP >= 378000 && nXP <=405999) // level 28
{ i = 28; }
else if(nXP >= 406000 && nXP <=434999) // level 29
{ i = 29; }
else if(nXP >= 435000 && nXP <=464999) // level 30
{ i = 30; }
else if(nXP >= 465000 && nXP <=495999) // level 31
{ i = 31; }
else if(nXP >= 496000 && nXP <=527999) // level 32
{ i = 32; }
else if(nXP >= 528000 && nXP <=560999) // level 33
{ i = 33; }
else if(nXP >= 561000 && nXP <=594999) // level 34
{ i = 34; }
else if(nXP >= 595000 && nXP <=629999) // level 35
{ i = 35; }
else if(nXP >= 630000 && nXP <=665999) // level 36
{ i = 36; }
else if(nXP >= 666000 && nXP <=702999) // level 37
{ i = 37; }
else if(nXP >= 703000 && nXP <=740999) // level 38
{ i = 38; }
else if(nXP >= 741000 && nXP <780000) // level 39
{ i = 39; }
else if(nXP >= 780000 && nXP <XP_REQ_LVL41) //Handle level 40
{ i = 40; }

//Handle Legendary Levels (High Ground's System)

else if(nCurrentXP>=XP_REQ_LVL41 && nCurrentXP<XP_REQ_LVL42)
{ i = 41; }
else if(nCurrentXP>=XP_REQ_LVL42 && nCurrentXP<XP_REQ_LVL43)
{ i = 42; }
else if(nCurrentXP>=XP_REQ_LVL43 && nCurrentXP<XP_REQ_LVL44)
{ i = 43; }
else if(nCurrentXP>=XP_REQ_LVL44 && nCurrentXP<XP_REQ_LVL45)
{ i = 44; }
else if(nCurrentXP>=XP_REQ_LVL45 && nCurrentXP<XP_REQ_LVL46)
{ i = 45; }
else if(nCurrentXP>=XP_REQ_LVL46 && nCurrentXP<XP_REQ_LVL47)
{ i = 46; }
else if(nCurrentXP>=XP_REQ_LVL47 && nCurrentXP<XP_REQ_LVL48)
{ i = 47; }
else if(nCurrentXP>=XP_REQ_LVL48 && nCurrentXP<XP_REQ_LVL49)
{ i = 48; }
else if(nCurrentXP>=XP_REQ_LVL49 && nCurrentXP<XP_REQ_LVL50)
{ i = 49; }
else if(nCurrentXP>=XP_REQ_LVL50 && nCurrentXP<XP_REQ_LVL51)
{ i = 50; }
else if(nCurrentXP>=XP_REQ_LVL51 && nCurrentXP<XP_REQ_LVL52)
{ i = 51; }
else if(nCurrentXP>=XP_REQ_LVL52 && nCurrentXP<XP_REQ_LVL53)
{ i = 52; }
else if(nCurrentXP>=XP_REQ_LVL53 && nCurrentXP<XP_REQ_LVL54)
{ i = 53; }
else if(nCurrentXP>=XP_REQ_LVL54 && nCurrentXP<XP_REQ_LVL55)
{ i = 54; }
else if(nCurrentXP>=XP_REQ_LVL55 && nCurrentXP<XP_REQ_LVL56)
{ i = 55; }
else if(nCurrentXP>=XP_REQ_LVL56 && nCurrentXP<XP_REQ_LVL57)
{ i = 56; }
else if(nCurrentXP>=XP_REQ_LVL57 && nCurrentXP<XP_REQ_LVL58)
{ i = 57; }
else if(nCurrentXP>=XP_REQ_LVL58 && nCurrentXP<XP_REQ_LVL59)
{ i = 58; }
else if(nCurrentXP>=XP_REQ_LVL59 && nCurrentXP<XP_REQ_LVL60)
{ i = 59; }
else if(nCurrentXP>=XP_REQ_LVL60)
{ i = 60; }


return i;

//End Prototype
}
               
               

               


                     Modifié par _Guile, 27 septembre 2011 - 09:55 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #3 on: September 27, 2011, 08:44:46 am »


               For levels 1-40 you can just use this script:

///////////////////////////////////////////////////////////////////////////////
// By th1ef
// GetHitDiceByXP
//  HitDice is determined by player's xp, not by whether or not they have
//   leveled
//  Solve for hd from xp = hd * (hd - 1) * 500
//   hd = 1/50 * (sqrt(5) * sqrt(xp + 125) + 25)
int GetHitDiceByXP(object oCreature)
{
  float fXP = IntToFloat(GetXP(oCreature));
  return FloatToInt(0.02f * (sqrt(5.0f) * sqrt(fXP + 125.0f) + 25.0f));
}


 That's the only non-bioware script I use in my mod that I didn't write myself.  There is a definate advantage to determining the level by XP and not the level they've taken, since it gets rid of an exploit that most custom XP systems seem to have, that the vanilla XP system doesn't.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #4 on: September 27, 2011, 10:54:12 am »


               That's a nice script Failed.Bard, however could you make a reverse of that, where you get XP by Level??  I have a level 1-100 version of both (God Level System), but wanted to see a level 40 reverse version of the above script.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #5 on: September 27, 2011, 12:42:20 pm »


               int nMinXP = nLevel*(nLevel-1)*500);
int nMaxXP = nLevel*(nLevel+1)*500-1);

I think those should do it.  int nXP = nLevel*(nLevel-1)*500-1);   is what you use to find 1 XP below the minimum for delevelling just the last level. Those are just based on it.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #6 on: September 27, 2011, 01:34:17 pm »


               

Failed.Bard wrote...

int nMinXP = nLevel*(nLevel-1)*500);
int nMaxXP = nLevel*(nLevel+1)*500-1);

I think those should do it. int nXP = nLevel*(nLevel-1)*500-1);is what you use to find 1 XP below the minimum for delevelling just the last level. Those are just based on it.


Your -1 is in the wrong spot.  It needs to be after the )
int nMaxXP = nLevel*(nLevel+1)*500 -1;

Opps,  nope just get rid of the ')'  in the other one also.

int nMinXP = nLevel*(nLevel-1)*500;
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #7 on: September 27, 2011, 01:38:49 pm »


               http://social.biowar...3174344#3174344 - I created some XP related functions and posted them there, shame that thread didnt make it into stickied topics
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #8 on: September 27, 2011, 02:11:43 pm »


               

Lightfoot8 wrote...

Failed.Bard wrote...

int nMinXP = nLevel*(nLevel-1)*500);
int nMaxXP = nLevel*(nLevel+1)*500-1);

I think those should do it. int nXP = nLevel*(nLevel-1)*500-1);is what you use to find 1 XP below the minimum for delevelling just the last level. Those are just based on it.


Your -1 is in the wrong spot.  It needs to be after the )
int nMaxXP = nLevel*(nLevel+1)*500 -1;

Opps,  nope just get rid of the ')'  in the other one also.

int nMinXP = nLevel*(nLevel-1)*500;


ah.    Copy/paste error there, really.  I pulled it out of a set xp function and didn't notice I'd left in that last bracket.  What this forum needs is a script box with a compiler for checking that sort of thing.  That'd really make it much easier to troubleshoot posted scripts/snippets.
               
               

               


                     Modifié par Failed.Bard, 27 septembre 2011 - 01:12 .
                     
                  


            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
GetFirstFactionMember, GetFirstPC or GetNearestCreature?
« Reply #9 on: September 27, 2011, 05:21:11 pm »


               Thanks everyone for the infos!