Jump to content


Photo

Getting Non-Party NPC's to Equip Weapons


  • Please log in to reply
1 reply to this topic

#1 japheth

japheth

    Codewalker

  • Member
  • 317 posts

Posted 06 November 2002 - 03:50 PM

Alright, as some of you may know I'm working on a Hirelings mod over at FWP. I have the basics ironed out, the cre's are moving between areas smoothly, so now I've decided to add a little bit of interactivity to the mod by letting the player's talk to the hireling and asking about their status, health, equipment, etc.

One thing I'm trying to do is this:

If the player has more than 40 normal arrows, the merc is proficient with a bow and he has a bow in his inventory and has no arrows himself, the player can give the merc some arrows and then tell the merc to equip his bow rather than his sword. Here's the dialogue that initiates everything:

IF ~Global("JPHireFighter#1","GLOBAL",2)~ THEN BEGIN JPFIGHT4
SAY ~The mercenary is idly picking his nose looking at the local scenery...he notices you and whipes the booger on his pant leg.  "Yessa?"~
IF ~~ THEN REPLY ~How are you for equipment?~ GOTO JPFIGHT5
IF ~HasItemEquiped("jpp1lswd",Myself)
!HasItem("jparow",Myself)
!HasItem("jpp1arow",Myself)
!HasItem("jpp2arow",Myself)
HasItem("jplbw",Myself)~ THEN REPLY ~Hmm, you seem to be good with a sword, can you use a bow?~ GOTO JPFIGHT8
IF ~HasItemEquiped("jpp1lswd",Myself)
!HasItem("jparow",Myself)
!HasItem("jpp1arow",Myself)
!HasItem("jpp2arow",Myself)
HasItem("jpp1lbw",Myself)~ THEN REPLY ~Hmm, you seem to be good with a sword, can you use a bow?~ GOTO JPFIGHT9
IF ~HasItemEquiped("jpp1lswd",Myself)
!HasItem("jparow",Myself)
!HasItem("jpp1arow",Myself)
!HasItem("jpp2arow",Myself)
HasItem("jpp2lbw",Myself)~ THEN REPLY ~Hmm, you seem to be good with a sword, can you use a bow?~ GOTO JPFIGHT10
IF ~HasItemEquiped("jpp1lswd",Myself)
!HasItem("jparow",Myself)
!HasItem("jpp1arow",Myself)
!HasItem("jpp2arow",Myself)
HasItem("jpclbw",Myself)~ THEN REPLY ~Hmm, you seem to be good with a sword, can you use a bow?~ GOTO JPFIGHT11
IF ~HasItemEquiped("jpp1lswd",Myself)
!HasItem("jparow",Myself)
!HasItem("jpp1arow",Myself)
!HasItem("jpp2arow",Myself)
HasItem("jpp1clbw",Myself)~ THEN REPLY ~Hmm, you seem to be good with a sword, can you use a bow?~ GOTO JPFIGHT12
IF ~HasItemEquiped("jpp1lswd",Myself)
!HasItem("jparow",Myself)
!HasItem("jpp1arow",Myself)
!HasItem("jpp2arow",Myself)
HasItem("jpp2clbw",Myself)~ THEN REPLY ~Hmm, you seem to be good with a sword, can you use a bow?~ GOTO JPFIGHT13
IF ~~ THEN REPLY ~We don't need you anymore.  Scram buddy.~ GOTO JPFIGHT6
END

IF ~~ THEN BEGIN JPFIGHT5
SAY ~The mercenary ruffles through his pack, and checks his equipment.  "Just fine boss."~
IF ~~ THEN EXIT
END

IF ~~ THEN BEGIN JPFIGHT6
SAY ~The mercenary gives you the forbidden finger and walks off.~
IF ~~ THEN DO ~LeaveParty()
SetGlobal("JPHireFighter#1","GLOBAL",0)
AddJournalEntry(99999,QUEST_DONE)~ EXIT
END

IF ~~ THEN BEGIN JPFIGHT8
SAY ~The fighter smirks and points to the longbow on his back.  "Yeah, I can use one.  But I forgot my arrows back at the guild."~
IF ~HasItem("jplbw",Myself)
PartyHasItem("arow01")
NumItemsPartyGT("arow01",40)~ THEN REPLY ~Here take these arrows and start plunking some bad guys.~ DO ~TakePartyItemNum("arow01",40)
SetGlobal("JPFighter#1Equip","GLOBAL",1)~ EXIT
END

IF ~~ THEN BEGIN JPFIGHT9
SAY ~The fighter smirks and points to the longbow on his back.  "Yeah, I can use one.  But I forgot my arrows back at the guild."~
IF ~HasItem("jpp1lbw",Myself)
PartyHasItem("arow01")
NumItemsPartyGT("arow01",40)~ THEN REPLY ~Here take these arrows and start plunking some bad guys.~ DO ~TakePartyItemNum("arow01",40)
SetGlobal("JPFighter#1Equip","GLOBAL",1)~ EXIT
END

