Author Topic: Guard Script "Halt! Sheath your weapon citizen!"  (Read 995 times)

Legacy_Grieyls

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« on: July 29, 2010, 09:38:56 pm »


               Hi there, I'm trying to write a script to place on the UserDefined handle that when a guard percieves a PC with an equiped weapon will tell them to sheath it.

Now I'm trying to figure this out but I only got so far and now I'm stuck... Any help anybody can give or hints on what I should be doing... Heck if there is a simpler way of doing this please tell me. 

The below script is as far as I got before I couldn't figure out what more I had to do .'Posted


       
case 1002:  //Called by OnPerception
            object oSeen=GetLastPerceived();
            object oWeapon=GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oSeen)
            && GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oSeen)

             if (GetIsPC(oSeen) && GetLastPerceptionSeen())
                //what goes here???
                ActionSpeakString("Blah, Blah, Blah");
            break;
               
               

               


                     Modifié par Grieyls, 29 juillet 2010 - 08:41 .
                     
                  


            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #1 on: July 29, 2010, 09:50:24 pm »


               object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF);

object oWp = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC);



//VARIABLES START HERE



//The first warning a guard will give - edit the text between "" as desired.

string WARNING1 = "Please put away your weapon";

//The second warning - edit as above

string WARNING2 = "I said put away your weapon!";

//The third warning

string WARNING3 = "I will not tell you again! Put it away!";//Move to Player

//The Battlecry

string ATTACK_MSG = "You where warned!!! Attack!!";//Attack here

//What the guard says when the PC puts their weapon away.

string COMPLY_REPLY = "Good";



float  WARN_DISTANCE = 10.0;//Distance in which to spot player

float ANGER_DUR = 60.0; //Length of time (sec) that will remain angry at the pc

//END OF VARIABLES



void main()

