Author Topic: Restricting Player's Race and class [UPDATED]  (Read 921 times)

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« on: January 30, 2011, 01:31:19 am »


               I've read a couple similar requests, but I'm looking for something a little different.

I want to know if there's a way I can restrict which races and classes are choosable when you start
my campaign. Like if you wanted to create a module specifically built to be played by (say) a Human
Cleric. Is there a way to disable the other choices?

I'm not trying to restrict exactly how the player builds their character in terms of precise statistics, just
race and class.

Also, how do I determine exactly what items the PC starts with equipped and in their inventory? I don't
want to use the default values.

I'm very sorry if this has been covered a million times, I swear I've used the search feature.

So:

1. How can I restrict race and class choice?
2. How can I determine the player's starting equipment?
               
               

               


                     Modifié par Dylan RPG, 09 février 2011 - 06:41 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #1 on: January 30, 2011, 01:47:14 am »


               

Dylan RPG wrote...

1. How can I restrict race and class choice?
2. How can I determine the player's starting equipment?


1. You can't - at least directly, all initial build of PC is done on the player's computer - but you can read their PC and PORT them to an area (with no exits) where a sign can explain why they are there (dis-allowed race/class) and instruct them in what they need to make to play on your server.

2. you can unequip all their gear (assuming they pass the #1 above) and delete all gear, then give them what you want them to have.

All of this would be done in the 'on client enter' script.

Hope this helps.
               
               

               
            

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #2 on: January 30, 2011, 01:22:33 pm »


               Thanks for the tip. I have it working now so that the PC can only play the game as a certain race and class, although I did it solely through an area transition trigger set over the starting point, and not through the "on client enter" script.

Er, well I supposed when you said "on client enter" script, you meant in the module settings, but it now occurs to me that maybe you meant exactly what I did.

In any case, I'm finding figuring out unequipping and deleting the PC's gear and adding inventory to be more difficult. I'm very, very new at this and am relying very much on intuition.

Could you give me an example of how I might script the removal of starting gear?
               
               

               


                     Modifié par Dylan RPG, 30 janvier 2011 - 01:24 .
                     
                  


            

Legacy_cyberglum

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #3 on: January 30, 2011, 01:37:58 pm »


               Hi Dylan,

ehye_khandee's answers assume you're running a server which players are going to log into and play.

If you're creating a single player module simply editing the class .2da and putting it in a hak would do the trick.
This Link shows the various parameters in the class .2da. Scroll across to the Player class column and you see either a 1 or 0 defining if the player can play the class or not. 1=Player class, 0= No Player class.

Not sure how you'd restrict the races.
               
               

               


                     Modifié par cyberglum, 30 janvier 2011 - 02:03 .
                     
                  


            

Legacy_cyberglum

  • Jr. Member
  • **
  • Posts: 61
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #4 on: January 30, 2011, 02:00:39 pm »


               This goes Module>OnClientEnter. Strip the Player of all items and gold. Then you can set how much gold, what level you want them to start and which items they have. Its all commented in the script. Cut n' Paste into the toolset script editor makes them easier to read.

//::///////////////////////////////////////////////
//:: RemoveAllItems
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*   RemoveAllItems(object oPlayer)
     The function removes all items in inventory,
     equipped items and gold from oPlayer.
*/
//:://////////////////////////////////////////////
void RemoveAllItems(object oPlayer)
{
 if (GetIsPC(oPlayer) == TRUE)
 {
  // First remove equipped items.
  int i;
  for (i=0; i<14; i++)
  {
   object oEquip = GetItemInSlot(i, oPlayer);
   if(GetIsObjectValid(oEquip))
   {
    SetPlotFlag(oEquip, FALSE);
    DestroyObject(oEquip);
   }
  }
  // Second remove items in inventory.
  object oItem = GetFirstItemInInventory(oPlayer);
  while(GetIsObjectValid(oItem))
  {
   SetPlotFlag(oItem, FALSE);
   DestroyObject(oItem);
   oItem = GetNextItemInInventory(oPlayer);
  }
  // Finally remove all gold
  int nAmount = GetGold(oPlayer);
  if(nAmount > 0)
  {
   AssignCommand(oPlayer,TakeGoldFromCreature(nAmount, oPlayer, TRUE));
  }
 }
}

//::///////////////////////////////////////////////
//:: RemoveUberItems
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*   RemoveUberItems(object oPlayer)
     Remove items whit immunity properties.
*/
//:://////////////////////////////////////////////
//:: Created By: eldbane
//:: Created On: 2003
//:://////////////////////////////////////////////
void RemoveUberItems(object oPlayer)
{
 object oUber = GetFirstItemInInventory(oPlayer);
 while (GetIsObjectValid(oUber))
 {
  // Check for immunity items in inventory, remove if present.
  if (GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_DAMAGE_TYPE) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_SPECIFIC_SPELL) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_SPELL_SCHOOL) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_SPELLS_BY_LEVEL))
  {
   SetPlotFlag(oUber, FALSE);
   DestroyObject(oUber);
  }
  oUber = GetNextItemInInventory(oPlayer);
 }
 int i;
 for (i=0; i<14; i++)
 {
  object oUber = GetItemInSlot(i, oPlayer);
  // Check for equipped immunity items, remove if present.
  if (GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_DAMAGE_TYPE) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_MISCELLANEOUS) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_SPECIFIC_SPELL) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_SPELL_SCHOOL) ||
      GetItemHasItemProperty(oUber, ITEM_PROPERTY_IMMUNITY_SPELLS_BY_LEVEL))
  {
   SetPlotFlag(oUber, FALSE);
   DestroyObject(oUber);
  }
 }
}

