Jump to content

script to change npc name while in combat


Guest Pyro

Recommended Posts

a few months back i made a post asking how to polymorph a npc during combat mode. specifically to become a werewolf. here is the script we came up with:

IF
OnCreation()
THEN
RESPONSE #100
	SetGlobal("form","LOCALS",1)
END

IF
Global("form","LOCALS",1)
!CombatCounter(0)
THEN
RESPONSE #100
	ActionOverride("Korgan",Polymorph(WEREWOLF))
	SetGlobal("form","LOCALS",2)
END

IF
Global("form","LOCALS",2)
CombatCounter(0)
THEN
RESPONSE #100
	ActionOverride("Korgan",Polymorph(FIGHTER_MALE_DWARF_LOW))
	SetGlobal("form","LOCALS",1)
END

 

my question now is this: is there a way to change the name of that character from their human name (when not in combat) to another name (say 'werewolf') when they are in combat, and thus, polymorphed into the werewolf form?

 

again, i am a complete novice to the script thing so if someone could actually write the script or tell me exactly what lines of code id need to put into the above script, then thatd be great. thanks

Link to comment
ActionOverride("Korgan",Polymorph(FIGHTER_MALE_DWARF_LOW)
This is incompatible with some mods like Infinity Animations, and is identical to FIGHTER_MALE_DWARF in the BG2 engine, so use that instead.

you mean just remove the '_LOW' part from what i originally have?

 

another question: is there a way to change the portrait that is displayed while in combat? so when not in combat it has the standard/normal portrait you select, but then when entering combat, the portrait changes? i looked at the list of script actions but didnt see anything about it

Link to comment
you mean just remove the '_LOW' part from what i originally have?
Yes.
another question: is there a way to change the portrait that is displayed while in combat?
You can use a spell or effect with opcode #107 (portrait change) but the problem is that you need to explicitly set it back to the original portrait (I think - it might reset if you use a duration but from what I recall of my testing, I don't think so). And the issue with that is that you can use the default NPC's portrait but someone may have used a mod to change it to something else.
Link to comment
another question: is there a way to change the portrait that is displayed while in combat?
You can use a spell or effect with opcode #107 (portrait change) but the problem is that you need to explicitly set it back to the original portrait (I think - it might reset if you use a duration but from what I recall of my testing, I don't think so). And the issue with that is that you can use the default NPC's portrait but someone may have used a mod to change it to something else.

i wont be using any mods so thats not a prob. but i will be using custom portraits for both the non-combat and combat. so is there a way to use the opcode #107 (portrait change) effect to take place at the start of battle, and then do it again at the end of battle? again, i know nothing of how to do this so if anyone has an idea, could you please give me the code to try out, because i wouldnt know how to do it myself anyway. thanks

Link to comment

You need to make two new spells. One will change the character's portraits to the the in-combat state and the other will change them to the out-of-combat state.

 

Assuming you aren't at all familiar with modding, here is a step-by-step tutorial on how to do this. I'd rather help you learn to help yourself than spoon-feed you.

 

To make new spells, it's best to grab Near Infinity (old and stable or new and improved) and duplicate an existing spell that behaves similarly to what you want - SPCL241.SPL is a good example. It permanently gives characters who have the Undead Hunter kit bonuses to hit and damage against undead creatures. Open Near Infinity, find the file, right click it, and export. Save it with a new name in a place where you can find it later, then open this new file. This will ensure that the original SPCL241.SPL file will remain unaltered.

 

Note: keep the names of all spells, portraits, and other resources to 8 characters or fewer.

 

We'll start by making the spell that changes the character's portraits when he enters combat. Once you have opened your new spell, select the "Edit" tab at the top of the window. The spell has one ability, viewable at the very bottom. If you double click the ability, you'll see that it has 2 effects set to "Use EFF File (177)". These are not the effects we want, but it will be very easy to turn them into our desired portrait changes. Open up the first effect. Change the "Type" field to "Change Portrait (107)". You'll now have to select which portrait you want to change: the small one or the large one. Set the "Which portrait?" field to "Small". Your final step is to provide the name of this small portrait file. Right click on the "Resource" field and choose "Edit as string". Then, double click the field and type in the name of your small in-combat image file, without the .bmp extension. You can now close the effect. If you want the spell to swap the character's large portrait as well, you should repeat the procedure on the spell's other "Use EFF File (177)" effect. Otherwise, if you only want the small portrait to be changed, you should delete the other effect by selecting it and clicking the Remove button at the bottom of the window.

 

Once you've finished all this, you can close the ability window and click the Save button in the bottom right. Once saved, you can export a copy of this spell for the out-of-combat version. The only thing you'll have to do for it is open up the effects and change the portrait names to the out-of-combat ones.

 

The script you posted above already has the triggers for when the spells should be applied, so you'll just need to add a spellcasting action in with the polymorph. The actual command would be something like ApplySpellRES("MYSPELL","Korgan").

Link to comment

Mike1072, you rock! it worked like a charm. thank you so much for the in depth walkthrough. thats exactly what i needed

 

i am having some trouble with getting the name change to work...

someone here gave me this: 288 SetName(I:STRREF*)

i tried it with and without the 288 in front, with and without the "I:", with and without the "*" at the end. and nearinfinity wont let me save the changes. what should this code be?

 

another issue. when i load the game, the screen is off center to the left when the resolution is anything higher then 640x480. my computer is set at 1024x768 and works fine, but when i load the game its off to the left. when i configure the settings, the reg green blue square test is off center to the left also. is there a fix for this or am i stuck playing it at crappy 640x480? thanks

Link to comment
Mike1072, you rock! it worked like a charm. thank you so much for the in depth walkthrough. thats exactly what i needed

Glad to hear!

 

i am having some trouble with getting the name change to work...

someone here gave me this: 288 SetName(I:STRREF*)

i tried it with and without the 288 in front, with and without the "I:", with and without the "*" at the end. and nearinfinity wont let me save the changes. what should this code be?

See here. The I:STRREF* means that this parameter is an integer representing a reference to a string. If those strings already exist in your game, you'll want to look up the references to them in dialog.tlk (using NI's Search -> StringRef command). "Werewolf" is 22780, so to change the character's name to that, you'd use SetName(22780).

 