{

   object oPC;

       object item;

         object oWp = GetItemInSlot (INVENTORY_SLOT_RIGHTHAND, oPC);

       oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF);



           if(oPC != OBJECT_INVALID && (GetDistanceBetween(OBJECT_SELF,oPC) < WARN_DISTANCE) && GetObjectSeen(oPC) && !GetIsEnemy(oPC))

           {

            //If the pc is holding anyhting other than a Wizard's staff in his right hand then the guard will shout at him to put his weapon away.

   if (GetBaseItemType(oWp) == BASE_ITEM_LIGHTCROSSBOW || GetBaseItemType(oWp) == BASE_ITEM_HEAVYCROSSBOW ||

       GetBaseItemType(oWp) == BASE_ITEM_LONGBOW || GetBaseItemType(oWp) == BASE_ITEM_SHORTBOW ||

       GetBaseItemType(oWp) == BASE_ITEM_DART || GetBaseItemType(oWp) == BASE_ITEM_THROWINGAXE ||

       GetBaseItemType(oWp) == BASE_ITEM_SHURIKEN || GetBaseItemType(oWp) == BASE_ITEM_SLING ||

       GetBaseItemType(oWp) == BASE_ITEM_BASTARDSWORD || GetBaseItemType(oWp) == BASE_ITEM_BATTLEAXE ||

       GetBaseItemType(oWp) == BASE_ITEM_CBLUDGWEAPON || GetBaseItemType(oWp) == BASE_ITEM_CLUB ||

       GetBaseItemType(oWp) == BASE_ITEM_CPIERCWEAPON || GetBaseItemType(oWp) == BASE_ITEM_CSLASHWEAPON ||

       GetBaseItemType(oWp) == BASE_ITEM_CSLSHPRCWEAP || GetBaseItemType(oWp) == BASE_ITEM_DAGGER ||

       GetBaseItemType(oWp) == BASE_ITEM_DIREMACE || GetBaseItemType(oWp) == BASE_ITEM_DOUBLEAXE ||

       GetBaseItemType(oWp) == BASE_ITEM_DWARVENWARAXE || GetBaseItemType(oWp) == BASE_ITEM_GREATAXE ||

       GetBaseItemType(oWp) == BASE_ITEM_GREATSWORD || GetBaseItemType(oWp) == BASE_ITEM_HALBERD ||

       GetBaseItemType(oWp) == BASE_ITEM_HANDAXE || GetBaseItemType(oWp) == BASE_ITEM_HEAVYFLAIL ||

       GetBaseItemType(oWp) == BASE_ITEM_KAMA || GetBaseItemType(oWp) == BASE_ITEM_KATANA ||

       GetBaseItemType(oWp) == BASE_ITEM_KUKRI || GetBaseItemType(oWp) == BASE_ITEM_LIGHTFLAIL ||

       GetBaseItemType(oWp) == BASE_ITEM_LIGHTHAMMER || GetBaseItemType(oWp) == BASE_ITEM_LIGHTMACE ||

       GetBaseItemType(oWp) == BASE_ITEM_LONGSWORD || GetBaseItemType(oWp) == BASE_ITEM_MORNINGSTAR || GetBaseItemType(oWp) == BASE_ITEM_QUARTERSTAFF ||

       GetBaseItemType(oWp) == BASE_ITEM_RAPIER || GetBaseItemType(oWp) == BASE_ITEM_SCIMITAR ||

       GetBaseItemType(oWp) == BASE_ITEM_SCYTHE || GetBaseItemType(oWp) == BASE_ITEM_SHORTSPEAR ||

       GetBaseItemType(oWp) == BASE_ITEM_SHORTSWORD || GetBaseItemType(oWp) == BASE_ITEM_SICKLE ||

       GetBaseItemType(oWp) == BASE_ITEM_TRIDENT || GetBaseItemType(oWp) == BASE_ITEM_TWOBLADEDSWORD ||

       GetBaseItemType(oWp) == BASE_ITEM_WARHAMMER || GetBaseItemType(oWp) == BASE_ITEM_WHIP)







            {

               if(GetLocalObject(OBJECT_SELF,"LastOffender")==oPC)

               {

                   if(GetLocalInt(OBJECT_SELF,"OffenseCount")==1)

                   {

                        SpeakString(ATTACK_MSG);

                        SetIsTemporaryEnemy(oPC,OBJECT_SELF,TRUE,ANGER_DUR);

                        ActionAttack(oPC);

                   }

                   else if(GetLocalInt(OBJECT_SELF,"OffenseCount")==1)

                   {

                       ActionMoveToObject(oPC,TRUE);

                       SetLocalInt(OBJECT_SELF,"OffenseCount",2);

                       SpeakString(WARNING3);

                   }

                   else

                   {

                       SetLocalInt(OBJECT_SELF,"OffenseCount",1);

                       SpeakString(WARNING2);

                   }

               }

               else

               {

                     SetLocalInt(OBJECT_SELF,"OffenseCount",0);

                     SpeakString(WARNING1);

                     SetLocalObject(OBJECT_SELF,"LastOffender",oPC);

               }

            }

            else

            {

                   if( GetLocalObject(OBJECT_SELF,"LastOffender")!= OBJECT_INVALID)

                       SpeakString(COMPLY_REPLY);



                   DeleteLocalObject(OBJECT_SELF,"LastOffender");

                   SetLocalInt(OBJECT_SELF,"OffenseCount",0);

            }

       }



   if(GetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY))

   {

       if(TalentAdvancedBuff(40.0))

       {

           SetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY, TRUE);

           return;

       }

   }



   if(GetSpawnInCondition(NW_FLAG_DAY_NIGHT_POSTING))

   {

       int nDay = FALSE;

       if(GetIsDay() || GetIsDawn())

       {

           nDay = TRUE;

       }

       if(GetLocalInt(OBJECT_SELF, "NW_GENERIC_DAY_NIGHT") != nDay)

       {

           if(nDay == TRUE)

           {

               SetLocalInt(OBJECT_SELF, "NW_GENERIC_DAY_NIGHT", TRUE);

           }

           else

           {

               SetLocalInt(OBJECT_SELF, "NW_GENERIC_DAY_NIGHT", FALSE);

           }

           WalkWayPoints();

       }

   }



   if(!GetHasEffect(EFFECT_TYPE_SLEEP))

   {

       if(!GetIsPostOrWalking())

       {

           if(!GetIsObjectValid(GetAttemptedAttackTarget()) && !GetIsObjectValid(GetAttemptedSpellTarget()))

           {

               if(!GetIsObjectValid(GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN)))

               {

                   if(!GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL) && !IsInConversation(OBJECT_SELF))

                   {

                       if(GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS) || GetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS_AVIAN))

                       {

                           PlayMobileAmbientAnimations();

                       }

                       else if(GetIsEncounterCreature() &&

                       !GetIsObjectValid(GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN)))

                       {

                           PlayMobileAmbientAnimations();

                       }

                       else if(GetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS) &&

                          !GetIsObjectValid(GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN)))

                       {

                           PlayImmobileAmbientAnimations();

                       }

                   }

                   else

                   {

                       DetermineSpecialBehavior();

                   }

               }

               else

               {

                   //DetermineCombatRound();

               }

           }

       }

   }

   else

   {

       if(GetSpawnInCondition(NW_FLAG_SLEEPING_AT_NIGHT))

       {

           effect eVis = EffectVisualEffect(VFX_IMP_SLEEP);

           if(d10() > 6)

           {

               ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF);

           }

       }

   }



   if(GetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT))

   {

       SignalEvent(OBJECT_SELF, EventUserDefined(1001));

   }

}

               
               

               
            

