I was messing around with the OnClientEnter script for the module, which is designed to strip a players inventory and give them some basic stuff based on their class/weapon focus.
I figured I'd post it here in hopes of some suggestions or optimizations, as it's currently just shy of 300 lines of code.
I'm also interested as to whether this would work if I were to make the module a PW of some sort, as that is a possibility in the future.
string GetWeapon() // Taken and slightly edited from the chest by spawn point in OC Prelude
{
object oPC = GetEnteringObject();
// Choose the weapon type to create
if (GetHasFeat(FEAT_WEAPON_FOCUS_BASTARD_SWORD, oPC))
{
return "bastardsword";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_BATTLE_AXE,oPC))
{
return "battleaxe";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_CLUB,oPC))
{
return "club";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_DAGGER,oPC))
{
return "dagger";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_DART,oPC))
{
return "dart";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_DIRE_MACE,oPC))
{
return "diremace";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_DOUBLE_AXE,oPC))
{
return "doubleaxe";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_GREAT_AXE,oPC))
{
return "greataxe";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_GREAT_SWORD,oPC))
{
return "greatsword";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_HALBERD,oPC))
{
return "halberd";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_HAND_AXE,oPC))
{
return "handaxe";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_HEAVY_CROSSBOW,oPC))
{
return "heavycrossbow";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_HEAVY_FLAIL,oPC))
{
return "heavyflail";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_KAMA,oPC))
{
return "kama";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_KATANA,oPC))
{
return "katana";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_KUKRI,oPC))
{
return "kukri";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_LIGHT_CROSSBOW,oPC))
{
return "lightcrossbow";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_LIGHT_FLAIL,oPC))
{
return "lightflail";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_LIGHT_HAMMER,oPC))
{
return "lighthammer";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_LIGHT_MACE,oPC))
{
return "lightmace";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_LONG_SWORD,oPC))
{
return "longsword";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_LONGBOW,oPC))
{
return "longbow";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_MORNING_STAR,oPC))
{
return "morningstar";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_RAPIER,oPC))
{
return "rapier";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SCIMITAR,oPC))
{
return "scimitar";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SCYTHE,oPC))
{
return "scythe";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SHORT_SWORD,oPC))
{
return "shortsword";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SHORTBOW,oPC))
{
return "shortbow";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SHURIKEN,oPC))
{
return "shuriken";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SICKLE,oPC))
{
return "sickle";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SLING,oPC))
{
return "sling";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_SPEAR,oPC))
{
return "spear";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_STAFF,oPC))
{
return "staff";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_THROWING_AXE,oPC))
{
return "throwingaxe";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_TWO_BLADED_SWORD,oPC))
{
return "twobladedsword";
}
else if (GetHasFeat(FEAT_WEAPON_FOCUS_WAR_HAMMER,oPC))
{
return "warhammer";
}
return ""; // Return nothing if character has no weapon focus
}
void main()
{
object oPC = GetEnteringObject();
if(!GetIsPC(oPC) || GetIsDM(oPC)) return;
// Check Equip Items and get rid of them
int i;
for(i<17; i++;)
{
object oEquip = GetItemInSlot(i,oPC);
if(GetIsObjectValid(oEquip))
{
SetPlotFlag(oEquip,FALSE);
DestroyObject(oEquip);
}
}
// Check general Inventory and clear it out.
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
{
SetPlotFlag(oItem,FALSE);
DestroyObject(oItem);
oItem = GetNextItemInInventory(oPC);
}
// Give them Gold
TakeGoldFromCreature(GetGold(oPC), oPC);
GiveGoldToCreature(oPC, 250);
// Get First class and assign default item tags
int iClass = GetClassByPosition(1,oPC);
string sAmmo, sWeapon = "staff", sArmour = "plainrobe";
int iAmmoAmount, iWepStacksize = 1;
// Assign Item tags based on primary class
switch (iClass)
{
// Barbarian
case 0:
sArmour = "hidearmour";
sWeapon = "handaxe";
break;
// Bard
case 1:
sArmour = "plainrobe";
sWeapon = "staff";
break;
// Cleric
case 2:
sArmour = "chainmail";
sWeapon = "lightmace";
break;
// Druid
case 3:
sArmour = "hidearmour";
sWeapon = "staff";
break;
// Fighter
case 4:
sArmour = "halfplate";
sWeapon = "longsword";
break;
// Monk
case 5:
sArmour = "paddedcloth";
sWeapon = "staff";
break;
// Paladin
case 6:
sArmour = "fullplate";
sWeapon = "greatsword";
break;
// Ranger
case 7:
sArmour = "heavyleather";
sWeapon = "longbow";
sAmmo = "arrow";
iAmmoAmount = 99;
break;
// Rogue
case 8:
sArmour = "leatherarmour";
sWeapon = "shortsword";
break;
// Sorcerer
case 9:
sArmour = "plainrobe";
sWeapon = "dagger";
break;
// Wizard
case 10:
sArmour = "plainrobe";
sWeapon = "staff";
break;
}
// Check for Weapon focus
string sFeatWeapon = GetWeapon();
if(sFeatWeapon != "")
{
sWeapon = sFeatWeapon;
}
// Check for ammo requirement
if(sWeapon == "shortbow" || sWeapon == "longbow")
{
sAmmo = "arrow";
}
else if(sWeapon == "lightcrossbow" || sWeapon == "heavycrossbow")
{
sAmmo = "bolt";
}
else if(sWeapon == "sling")
{
sAmmo = "bullet";
}
// Check weapon stacksize
if(sWeapon == "dart" || sWeapon == "throwingaxe")
{
iWepStacksize = 50;
}
else if(sWeapon == "shuriken")
{
iWepStacksize = 99;
}
CreateItemOnObject(sArmour, oPC);
CreateItemOnObject(sWeapon, oPC, iWepStacksize);
if(sAmmo != "")
{
CreateItemOnObject(sAmmo, oPC, 99);
}
string sHerb = "medicinalherb";
CreateItemOnObject(sHerb, oPC);
CreateItemOnObject(sHerb, oPC);
CreateItemOnObject(sHerb, oPC);
}
I'm still re-accustoming myself with NWScript, although I've learned C# since the last time I used it, and it has some close similarities.





Retour en haut






