| Author |
Sticky:
Post Working Scripts Here |
|
Kaine
|
Posted: Sunday, 23 June 02:08AM
|
Sheathing Weapons: This is a small set of scripts I use for my city guards. I didn't think they'd normally walk around with their weapons drawn getting rained on. These scripts will have the NPCs draw their weapons before they run into combat then sheath them again after combat is finished.
The first part you can add to the NPCs existing OnPhysicalAttacked script, you could also drop it into an include file if you like.
NWScript: int GetBaseGroup(int nItem) {
int nValue = 0;
switch (nItem ) {
case BASE_ITEM_SMALLSHIELD:
case BASE_ITEM_TOWERSHIELD:
case BASE_ITEM_LARGESHIELD:
nValue = 1;
break;
case BASE_ITEM_BASTARDSWORD:
case BASE_ITEM_BATTLEAXE:
case BASE_ITEM_CLUB:
case BASE_ITEM_DAGGER:
case BASE_ITEM_DART:
case BASE_ITEM_GREATSWORD:
case BASE_ITEM_HANDAXE:
case BASE_ITEM_KAMA:
case BASE_ITEM_KATANA:
case BASE_ITEM_KUKRI:
case BASE_ITEM_LIGHTCROSSBOW:
case BASE_ITEM_LIGHTFLAIL:
case BASE_ITEM_LIGHTHAMMER:
case BASE_ITEM_LIGHTMACE:
case BASE_ITEM_LONGSWORD:
case BASE_ITEM_RAPIER:
case BASE_ITEM_SCIMITAR:
case BASE_ITEM_SHORTSWORD:
case BASE_ITEM_SHORTBOW:
case BASE_ITEM_SHURIKEN:
case BASE_ITEM_SICKLE:
case BASE_ITEM_SLING:
case BASE_ITEM_THROWINGAXE:
case BASE_ITEM_WARHAMMER:
nValue = 2;
break;
case BASE_ITEM_DIREMACE:
case BASE_ITEM_DOUBLEAXE:
case BASE_ITEM_GREATAXE:
case BASE_ITEM_HALBERD:
case BASE_ITEM_HEAVYCROSSBOW:
case BASE_ITEM_HEAVYFLAIL:
case BASE_ITEM_LONGBOW:
case BASE_ITEM_MORNINGSTAR:
case BASE_ITEM_QUARTERSTAFF:
case BASE_ITEM_SCYTHE:
case BASE_ITEM_SHORTSPEAR:
case BASE_ITEM_TWOBLADEDSWORD:
nValue = 3;
break;
}
return nValue;
}
void EquipWeapon() {
if( !GetIsObjectValid( GetItemInSlot( INVENTORY_SLOT_RIGHTHAND ) ) ) {
object objInv;
objInv = GetFirstItemInInventory();
while( objInv != OBJECT_INVALID ) {
if( GetBaseGroup( GetBaseItemType( objInv ) ) > 1 ) {
ActionEquipItem( objInv, INVENTORY_SLOT_RIGHTHAND );
break;
}
objInv = GetNextItemInInventory();
}
}
return;
}
You then just need to put a call to EquipWeapon() in the main() of the OnPhysicalAttacked like this:
NWScript: ....
if( !GetIsObjectValid( GetAttemptedAttackTarget() ) && !GetIsObjectValid( GetAttemptedSpellTarget() ) ) {
EquipWeapon();
if( GetIsObjectValid( GetLastAttacker() ) ) {
....
Now your NPC should look for a weapon in inventory and equip it. Note, this doesnt do any checking to make sure there isnt a shield in the left hand and the NPC tries to equip a two handed weapon. If you want to put those checks in more power to you.
Okay, the monster is dead and our heroic city guard is standing there with his sword drawn in the rain. Now we want to have him put it away so it doesn't rust.
Now we drop a few lines into their OnHeartbeat script. Add or use the header file with the GetBaseGroup() function into the OnHeartbeat script as well as this function.
NWScript: void PutWeaponAway() {
if( !GetIsInCombat() ) {
object objInHand;
objInHand = GetItemInSlot( INVENTORY_SLOT_RIGHTHAND );
if( GetBaseGroup( GetBaseItemType( objInHand ) ) == 2 ) {
ActionUnequipItem( objInHand );
}
}
}
Then in the main() of the OnHeartbeat add the a call to the new function like this
NWScript: void main(){
PutWeaponAway( );
if( GetSpawnInCondition( NW_FLAG_FAST_BUFF_ENEMY ) )
{
....
I've run this with about 20 guards at a time fighting monsters and using this script at a time and it didnt make any noticable lag. Since it is in the OnHeartbeat you may want to test it on your system.
...and the "Could Not Submit: Message contains word with too many characters without a space. Please check your message" sucks for this forum btw.
[ Edited By Kaine: Sunday, 23 June 02:08AM (GMT) ]
[ Edited By Kaine: Sunday, 23 June 02:09AM (GMT) ] |
|