Well, I'm not CamDawg or Cuv, but I'll try to answer your question anyway. :P
The usage of custom tokens in BG(2):EE is very limited. Afaik, only (fixed) strrefs, variables and object names can be assigned to tokens. Additionally, your tokens aren't stored in saved games, so you have to re-initialize them each time you start or load a game.
You could use an indirect approach however. Since strength is limited to the range [0..25], you can check for each number individually. It has the disadvantage that any strength changes that occur during game play will be detected only at the beginning of the next game session. This is the code:
// checking for individual strength values of the protagonist IF OnCreation() CheckStat(Player1, 1, STR) !Global("TokenSet", "GLOBAL", 1) THEN RESPONSE #100 SetGlobal("TokenSet", "GLOBAL", 1) SetGlobal("MySTR", "GLOBAL", 1) Continue() END
IF OnCreation() CheckStat(Player1, 2, STR) !Global("TokenSet", "GLOBAL", 1) THEN RESPONSE #100 SetGlobal("TokenSet", "GLOBAL", 1) SetGlobal("MySTR", "GLOBAL", 2) Continue() END
// ...and so on for the remaining strength values 3..25
// this block will set the actual token IF Global("TokenSet", "GLOBAL", 1) THEN RESPONSE #100 SetGlobal("TokenSet", "GLOBAL", 2) SetTokenGlobal("MySTR", "GLOBAL", "MY_STR_TOKEN") END
Add this code to a creature script (e.g. of your protagonist), or the baldur[25].bcs if you can't find another way.
Now you should be able to use <MY_STR_TOKEN> in dialogs and other text messages. I'm using a similar approach in a mod that I'm working on and it works fine.
Thanks for the help. I was just trying a basic If True() and all my problems were caused since I was setting my token as instead of STR.
Can I just have this run all of the time with True() and it will constantly check the stat I am looking at? Basically, in my mod I have altered armor to have slashing/piercing/crushing/missile defense, but I have been having a heckuva time trying to mod the guiinv or guirec chus to display this natively. I can move stuff around, but cnnot figure out how to change the actual text displayed.
So, I figured I'd try to add it in. Of course, it would need to be updated as it changes. I figured there were a couple ways to do this. First, run through all 100 possibilities for all 4 stats and then pop the number up there. That seems like it would be very intensive. Second, run through all the possibilities initially on game load. Then, save that number just as a global variable and compare that number to the stat I am looking at and then run the possibilities if they are different. Since this will be occurring mostly on armor changes, it shouldn't impact the game much (I assume).
Doesn't baldur.bcs always run and thus should always update the stat in question?
Can I just have this run all of the time with True() and it will constantly check the stat I am looking at?
You can do that. But then you shouldn't place it into your character's script. Because each time one of your script blocks is executed, it will reset that character's current action. This is an example script that will check your character's strength constantly. It will update your tokens only if the strength value has been changed:
IF CheckStat(Player1, 1, STR) OR(2) OnCreation() // needed to force a first-time initialization of your token !Global("MySTR", "GLOBAL", 1) THEN RESPONSE #100 SetGlobal("MySTR", "GLOBAL", 1) SetTokenGlobal("MySTR", "GLOBAL", "MY_STR_TOKEN") Continue() END
IF CheckStat(Player1, 2, STR) OR(2) OnCreation() !Global("MySTR", "GLOBAL", 2) THEN RESPONSE #100 SetGlobal("MySTR", "GLOBAL", 2) SetTokenGlobal("MySTR", "GLOBAL", "MY_STR_TOKEN") Continue() END
// ...and so on for the remaining strength values 3..25
I'm not certain if global variables are updated immediately in the same script block. If the token isn't updated correctly, then you'll have to use a separate script block to set the token (as done in my previous script example).
Doesn't baldur.bcs always run and thus should always update the stat in question?
Not using the baldur.bcs is just a precaution. That script contains lots of script blocks already. Furthermore, megamod installations will add countless of new script blocks that have to be processed by the game, increasing the chance that your own blocks are not executed in time. If one of the mods installed a faulty script, chances are that your script blocks will never be executed at all.
Basically I am looking at 400 If Then statements if I wanted to do the 4 physical resistances. It's not hard with copying and pasting but seems ridiculously inefficient. Its ridiculous I can not just be able to print out a variable. Even so, it appears that CheckStat HAS to use an integer as it's second argument and not even a global variable that is an integer. Not sure what I was expecting with the scripting, but maybe something a little smarter than this.
I am wondering if it would be more efficient to use the HasItemEquipped and just set the global variables there.
That would actually increase the number of scripts, but maybe then reduce the amount of computational work.
IE: Script checks GT 50 True, check GT 25 and so forth until it has to get to a specific value. That would remove the need to run each other and just run down the trees. In the end, I am not sure if it is worth the effort...especially if nobody ends up playing the mod
After realizing none of this was going to work, I came across tokentxt.2da which, appears, to be exactly what I need. Of course, I am not sure how it works (though I am trial and erroring). Sending out another batsignal.
Comments
The usage of custom tokens in BG(2):EE is very limited. Afaik, only (fixed) strrefs, variables and object names can be assigned to tokens. Additionally, your tokens aren't stored in saved games, so you have to re-initialize them each time you start or load a game.
You could use an indirect approach however. Since strength is limited to the range [0..25], you can check for each number individually. It has the disadvantage that any strength changes that occur during game play will be detected only at the beginning of the next game session.
This is the code: Add this code to a creature script (e.g. of your protagonist), or the baldur[25].bcs if you can't find another way.
Now you should be able to use <MY_STR_TOKEN> in dialogs and other text messages. I'm using a similar approach in a mod that I'm working on and it works fine.
Thanks for the help. I was just trying a basic If True() and all my problems were caused since I was setting my token as instead of STR.
Can I just have this run all of the time with True() and it will constantly check the stat I am looking at? Basically, in my mod I have altered armor to have slashing/piercing/crushing/missile defense, but I have been having a heckuva time trying to mod the guiinv or guirec chus to display this natively. I can move stuff around, but cnnot figure out how to change the actual text displayed.
So, I figured I'd try to add it in. Of course, it would need to be updated as it changes. I figured there were a couple ways to do this. First, run through all 100 possibilities for all 4 stats and then pop the number up there. That seems like it would be very intensive. Second, run through all the possibilities initially on game load. Then, save that number just as a global variable and compare that number to the stat I am looking at and then run the possibilities if they are different. Since this will be occurring mostly on armor changes, it shouldn't impact the game much (I assume).
Doesn't baldur.bcs always run and thus should always update the stat in question?
Thanks again.
This is an example script that will check your character's strength constantly. It will update your tokens only if the strength value has been changed: I'm not certain if global variables are updated immediately in the same script block. If the token isn't updated correctly, then you'll have to use a separate script block to set the token (as done in my previous script example).
Not using the baldur.bcs is just a precaution. That script contains lots of script blocks already. Furthermore, megamod installations will add countless of new script blocks that have to be processed by the game, increasing the chance that your own blocks are not executed in time. If one of the mods installed a faulty script, chances are that your script blocks will never be executed at all.
I am wondering if it would be more efficient to use the HasItemEquipped and just set the global variables there.
IE: Script checks GT 50
True, check GT 25
and so forth until it has to get to a specific value. That would remove the need to run each other and just run down the trees. In the end, I am not sure if it is worth the effort...especially if nobody ends up playing the mod
@CamDawg