//::///////////////////////////////////////////////
//:: SetEnterLevel
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*   SetEnterLevel(object oPlayer, int iLevel)
     Checks the level of oPlayer and raise it to
     iLevel if it is below iLevel.
*/
//:://////////////////////////////////////////////
//:: Created By: eldbane
//:: Created On: 2003
//:://////////////////////////////////////////////
void SetEnterLevel(object oPlayer, int iLevel)
{
 int iPClvl = GetHitDice(oPlayer);
 int iPCxp = GetXP(oPlayer);
 // Check if oPlayer needs to be boosted.
 if (iPClvl < iLevel)
 {
  // Calculate xp requred for iLevel
  int iLevelXP = (500*iLevel*(iLevel-1));
  // Calculate xp to give.
  int iGiveXP = ((iLevelXP - iPCxp)+1);
  // Give xp to oPlayer.
  GiveXPToCreature(oPlayer, iGiveXP);
 }
}

//::///////////////////////////////////////////////
//:: GiveEnterItem
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*   GiveEnterItem(object oPlayer, string sItem)
     Give Item with ResRef (blueprint) sItem to
     oPlayer if oPlayer do not have it.
*/
//:://////////////////////////////////////////////
//:: Created By: eldbane
//:: Created On: 2003
//:://////////////////////////////////////////////
void GiveEnterItem(object oPlayer, string sItem)
{
 // Check if oPlayer already have item.
 object oItemPC = GetFirstItemInInventory(oPlayer);
 int iNoItem = 1;
 while (GetIsObjectValid(oItemPC))
 {
  if ((GetResRef(oItemPC) == sItem) || (GetTag(oItemPC) == sItem))
   iNoItem = 0;
  oItemPC = GetNextItemInInventory(oPlayer);
 }
 int i;
 for (i=0; i<14; i++)
 {
  object oEquipPC = GetItemInSlot(i, oPlayer);
  if ((GetResRef(oEquipPC) == sItem) || (GetTag(oEquipPC) == sItem))
   iNoItem = 0;
 }
 // Give item and make sure it is identified
 if (iNoItem == 1)
 {
  object oItem = CreateItemOnObject(sItem, oPlayer);
  SetIdentified(oItem, TRUE);
 }
}

//::///////////////////////////////////////////////
//:: GiveEnterGold
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*   GiveEnterGold(object oPlayer, int iAmount)
     Check if oPlayer have less then iAmount gold
     if so oPlayer gold is set to iAmount.
*/
//:://////////////////////////////////////////////
//:: Created By: eldbane
//:: Created On: 2003
//:://////////////////////////////////////////////
void GiveEnterGold(object oPlayer, int iAmount)
{
 int iGoldPC = GetGold(oPlayer);
 // Check if oPlayer have enough gold.
 if (iGoldPC < iAmount)
 {
  int iGiveGold = (iAmount - iGoldPC);
  // If not give gold
  GiveGoldToCreature(oPlayer, iGiveGold);
 }
}