Legacy_Grieyls

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #2 on: July 29, 2010, 10:33:49 pm »


               That's a monster script 'Posted

Anyway, thanks so much for that but when I compile it I get an error message 'Posted

for this line....

if(GetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY))
ERROR: NO RIGHT BRACKET ON EXPRESSION
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #3 on: July 30, 2010, 12:40:23 am »


               It looks like a  monster because its posted here, lol...I forogt the include at the top in my posting.



#include "NW_I0_GENERIC"



We actually use this as a on heratbeta script though we do have a user defined as well. Honestly it does not cause much lag at all as they also walk around a bit and we despawn them when a PC is NOT in the area.



               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #4 on: July 30, 2010, 01:28:42 am »


               Yeah posting scripts in this new forum is not only tedious but unruly and ugly in the post as well...



I sure hope they fix this issue...  (However I'm thinking we have been abandoned by Bioware)



*Feels like an unwanted stepchild*
               
               

               
            

Legacy_Grieyls

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #5 on: July 30, 2010, 01:30:15 am »


               Any chance you could post the UserDefined one then... Just so I can compare and then perhaps learn something new '<img'>
               
               

               


                     Modifié par Grieyls, 30 juillet 2010 - 12:50 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #6 on: July 30, 2010, 10:19:09 am »


               Just a quick note on script efficiency, especially since you're using this as a heartbeat script.



You can smooth things a little by reducing some scripting calls, such as where you have multiple "GetBaseItemType(oWp) == " pieces.  Instead of calling it one time for every type of weapon, you could just start with something like:



int nHeldType = GetBaseItemType(oWp);

int nHasWeapon;



Then follow with a switch check (which you can do with the integers of base item type constants), which should only be looking for the specific one for the correct base item type:



switch (nHeldType)

{

case BASE_ITEM_LIGHTCROSSBOW:

case BASE_ITEM_HEAVYCROSSBOW:

case BASE_ITEM_LONGBOW:

case BASE_ITEM_SHORTBOW:

case BASE_ITEM_DART:

case BASE_ITEM_THROWINGAXE:

case BASE_ITEM_SHURIKEN:

case BASE_ITEM_SLING:

case BASE_ITEM_BASTARDSWORD:

case BASE_ITEM_BATTLEAXE:

case BASE_ITEM_CBLUDGWEAPON:

case BASE_ITEM_CLUB:

case BASE_ITEM_CPIERCWEAPON:

case BASE_ITEM_CSLASHWEAPON:

case BASE_ITEM_CSLSHPRCWEAP:

case BASE_ITEM_DAGGER:

case BASE_ITEM_DIREMACE:

case BASE_ITEM_DOUBLEAXE:

case BASE_ITEM_DWARVENWARAXE:

case BASE_ITEM_GREATAXE:

case BASE_ITEM_GREATSWORD:

case BASE_ITEM_HALBERD:

case BASE_ITEM_HANDAXE:

case BASE_ITEM_HEAVYFLAIL:

case BASE_ITEM_KAMA:

case BASE_ITEM_KATANA:

case BASE_ITEM_KUKRI:

case BASE_ITEM_LIGHTFLAIL:

case BASE_ITEM_LIGHTHAMMER:

case BASE_ITEM_LIGHTMACE:

case BASE_ITEM_LONGSWORD:

case BASE_ITEM_MORNINGSTAR:

case BASE_ITEM_QUARTERSTAFF:

case BASE_ITEM_RAPIER:

case BASE_ITEM_SCIMITAR:

case BASE_ITEM_SCYTHE:

case BASE_ITEM_SHORTSPEAR:

case BASE_ITEM_SHORTSWORD:

case BASE_ITEM_SICKLE:

case BASE_ITEM_TRIDENT:

case BASE_ITEM_TWOBLADEDSWORD:

case BASE_ITEM_WARHAMMER:

case BASE_ITEM_WHIP: nHasWeapon = 1; break;

}



Then follow with an if statement to start off your code when a weapon is spotted:



if (nHasWeapon == 1)



               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #7 on: July 30, 2010, 08:34:06 pm »


               Cool thanks. I am really self taught so any advice form scripters helps.



The problem with being self taught is your teacher is confusing and your student is an idiot.
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #8 on: September 04, 2010, 09:25:17 am »


               would that script also work for NPC Guards who stand at the gate or something?

as a onpercieve script? Since as Grieyls I have been trying to get something similar to work....prefer on percieve scripts since I want to make sure we do not get any alg here and alll that

               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #9 on: September 04, 2010, 03:25:24 pm »


               This is all overkill to my way of thinking.

Use the guards' OnPerceived script, no heartbeat needed - try this

NOTE I used some of the code above for the function here.


int CheckForWeapon(object oWp)
{
   int nHeldType = GetBaseItemType(oWp);
   int nHasWeapon = 0;
   switch (nHeldType)
   {
   case BASE_ITEM_LIGHTCROSSBOW:
   case BASE_ITEM_HEAVYCROSSBOW:
   case BASE_ITEM_LONGBOW:
   case BASE_ITEM_SHORTBOW:
   case BASE_ITEM_DART:
   case BASE_ITEM_THROWINGAXE:
   case BASE_ITEM_SHURIKEN:
   case BASE_ITEM_SLING:
   case BASE_ITEM_BASTARDSWORD:
   case BASE_ITEM_BATTLEAXE:
   case BASE_ITEM_CBLUDGWEAPON:
   case BASE_ITEM_CLUB:
   case BASE_ITEM_CPIERCWEAPON:
   case BASE_ITEM_CSLASHWEAPON:
   case BASE_ITEM_CSLSHPRCWEAP:
   case BASE_ITEM_DAGGER:
   case BASE_ITEM_DIREMACE:
   case BASE_ITEM_DOUBLEAXE:
   case BASE_ITEM_DWARVENWARAXE:
   case BASE_ITEM_GREATAXE:
   case BASE_ITEM_GREATSWORD:
   case BASE_ITEM_HALBERD:
   case BASE_ITEM_HANDAXE:
   case BASE_ITEM_HEAVYFLAIL:
   case BASE_ITEM_KAMA:
   case BASE_ITEM_KATANA:
   case BASE_ITEM_KUKRI:
   case BASE_ITEM_LIGHTFLAIL:
   case BASE_ITEM_LIGHTHAMMER:
   case BASE_ITEM_LIGHTMACE:
   case BASE_ITEM_LONGSWORD:
   case BASE_ITEM_MORNINGSTAR:
   case BASE_ITEM_QUARTERSTAFF:
   case BASE_ITEM_RAPIER:
   case BASE_ITEM_SCIMITAR:
   case BASE_ITEM_SCYTHE:
   case BASE_ITEM_SHORTSPEAR:
   case BASE_ITEM_SHORTSWORD:
   case BASE_ITEM_SICKLE:
   case BASE_ITEM_TRIDENT:
   case BASE_ITEM_TWOBLADEDSWORD:
   case BASE_ITEM_WARHAMMER:
   case BASE_ITEM_WHIP:
       nHasWeapon = 1; break;
   }
   return nHasWeapon;
}

void main()
{
   object oPerceived = GetLastPerceived();
   object oLefthand = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPerceived);
   object oRighthand = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPerceived);
   int nTriggerWarning = CheckForWeapon(oLefthand) + CheckForWeapon(oRighthand);
   if(nTriggerWarning != 0)
   {
       SpeakString("Weapons are not permitted here!");
   }
}