IF ~~ THEN BEGIN JPFIGHT10
SAY ~The fighter smirks and points to the longbow on his back.  "Yeah, I can use one.  But I forgot my arrows back at the guild."~
IF ~HasItem("jpp2lbw",Myself)
PartyHasItem("arow01")
NumItemsPartyGT("arow01",40)~ THEN REPLY ~Here take these arrows and start plunking some bad guys.~ DO ~TakePartyItemNum("arow01",40)
SetGlobal("JPFighter#1Equip","GLOBAL",1)~ EXIT
END

IF ~~ THEN BEGIN JPFIGHT11
SAY ~The fighter smirks and points to the composite longbow on his back.  "Yeah, I can use one.  But I forgot my arrows back at the guild."~
IF ~HasItem("jpclbw",Myself)
PartyHasItem("arow01")
NumItemsPartyGT("arow01",40)~ THEN REPLY ~Here take these arrows and start plunking some bad guys.~ DO ~TakePartyItemNum("arow01",40)
SetGlobal("JPFighter#1Equip","GLOBAL",1)~ EXIT
END

IF ~~ THEN BEGIN JPFIGHT12
SAY ~The fighter smirks and points to the composite longbow on his back.  "Yeah, I can use one.  But I forgot my arrows back at the guild."~
IF ~HasItem("jpp1clbw",Myself)
PartyHasItem("arow01")
NumItemsPartyGT("arow01",40)~ THEN REPLY ~Here take these arrows and start plunking some bad guys.~ DO ~TakePartyItemNum("arow01",40)
SetGlobal("JPFighter#1Equip","GLOBAL",1)~ EXIT
END

IF ~~ THEN BEGIN JPFIGHT13
SAY ~The fighter smirks and points to the composite longbow on his back.  "Yeah, I can use one.  But I forgot my arrows back at the guild."~
IF ~HasItem("jpp2clbw",Myself)
PartyHasItem("arow01")
NumItemsPartyGT("arow01",40)~ THEN REPLY ~Here take these arrows and start plunking some bad guys.~ DO ~TakePartyItemNum("arow01",40)
SetGlobal("JPFighter#1Equip","GLOBAL",1)~ EXIT
END

And then, in the merc script, I have this:

IF
    HasItemEquiped("jpp1lswd",Myself) // +1 Long Sword 
    HasItemEquiped("jpp1shld",Myself) // +1 Shield
	Global("JPFighter#1Equip","GLOBAL",1)
THEN
    RESPONSE #100
  DropItem("jpp1lswd",[10.10]) //Don't care where it's dropped since it's going to be destroyed
  DropItem("jpp1shld",[20.20]) //Don't care where it's dropped since it's going to be destroyed
  DestroyItem("jpp1lswd")
  DestroyItem("jpp1shld")
  SetGlobal("JPFighter#1Equip","GLOBAL",2)
END

IF
	HasItem("arow01",Myself)
	Global("JPFighter#1Equip","GLOBAL",2)
THEN
	RESPONSE #100
  FillSlot(SLOT_AMMO0)
  SetGlobal("JPFighter#1Equip","GLOBAL",3)
END

IF
	HasItem("jpclbw",Myself)
	Global("JPFighter#1Equip","GLOBAL",3)
THEN
	RESPONSE #100
  FillSlot(SLOT_WEAPON0)
  SetGlobal("JPFighter#1Equip","GLOBAL",4)
END

IF
	!HasItem("jpp1lswd",Myself) //Just checking to be sure
	!HasItem("jpp1shld",Myself) //Just checking to be sure
	Global("JPFighter#1Equip","GLOBAL",4)
THEN
	RESPONSE #100
  GiveItemCreate("jpp1lswd",Myself,0,0,0) //Creating the item again
  GiveItemCreate("jpp1shld",Myself,0,0,0) //Creating the item again
  SetGlobal("JPFighter#1Equip","GLOBAL",0)
END

So, basically, through dialogue, the player can figure out if the merc has a bow and doesn't have ammo, and then the script takes care of equipping the bow.

However, the big problem is that it doesn't work. I've experimented with FillSlot() a bit and it worked for equipping a Helmet and Armor, but it's not working for Weapons...

Oh, and I should note that the mercenary does have the sword jpp1lswd equipped and he also has a bow in his inventory. (jpclbw to be exact)

Anyone have a clue here?
Check out BG1Tutu.

#2 -Guest-

-Guest-
  • Guest

Posted 06 November 2002 - 08:41 PM

Nevermind folks I've figured it out. ;)

You have to use EquipRanged(), although I still don't understand why FillSlot(SLOT_WEAPON0) won't work.

Anyone know any reasons why FillSlot(SLOT_WEAPON0) doesn't work?