//::///////////////////////////////////////////////
//:: EquipEnterItem
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*   EquipEnterItem(object oPlayer, string sItemTag)
     Checks if oPlayer possesses item with the tag
     sItemTag and equip it.
*/
//:://////////////////////////////////////////////
//:: Created By: eldbane
//:: Created On: 2003
//:://////////////////////////////////////////////
void EquipEnterItem(object oPlayer, string sItemTag)
{
 object oItem = GetObjectByTag(sItemTag);
 // Check if oPlayer have item.
 if (GetItemPossessor(oItem) == oPlayer)
 {
  // Get the item type and equip the item.
  int iType = GetBaseItemType(oItem);
  int iSlot;
  if ((iType == BASE_ITEM_LARGESHIELD) || (iType == BASE_ITEM_SMALLSHIELD)
      || (iType == BASE_ITEM_TOWERSHIELD) || (iType == BASE_ITEM_TORCH))
   iSlot = INVENTORY_SLOT_LEFTHAND;
  else if (iType == BASE_ITEM_ARMOR)
   iSlot = INVENTORY_SLOT_CHEST;
  else if ((iType == BASE_ITEM_BRACER) || (iType == BASE_ITEM_GLOVES))
   iSlot = INVENTORY_SLOT_ARMS;
  else if (iType == BASE_ITEM_ARROW)
   iSlot = INVENTORY_SLOT_ARROWS;
  else if (iType == BASE_ITEM_AMULET)
   iSlot = INVENTORY_SLOT_NECK;
  else if (iType == BASE_ITEM_BOLT)
   iSlot = INVENTORY_SLOT_BOLTS;
  else if (iType == BASE_ITEM_BELT)
   iSlot = INVENTORY_SLOT_BELT;
  else if (iType == BASE_ITEM_BOOTS)
   iSlot = INVENTORY_SLOT_BOOTS;
  else if (iType == BASE_ITEM_BULLET)
   iSlot = INVENTORY_SLOT_BULLETS;
  else if (iType == BASE_ITEM_CLOAK)
   iSlot = INVENTORY_SLOT_CLOAK;
  else if (iType == BASE_ITEM_HELMET)
   iSlot = INVENTORY_SLOT_HEAD;
  else if (iType == BASE_ITEM_RING)
   iSlot = INVENTORY_SLOT_RIGHTRING;
  else
   iSlot = INVENTORY_SLOT_RIGHTHAND;
  AssignCommand(oPlayer, ActionEquipItem(oItem, iSlot));
 }
}

// Here is the main script in which you can customize your
// entering behaviour.
  void main()
{


 // Get the entering player
 object oPlayer = GetEnteringObject();

 // Uncomment if you want all items and gold removed.
  RemoveAllItems(oPlayer);

 // Uncomment if you want all immunity items removed.
  RemoveUberItems(oPlayer);

 // Uncomment if you want to boost the entering player.
 int iLevel = 3; // Change 1 to wanted level.
 SetEnterLevel(oPlayer, iLevel);

 // Uncomment if you want player to have at least a certain amount
 // of gold when entering.
  int iAmount = 0; //Change 150 to min. amount gold for player.
  GiveEnterGold(oPlayer, iAmount);
{
   object oPlayer = GetEnteringObject();


}
 // Uncomment if you want the player to receive a item when entering.
 // You can give more items by calling the function again with a
 // new item ResRef set.
  string sItem = "cloth028"; // ResRef (blueprint) name of item to give.
                                  // If NWN-default item use tag instead.
  GiveEnterItem(oPlayer, sItem);

 // Uncomment if you want the player to equip a item.
 // You can equip more items by calling the function again with a
 // new item tag set.
 string sItemTag = "cloth028"; // Tag of item to equip.
 EquipEnterItem(oPlayer, sItemTag);


 // Place your own custom content below

{



}
}
               
               

               


                     Modifié par cyberglum, 30 janvier 2011 - 02:03 .
                     
                  


            

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #5 on: January 30, 2011, 02:14:22 pm »


               Wow, thank you so much! That's a huge help. I am indeed making a single-player module. I can't stress enough how appreciated this is. '<img'>
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #6 on: January 30, 2011, 08:02:59 pm »


               //------------------------------------------------------------------