// Above compiled but NOT TESTED - it should work.
               
               

               


                     Modifié par ehye_khandee, 04 septembre 2010 - 02:26 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #10 on: September 04, 2010, 06:17:57 pm »


               I did a bar where you have to sheath you weapons when you enter. Now intead of having the guard just tell someone to do it, sheath their weapon you could have that happen too. Treating it more as a command effect. Guard: Sheath your Weapon, and then execute that action. Something to consider also is that you would have to do it for both hands, unless they are carrying a two-handed weapon. You can actually get bows but sadly no funtion for melee weapons. What I mean is that there is a function that checks for bows:

// Returns TRUE if the given opponent is wielding a
// ranged weapon.
int GetIsWieldingRanged(object oAttacker)

So without listing all the weapons you could also just unequip what the PC is carrying in their hands, assuming they will be weapons, though it could be a torch I suppose.
This is the script for interior inhabited areas like Inns, houses, etc...

#include "NW_I0_GENERIC"

void main()
{
object oPC = GetEnteringObject();
object oDatabase = GetItemPossessedBy(oPC, "database");
object oArea = GetArea(oPC);
if (!GetIsPC(oPC))
return;
object oItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
object oItem1 = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
location lLocation = GetLocation(oPC);


if (GetIsObjectValid(oItem))
{
AssignCommand(oPC, ActionUnequipItem(oItem));
}

if (GetIsObjectValid(oItem1))
{
AssignCommand(oPC, ActionUnequipItem(oItem1));
}
//can't enter with weapons equipped,torches, shields...

}

You could make an exception for torches checking the left hand and returning the script at that point. Then onequipped I check the area for the variable No_Weapon and if it's set to 1 the PC is auto-unequipped of their weapons.

Now for your particular case you may not want this but it might be useful for some other areas, like a boxing arena where you can't use weapons. Which is what I originally designed it for.
Cheers!

You could also use the function:
// * Returns TRUE if the weapon equipped is capable of damaging oVersus.
int GetIsWeaponEffective(object oVersus=OBJECT_INVALID, int bOffHand=FALSE)

Where both weapons are checked, and if they are effective, i.e, they can damage the caller then they meet the
criteria of weapons and can be called as such or unequipped.  About the only reason to list all the weapons that
I can think of is that you could actually have the guard refer to the weapon, sheath your long-sword or sheath you great axe of slaying gibbering gibbons, which adds some flavor to the world.
               
               

               


                     Modifié par ffbj, 04 septembre 2010 - 05:26 .
                     
                  


            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Guard Script "Halt! Sheath your weapon citizen!"
« Reply #11 on: September 17, 2010, 10:52:08 am »


               Okay this is REALLY useful here!



Thanks! Will try it out ASAP! '<img'>