IF
 OnCreation()
THEN
 RESPONSE #100
SetGlobal("form","LOCALS",1)
END

IF
 Global("form","LOCALS",1)
 !CombatCounter(0)
THEN
 RESPONSE #100
ActionOverride("Korgan",Polymorph(WEREWOLF))
ApplySpellRES("portwolf","Korgan")
SetName(22780)
SetGlobal("form","LOCALS",2)
END

IF
 Global("form","LOCALS",2)
 CombatCounter(0)
THEN
 RESPONSE #100
ActionOverride("Korgan",Polymorph(FIGHTER_MALE_DWARF))
ApplySpellRES("portkorg","Korgan")
SetName(1138)
SetGlobal("form","LOCALS",1)
END

Link to comment

ooooh ok. so it references to a preexisting string thats already in the game. i see. i was hoping to be able to set the value myself so it would display whatever text i put in the field. like: SetName(Korgan) or: SetName(Werewolf)

 

i actually want to use custom names. how would i go about doing that? thanks

 

ps - solved the screen off-center problem. i had to change the display frequency in the ini file. it was set to 60 which is too low. that was prolly high back then, since this game is so old lol

Link to comment
ooooh ok. so it references to a preexisting string thats already in the game. i see. i was hoping to be able to set the value myself so it would display whatever text i put in the field. like: SetName(Korgan) or: SetName(Werewolf)

 

i actually want to use custom names. how would i go about doing that? thanks

To do that, I'd use WeiDU to create an installer for the mod. If you don't already have one, you just need a text file like this:

BACKUP ~werewolf_fun/backup~
AUTHOR ~Pyro~

//README ~werewolf_fun/readme-werewolf_fun.html~

VERSION ~v1~

LANGUAGE ~English~
	 ~english~

BEGIN ~Werewolf Combat~

Save this file as setup-werewolf_fun.tp2. This is the skeleton for your installer, and later we will add more to this to describe what we actually want WeiDU to do.

 