// find race/class if not valid jump to area...
/*
RACIAL_TYPE_DWARF      =0
RACIAL_TYPE_ELF        =1
RACIAL_TYPE_GNOME      =2
RACIAL_TYPE_HALFLING   =3
RACIAL_TYPE_HALFELF    =4
RACIAL_TYPE_HALFORC    =5
RACIAL_TYPE_HUMAN      =6

*/
if(GetRacialType(oPlayer)==RACIAL_TYPE_DWARF ||
  GetRacialType(oPlayer)==RACIAL_TYPE_GNOME ||
  GetRacialType(oPlayer)==RACIAL_TYPE_HALFORC )
  {
  // Jumps player to area race limmits/ and or class limmmits
  AssignCommand(oPlayer,ActionJumpToObject(GetObjectByTag("Name Of Waypoint in AREA")) );
  }

// look for class
int iClss1pos=GetclassByPosition(1,oPlayer);
int iClss2pos=GetclassByPosition(2,oPlayer);
int iClss3pos=GetclassByPosition(3,oPlayer);

/*
class_TYPE_BARBARIAN      =0
class_TYPE_BARD        =1
class_TYPE_CLERIC      =2

to find these look in lexicon type class_TYPE_ in the search option

*/
if( iClss1pos==class_TYPE_BARBARIAN || iClss2pos==class_TYPE_BARBARIAN  || iClss3pos==class_TYPE_BARBARIAN )
  {
  // Jumps player to area race limmits/ and or class limmmits
  AssignCommand(oPlayer,ActionJumpToObject(GetObjectByTag("Name Of Waypoint in AREA")) );
  }


//end of // find race/class if not valid jump to area...
//------------------------------------------------------------------

// end of script
}

Add this ware the script they gave you said..
 // Place your own custom content below

replacing the last } with this copied script text. you will have to change to add you class and race restrictions, but it should work like suggested never allowing any pc of any race or class restricted to always be ported to area
if any problems or question please ask
               
               

               


                     Modifié par Greyfort, 30 janvier 2011 - 08:06 .
                     
                  


            

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #7 on: January 30, 2011, 10:52:46 pm »


               You guys rock. '<img'> Greyfort, quick clarification, when you say "Jumps to player area race limits/and or class limits", do you mean, as per your example:
(a)If you ARE a Dwarf, Gnome or Half-orc, you go here.

or

(b)If you ARE NOT a Dwarf, Gnome, or Half-orc, you go here.
?

Basically I want to make it so there's only one kind of race that gets you to the starting point, and everybody else goes to the detour waypoint. So if I wanted a Halfling to be valid, and only a Halfling, would that part of the code look like this?:

if(GetRacialType(oPlayer)==RACIAL_TYPE_DWARF ||
GetRacialType(oPlayer)==RACIAL_TYPE_GNOME ||
GetRacialType(oPlayer)==RACIAL_TYPE_HALFORC ||
GetRacialType(oPlayer)==RACIAL_TYPE_ELF ||
GetRacialType(oPlayer)==RACIAL_TYPE_HALFELF ||
GetRacialType(oPlayer)==RACIAL_TYPE_HUMAN || )
{
// Jumps player to area race limmits/ and or class limmmits
AssignCommand(oPlayer,ActionJumpToObject(GetObjectByTag("ReRoll")) );
}


