Here's the script with playable races added and transgender thing resolved. May want to check the codes for playable races.
Also, this version looks for the command on OBJECT_SELF, not on CoA token.
May also want to rename HALF-ORC and HALF-ELF to loose the dash.
//::///////////////////////////////////////////////
//:: Polymorph Self
//:: NW_S0_PolySelf.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
The PC is able to changed their form to one of
several forms.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 21, 2002
//:://////////////////////////////////////////////
#include "x2_inc_spellhook"
// Returns true if sCreatureName starts with sFormID
int ComparePolyStr(string sFormID, string sCreatureName) {
return GetStringLeft(sCreatureName, GetStringLength(sFormID)) == sFormID;
}
void main()
{
/*
Spellcast Hook Code
Added 2003-06-23 by GeorgZ
If you want to make changes to all spells,
check x2_inc_spellhook.nss to find out more
*/
if (!X2PreSpellCastCode())
{
// If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
return;
}
// End of Spell Cast Hook
// No spell if already polymorphed.
if (GetHasEffect(EFFECT_TYPE_POLYMORPH, OBJECT_SELF)) return;
//Declare major variables
object oTarget = GetSpellTargetObject();
effect eVis = EffectVisualEffect(VFX_IMP_POLYMORPH);
effect ePoly;
int nPoly = 0;
int nHD = 0;
int isFemale = (GetGender(OBJECT_SELF) == GENDER_FEMALE);
string sFormID = GetStringUpperCase(GetLocalString(OBJECT_SELF, "sPolyFormID"));
int nFeatTier = 0; //used for the splitting forms apart for Spell Focus and
//greater spell focus transmutation. Uncomment line 226 to disable
int nCasterLevel = GetCasterLevel(OBJECT_SELF);
int nTargetHD = GetHitDice(oTarget);
// Determine duration
int nMetaMagic = GetMetaMagicFeat();
int nDuration = nCasterLevel;
if (nMetaMagic == METAMAGIC_EXTEND) {
nDuration = nDuration *2; //Duration is +100%
}
// --------------------------------
// --- Determine Polymorph type ---
// HD 1
if(ComparePolyStr(sFormID, "EYEBALL")) { nPoly = 213; nHD = 1; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "GOBLIN")) { nPoly = 157; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "HOBGOBLIN")) { nPoly = 163; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "KOBOLD")) { nPoly = 165; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "ORC")) { nPoly = 166; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "FIRE BEETLE")) { nPoly = 177; nHD = 1; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "CHICKEN")) { nPoly = 40; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "FALCON")) { nPoly = 133; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "PENGUIN")) { nPoly = 26; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "RAVEN")) { nPoly = 134; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "RAT")) { nPoly = 144; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "OX")) { nPoly = 143; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "BADGER")) { nPoly = 25; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "BAT")) { nPoly = 140; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "COW")) { nPoly = 27; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DEER")) { nPoly = 142; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DIRE RAT")) { nPoly = 149; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "WHITE STAG")) { nPoly = 145; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "PARROT")) { nPoly = 324; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "SEAGULL")) { nPoly = 325; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "HORSE")) { nPoly = 326; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "PIXIE")) { nPoly = 328; nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "HUMAN")) { nPoly = (isFemale?306:164); nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "HALFLING")) { nPoly = (isFemale?305:162); nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "HALF-ORC")) { nPoly = (isFemale?304:161); nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "HALF-ELF")) { nPoly = (isFemale?303:160); nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "GNOME")) { nPoly = (isFemale?302:159); nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "ELF")) { nPoly = (isFemale?301:156); nHD = 1; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DWARF")) { nPoly = (isFemale?300:155); nHD = 1; nFeatTier = 0;}
// HD 2
else if(ComparePolyStr(sFormID, "TROGLODYTE")) { nPoly = 312; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "LIZARDFOLK")) { nPoly = 170; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "GNOLL")) { nPoly = 158; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DEEP ROTHE")) { nPoly = 190; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "KRENSHAR")) { nPoly = 194; nHD = 2; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "BOMBARDIER BEETLE")) { nPoly = 176; nHD = 2; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "FAERIE DRAGON")) { nPoly = 224; nHD = 2; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "PSEUDODRAGON")) { nPoly = 225; nHD = 2; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "DOG")) { nPoly = 130; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "WOLF")) { nPoly = 23; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "SAHUAGIN")) { nPoly = 329; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DRYAD")) { nPoly = 330; nHD = 2; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "OCHRE JELLY")) { nPoly = 331; nHD = 2; nFeatTier = 2;}
// HD 3
else if(ComparePolyStr(sFormID, "BUGBEAR")) { nPoly = 152; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "SEA HAG")) { nPoly = 168; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "STINK BEETLE")) { nPoly = 179; nHD = 3; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "SWORD SPIDER")) { nPoly = 181; nHD = 3; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING WHITE DRAGON")) { nPoly = 235; nHD = 3; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "BLACK BEAR")) { nPoly = 131; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "COUGAR")) { nPoly = 135; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "CRAG CAT")) { nPoly = 136; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "LEOPARD")) { nPoly = 138; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "PANTHER")) { nPoly = 22; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "BOAR")) { nPoly = 24; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DIRE BADGER")) { nPoly = 37; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "SNAKE")) { nPoly = 327; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "NYMPH")) { nPoly = 332; nHD = 3; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "GRAY OOZE")) { nPoly = 333; nHD = 3; nFeatTier = 2;}
// HD 4
else if(ComparePolyStr(sFormID, "OGRE")) { nPoly = 174; nHD = 4; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "STINGER")) { nPoly = 169; nHD = 4; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "GELATINOUS CUBE")) { nPoly = 208; nHD = 4; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "GARGOYLE")) { nPoly = 191; nHD = 4; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "GIANT SPIDER")) { nPoly = 180; nHD = 4; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING BLACK DRAGON")) { nPoly = 226; nHD = 4; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING BRASS DRAGON")) { nPoly = 228; nHD = 4; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WORG")) { nPoly = 258; nHD = 4; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "BLINK DOG")) { nPoly = 334; nHD = 4; nFeatTier = 1;}
// HD 5
else if(ComparePolyStr(sFormID, "ETTERCAP")) { nPoly = 212; nHD = 5; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "HOOK HORROR")) { nPoly = 214; nHD = 5; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "COCKATRICE")) { nPoly = 189; nHD = 5; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "WYRMLING COPPER DRAGON")) { nPoly = 230; nHD = 5; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING GREEN DRAGON")) { nPoly = 232; nHD = 5; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "JAGUAR")) { nPoly = 137; nHD = 5; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "LION")) { nPoly = 139; nHD = 5; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "SATYR")) { nPoly = 335; nHD = 5; nFeatTier = 0;}
// HD 6
else if(ComparePolyStr(sFormID, "DRIDER")) { nPoly = (isFemale?307:211); nHD = 6; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "INTELLECT DEVOURER")) { nPoly = 215; nHD = 6; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "TROLL")) { nPoly = 175; nHD = 6; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "YUAN-TI")) { nPoly = 171; nHD = 6; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "MINOTAUR")) { nPoly = 172; nHD = 6; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "MEDUSA")) { nPoly = 167; nHD = 6; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "BASILISK")) { nPoly = 197; nHD = 6; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "MANTICORE")) { nPoly = 195; nHD = 6; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING BLUE DRAGON")) { nPoly = 227; nHD = 6; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING BRONZE DRAGON")) { nPoly = 229; nHD = 6; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "BROWN BEAR")) { nPoly = 21; nHD = 6; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "WINTER WOLF")) { nPoly = 257; nHD = 6; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "DIRE WOLF")) { nPoly = 35; nHD = 6; nFeatTier = 0;}
// HD 7
else if(ComparePolyStr(sFormID, "HARPY")) { nPoly = 173; nHD = 7; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "STAG BEETLE")) { nPoly = 178; nHD = 7; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING RED DRAGON")) { nPoly = 233; nHD = 7; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING SILVER DRAGON")) { nPoly = 234; nHD = 7; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "DIRE BOAR")) { nPoly = 36; nHD = 7; nFeatTier = 0;}
// HD 8
else if(ComparePolyStr(sFormID, "MIND FLAYER")) { nPoly = 216; nHD = 8; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "UMBER HULK")) { nPoly = 217; nHD = 8; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "GORGON")) { nPoly = 192; nHD = 8; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "SPHINX")) { nPoly = 193; nHD = 8; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "WYRMLING GOLD DRAGON")) { nPoly = 231; nHD = 8; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "POLAR BEAR")) { nPoly = 148; nHD = 8; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "GRIZZLY BEAR")) { nPoly = 147; nHD = 8; nFeatTier = 0;}
// HD 9
else if(ComparePolyStr(sFormID, "BATTLE DEVOURER")) { nPoly = 209; nHD = 9; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "WILL O WISP")) { nPoly = 218; nHD = 9; nFeatTier = 2;}
else if(ComparePolyStr(sFormID, "BULLETTE")) { nPoly = 313; nHD = 9; nFeatTier = 1;}
// HD 10
else if(ComparePolyStr(sFormID, "ETTIN")) { nPoly = 187; nHD = 10; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "GREY RENDER")) { nPoly = 221; nHD = 10; nFeatTier = 1;}
else if(ComparePolyStr(sFormID, "DIRE SPIDER")) { nPoly = 188; nHD = 10; nFeatTier = 1;}
// HD 11
else if(ComparePolyStr(sFormID, "BEHOLDER")) { nPoly = 210; nHD = 11; nFeatTier = 2;}
// HD 12
else if(ComparePolyStr(sFormID, "HILL GIANT")) { nPoly = 222; nHD = 12; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "DIRE BEAR")) { nPoly = 33; nHD = 12; nFeatTier = 0;}
else if(ComparePolyStr(sFormID, "WYVERN")) { nPoly = 336; nHD = 12; nFeatTier = 1;}
// HD 13
// HD 14
else if(ComparePolyStr(sFormID, "FROST GIANT")) { nPoly = (isFemale?308:259); nHD = 14; nFeatTier = 0;}
// HD 15
else if(ComparePolyStr(sFormID, "FIRE GIANT")) { nPoly = (isFemale?309:289); nHD = 14; nFeatTier = 0;}
// Couldn't determine the form
if (nPoly == 0) {
SendMessageToPC(OBJECT_SELF, "Unknown form type. Check spelling.");
// Default to pixie! (so the spell defaults back to one of the default nwn forms)
nPoly = 328;
}
// Caster level not high enough for the form
if (nHD > nCasterLevel) {
SendMessageToPC(OBJECT_SELF, "Caster level is too low for this form.");
// Default to pixie! (so the spell defaults back to one of the default nwn forms)
nPoly = 328;
}
// Target hasn't enough HD for the form
if (nHD > nTargetHD) {
SendMessageToPC(OBJECT_SELF, "Target doesn't have enough HD for this form.");
// Default to pixie! (so the spell defaults back to one of the default nwn forms)
nPoly = 328;
}
//Spell Focuses for stronger racial variants
////nFeatTier = 0 ///uncomment this to disable the spell focus restrictions
if (nFeatTier == 1 && GetHasFeat(FEAT_SPELL_FOCUS_TRANSMUTATION, OBJECT_SELF) != TRUE)
{ SendMessageToPC(OBJECT_SELF, "Selected form requires spell focus in transmutation");
// Default to pixie! (so the spell defaults back to one of the default nwn forms)
nPoly = 328;
}
if (nFeatTier == 2 && GetHasFeat(FEAT_GREATER_SPELL_FOCUS_TRANSMUTATION, OBJECT_SELF) != TRUE)
{ SendMessageToPC(OBJECT_SELF, "Selected form requires greater spell focus in transmutation");
// Default to pixie! (so the spell defaults back to one of the default nwn forms)
nPoly = 328;
}
ePoly = EffectPolymorph(nPoly);
//copy their weapon properties so they don't suck completely
int bWeapon = StringToInt(Get2DAString("polymorph","MergeW",nPoly)) == 1;
object oWeaponOld = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,OBJECT_SELF);
//Fire cast spell at event for the specified target
SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_POLYMORPH_SELF, FALSE));
//Apply the VFX impact and effects
AssignCommand(oTarget, ClearAllActions()); // prevents an exploit
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, ePoly, oTarget, TurnsToSeconds(nDuration));
//copying the weapon properties
object oWeaponNew = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,OBJECT_SELF);
if (bWeapon)
{
IPWildShapeCopyItemProperties(oWeaponOld,oWeaponNew, TRUE);
}
}