You need a copy of WeiDU to do the work of installing your mod. You can either grab the latest version of WeiDU.exe from its website (direct link here), or make a duplicate of any of the setup-modname.exe files you have from other mods. Once you have this .exe file, rename it to setup-werewolf_fun.exe.

 

You should now have the following:

  • one setup-werewolf_fun.exe program in your BG2 directory
  • one werewolf_fun folder in your BG2 directory
  • one setup-werewolf_fun.tp2 file in your werewolf_fun folder

To get WeiDU to compile your script instead of doing it in Near Infinity, you should do the following:

  1. If your desired script file is script01.bcs, make a new text file called script01.baf in your werewolf_fun folder. (You haven't said if you're making a new .bs file for player characters to select, making a new .bcs file to add to a specific creature, or appending to an existing .bcs file, but the process for all is quite similar.)
  2. Paste your scripting commands into the file.
  3. Instead of SetName(22780) and SetName(1138), use SetName(placeholder_Werewolf) and SetName(placeholder_Korgan).
  4. Add the following lines to your setup-werewolf_fun.tp2 file:
    COMPILE ~werewolf_fun/script01.baf~
     REPLACE ~placeholder_Werewolf~ ~Werewolf~
     REPLACE ~placeholder_Korgan~ ~Korgan~


    The REPLACE commands will replace all instances of the first argument (placeholder_Werewolf) found in the script with a string reference to the second argument (Werewolf). If this string is already in dialog.tlk, it will find it and use that reference (22780). Otherwise, it will add the string to dialog.tlk and use the new reference.

That's all you need to do to compile your script. However, since we're here anyway, why don't we make the entire mod installable with WeiDU? The two spell files you made to switch between in-combat and out-of-combat portraits can be copied over using WeiDU. This will allow you to install and uninstall the entire mod extremely easily.

 

Put the two spell files (which I'll refer to as polywolf.spl and polykorg.spl) in your werewolf_fun folder. Now, add these lines to your setup-werewolf.tp2 file:

COPY ~werewolf_fun/polywolf.spl~ ~override~
 ~werewolf_fun/polykorg.spl~ ~override~

 

Your entire setup-werewolf.tp2 file should now look like this:

BACKUP ~werewolf_fun/backup~
AUTHOR ~Pyro~

//README ~werewolf_fun/readme-werewolf_fun.html~

VERSION ~v1~

LANGUAGE ~English~
	 ~english~

BEGIN ~Werewolf Combat~

COPY ~werewolf_fun/polywolf.spl~ ~override~
 ~werewolf_fun/polykorg.spl~ ~override~

COMPILE ~werewolf_fun/script01.baf~
 REPLACE ~placeholder_Werewolf~ ~Werewolf~
 REPLACE ~placeholder_Korgan~ ~Korgan~

You should be able to save the file and install your mod by running setup-werewolf_fun.exe in your BG2 folder.

Link to comment

umm...im not using any mod. im not familiar with mods at all. is there a way to just make a script that can change the name using Near Infinity?

Link to comment
umm...im not using any mod. im not familiar with mods at all. is there a way to just make a script that can change the name using Near Infinity?

Yes, if you manually add the strings to dialog.tlk (Edit -> Dialog.tlk) and then supply the string references. It's certainly doable, but this is not a modern practice, and being able to install your mod with WeiDU is a much better skill to have. Using WeiDU will make your mod sharable and much easier to edit (e.g. if you decide you want to add 20 strings to dialog.tlk instead of 2).

 

If you were able to follow the NI mini-tutorial without any additional assistance, I expect you won't have any trouble following the instructions in the previous post to create your very own complete mod. If you run into any problems, though, there are always people here willing to help out.

Link to comment

alright i figured it out. thanks

 

one last problem: i want to change my npc names. for the werewolf, i got that covered with the above script that changes it for being in and out of combat. but for the others, i just want them to have one and only one name. now...i thought this would be simple, i figured id just change the name of the npc in shadowkeeper after i loaded the saved game. but its greyed out and wont let me change it to whatever i want (i swear you can do this in gatekeeper). however, i can change the name to a preexisting string reference that looks like this: 0x0000085F

 

my question is, can i go about creating my own string reference # like the one above with my custom names in the field and change them that way? how would i go about doing this in nearinfinity? thank you

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...