Also, if there's only one combo that is valid and all the others are invalid, would it save me time to switch the starting point and detour area? In other words, right now I have to specify all the combinations that don't get to the starting area. What if I made the waypoint the real start to the game, and put the starting area in the "false" room with no exit and instructions? Then I could just tell the game to route Halfling characters to the Waypoint (which would actually be the game proper), and everything else could go to the "starting area" (the room where you can't continue and someone tells you why).

So it would look like:

if(GetRacialType(oPlayer)==RACIAL_TYPE_HALFLING)
{
AssignCommand(oPlayer, ActionJumpToObject(GetObjectByTag("ReRoll")) );

//And then make sure the Waypoint with the tag "ReRoll" was actually where you should be to start the game.
}
               
               

               


                     Modifié par Dylan RPG, 30 janvier 2011 - 10:59 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #8 on: January 30, 2011, 11:34:38 pm »


               NOTE a scripted solution works for BOTH locally played modules and ones you log onto to play, while the (tedious to edit) 2da method ONLY works for local games, and does so for ALL local games not just the module you desired to change the behavior of - so we prefer scripted solutions in this case.



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #9 on: January 31, 2011, 12:16:32 am »


               

ehye_khandee wrote...

NOTE a scripted solution works for BOTH locally played modules and ones you log onto to play, while the (tedious to edit) 2da method ONLY works for local games, and does so for ALL local games not just the module you desired to change the behavior of - so we prefer scripted solutions in this case.


It would only effect Games that have the hak.  If they make a new hak to do this, It would be unlikely that any other module would use it.

Keep in mind that single player games load the haks before a first level character is rolled up.  opposed to MP where they are loaded after the creacter is created.
               
               

               
            

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #10 on: January 31, 2011, 02:47:25 am »


               So, I actually figured out a very simple way to achieve the Race/class bit. I created a closed room as the starting area, and around the starting point I drew a generic trigger. In the trigger script for OnEnter, I specified that anyone who was a Halfling/Male/Rogue should be redirected to a waypoint on the map I intended to use as the beginning of the game. I then told the script that everyone else should remain in the default location, where an NPC tells the player what went wrong.

The script just looks like this (and I benefitted greatly from others here, and the lexicon and other guides in figuring how to do this. I'm very much a beginner, as you can tell):

void main()
{
   object oPC=GetClickingObject();
   object oCreature;
   object oTarget;
   int i;
   if (GetRacialType(oPC)==RACIAL_TYPE_HALFLING)
   if (GetGender(oPC)==GENDER_MALE)
   if (i = GetLevelByclass(class_TYPE_ROGUE,GetFirstPC()))
   {
       oTarget = GetObjectByTag("Beginning");
   }
   else
   {
       oTarget = GetTransitionTarget(OBJECT_SELF);
   }
   AssignCommand(oPC, JumpToObject(oTarget));
}

____________

Works great. I'm using cyberglum's code for the equipment which works great, except I'm having a bit of trouble figuring out how to edit it to put in the items I want, but I'll get it down.
               
               

               


                     Modifié par Dylan RPG, 31 janvier 2011 - 02:49 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #11 on: January 31, 2011, 03:28:55 pm »


               That is a very good effort - one tiny fix for you though -



void main()
{
object oPC=GetEnteringObject();
object oCreature;
object oTarget;
if (GetRacialType(oPC)==RACIAL_TYPE_HALFLING
&& GetGender(oPC)==GENDER_MALE
&& GetLevelByclass(class_TYPE_ROGUE,oPC)==1)
{
oTarget = GetObjectByTag("Beginning");
}
else
{
oTarget = GetTransitionTarget(OBJECT_SELF);
}
AssignCommand(oPC, JumpToObject(oTarget));
}


               
               

               


                     Modifié par ehye_khandee, 31 janvier 2011 - 03:32 .
                     
                  


            

Legacy_Dylan RPG

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #12 on: January 31, 2011, 08:02:56 pm »


               Ah, that makes sense, hehe. Thank you very much. ... When I compile that, it tells me there's no right bracket in the expression, in line " && GetLevelByclass(class_TYPE_ROGUE,oPC)==1) ". What am I missing?

Edited: Never mind, figured it out '<img'>
               
               

               


                     Modifié par Dylan RPG, 31 janvier 2011 - 08:32 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #13 on: February 01, 2011, 04:48:51 pm »


               

Lightfoot8 wrote...

ehye_khandee wrote...

NOTE a scripted solution works for BOTH locally played modules and ones you log onto to play, while the (tedious to edit) 2da method ONLY works for local games, and does so for ALL local games not just the module you desired to change the behavior of - so we prefer scripted solutions in this case.


It would only effect Games that have the hak.  If they make a new hak to do this, It would be unlikely that any other module would use it.

Keep in mind that single player games load the haks before a first level character is rolled up.  opposed to MP where they are loaded after the creacter is created.


I was thinking along the lines of an override for the 2da, haks do work that way, but overrides would impact any game played while the override was in place.

I like to avoid dealing with both hak and override in favor of scripting.

Be well. Game on.
GM_ODA
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Restricting Player's Race and class [UPDATED]
« Reply #14 on: February 03, 2011, 01:20:48 am »


               Forgive my late reply RL...I was talking about jumping player to the room if they did not meet your requirements, that way you could tell them with a sign what the restrictions are etc. and allow them to either delete that char or tag for delete and make another char fiting the requirements you need.  Forgive me for not stateing that, I didn't make a solid stand alone script i was trying to point you in the general direction.  If you need anyhelp please ask we are all here for eachother.