Companion script help thread

Post » Wed Jun 29, 2016 2:49 pm

Since I'm probably going to have a lot of different companion script-related queries come up, I thought I would bundle them all into this one thread.



I'm really sorry to have to ask people to comb through this, but this script is too important to my mod for it to not work, and I can't seem to figure it out, so I'd definitely appreciate any insights! Also, sorry, couldn't find the spoiler option on the editor...



The companion script (the big script at the very bottom) is NON_SabrinaCompanion (her name is Sabrina); the global NON_SabrinaFollowing, which shows up a lot, tracks whether or not she's following (= 1), not following (= 0) or dead/gone (-1). For other variables / scripts called, just ask and I shall explain, if they aren't clear.



My current problems:



1) Sabrina does not warp. (Fixed -- Abot is a genius, or at least, not an idiot like me!)



Specifically, Grumpy's warping code which should regularly and rapidly bring Sabrina near to the player (find it quickly via searching the messagebox phrase "normal warp") only works very rarely. I have seen the messageboxes come up (indicating warping) a handful of times; once during combat, and once while running around on hills. Otherwise, it never goes off and Sabrina gets left behind until eventually a bit of code courtesy of Stuporstar's companions forces an emergency warp (find it quickly via searching the messagebox phrase "EMERG"). This is the only type of warping which occurs (outside of the doorDelay warping), and I am not sure why normal warping is being blocked.



Other aspects of Sabrina's movement scripts (eg. her z-position matching in levitation or swimming) do work fine.



2) The underwater detection code does not work. (Fixed by stealing the function from Kateri's Julan script)



Find it quickly via searching for the test message "n_under reset" -- the point of this is to detect when Sabrina is underwater and set a local to activate certain greetings. The messageboxes never fire, and the greetings are never activated.



TBH, I wouldn't care much if someone just told me it was impossible -- seems like a lot of scripting for a very minor immersive dialogue function.



3) Sabrina's magicka is reported incorrectly. (Also fixed... by abot. Again!)


Specifically, in the main companion script the local 'currentmagicka' is used to track Sabrina's magicka. In dialogue, she reports her magicka as a % of her total magicka, via the following:



messagebox "[Sabrina's magicka is at %.0f percent]" currentmagicka



Initially this works fine. However, after a single round of Sabrina's levelling script alters her magicka from its CS-preset level of 100 to match the player's level, the formula starts reporting her current magicka as a percentage of this initial preset CS magicka level (100) rather than as a percentage of her newly set magicka.

User avatar
barbara belmonte
 
Posts: 3528
Joined: Fri Apr 06, 2007 6:12 pm

Post » Wed Jun 29, 2016 9:10 pm

I am not sure as following that variable logic is a little difficult, but I'd try
changing
	if ( warpTimer <= 0 )
if ( PCDist > 680 )
to
	if ( warpTimer >= 0 )
if ( PCDist > 680 )
To be honest, a script calling GetDistance 3 times in a frame is not efficient
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am

Post » Wed Jun 29, 2016 1:14 pm

Wow, quite a complicated script you have there. Well, I checked the warping part and it seems fine. In other companion mods I have it uses



if ( warpTimer = 0 )

but if you are using either >= or <= then warping should happen more often, not less.



Anyway, make sure you have MCP Equip command shows weapon turned OFF (thanks to abot for this info). I had this issue recently and even posted a thread about it here. It seems that with this option in MCP turned on companions are unable to switch back from their combat mode to regular mode. And in combat mode warping is turned off.



Another thing you can try is to add more messageboxes, like this



MessageBox "Warp:Test1"
if ( warpTimer <= 0 )
MessageBox "Warp:Test2"
if ( PCDist > 680 )
MessageBox "Warp:Test3"
if ( coDist > 350 )
MessageBox "test message: normal warping"
set doorDelay to -1
SetPos x bx
SetPos y by
SetPos z bz
AIFollow Player 0 0 0 0
return
elseif ( coDist2 > 350 )
MessageBox "test message: normal warping"
set doorDelay to -1
SetPos x cx
SetPos y cy
SetPos z cz
AIFollow Player 0 0 0 0
return
endif
endif
endif

If you will not see any message in game with this code, then the problem is somewhere above in the script, since the script interpreter will not even reach the warping block. If you see only test1, problem is with the variable warptimer. If you see test1 and test2, problem is with PCDist.



Sorry I cannot help more, but unfortunatelly companion scripting is not exactly my thing.

User avatar
evelina c
 
Posts: 3377
Joined: Tue Dec 19, 2006 4:28 pm

Post » Thu Jun 30, 2016 1:13 am

I've always wanted to take a try at writing a companion script, and as much as I would like to shirk my current responsibilities to dig into this script I really should not. I will make a few general observations.




I agree with abot about the GetDistance call, and it is quite unnecessary to do it three times when the first time it is called it sets a value to the float variable pcDist that is used in later distance checks.



set pcDist to ( GetDistance Player )



I can no reason pcDist cannot be used in this portion of the script in place of the GetDistance checks:




if ( NON_SabrinaFollowing == 1 )




Speaking of efficiency, there is also this in the warp portion of the script:



set coDist to ( GetSquareRoot, t1 )



There is no need to extract the root when it is being compared to a constant. Simply square the constant:



if ( coDist > 129600 )




As for the magicka percentage reporting more than 100%, it would be helpful to know how p_magicka is defined. I might infer that it is defined by a different script. If is not defined, then its initial value is zero until the script runs once, whereupon it have a value of 50. It is has a value determined by another script the anomaly you are seeing may be a result of the order in which the two scripts run.



I wonder why Sabrina's intelligence is set so low, particularly when it is clear a relatively large magicka pool is desired. Is not intelligence a factor in determining casting success for some spells?

User avatar
Miranda Taylor
 
Posts: 3406
Joined: Sat Feb 24, 2007 3:39 pm

Post » Wed Jun 29, 2016 10:30 pm

Thank you so much for all your help! I know it must have been really daunting and / or a drag to go through such a tedious and long post, and I'm very grateful that you took the time to do so. The good news is, two of my three concerns are fixed! And the third is not so important; I'll think of something...



If anyone wants an in-mod NPC dedicated to you, please say so! I doubt anyone will, but hey, a lame promised reward is a lame promised reward...





Yes, this completely fixed the issue. Thank you! In hindsight, I should have been able to work it out from the fact that warping was happening in combat (when it shouldn't) and not at all the other times (when it should)... but I couldn't. Also, it was very stupid of me to not replace the last two GetDistance checks with pcDist ; thanks for picking that up.



And I'll also try your personality / speechcraft suggestions for blocking persuasion, so thank you for that too!






Thanks for your help! Luckily abot honed in on the problem before I had to spend some more sleepless nights on messageboxes / debugging, but it's definitely a good suggestion which I'll keep in mind for future.



Also, thanks for the heads up on the MCP issue -- I had no idea!






Thank you for your insights. I've implemented the efficiency changes which both you and abot suggested (and in hindsight it really was very stupid of me not to use pcDist for those second GetDistance checks when I used the float literally several lines above...).



On the magicka reporting, I've clarified the original post -- p_magicka is also set in the same script (now included in the post), I just forgot to include it. Increasingly I think it's a problem with me using the wrong type of reporting strategy, since Sabrina's attributes seem to be updated correctly by the levelling script.



To answer your question about her intelligence, I use the formula of her intelligence being PCLevel + 10 ; and her magicka being 6x her intelligence (i.e. magicka = 6 (PCLevel + 10)), with hardset limits of 50 and 380. That probably wasn't clear because I left out the p_magicka part in the script. All of Sabrina's spells are flagged "always succeed" and I use her current magicka rather than skill to limit their use, so I don't think the low intelligence will make problems.



Please don't feel obliged to come back and comb through the script, though. I'll keep fiddling with it, and in worse case scenario, I'll just report her spell points, rather than a percentage. Thanks again!

User avatar
Ria dell
 
Posts: 3430
Joined: Sun Jun 25, 2006 4:03 pm

Post » Wed Jun 29, 2016 9:04 pm

About the magicka perc... something like this could work (you should display the magickaperc in messagebox)
set currentmagicka to GetMagicka
ModCurrentMagicka 30000 ; maximize magicka
float magickamax
set magickamax to GetMagicka ; to store Max magicka
float magickaperc
if ( magickamax > 0.01 )
set magickaperc to ( currentmagicka / magickamax )
else
set magickaperc to 0
endif
set tempfloat to ( currentmagicka - magickamax )
ModCurrentmagicka tempfloat ; restore current magicka
User avatar
Peetay
 
Posts: 3303
Joined: Sun Jul 22, 2007 10:33 am

Post » Wed Jun 29, 2016 2:04 pm


Thank you! With a little tweaking, I put that into a script triggered in dialogue and it works great! I had to put a counter in because otherwise the magicka alterations were screwing with the main companion script's detected currentmagicka.



Begin NON_SabrinaMagicReport

; init in dialogue -- 'use of magic' , reports magicka only - basically written by abot

short counter
float currentmana
float magickamax
float magickaperc
float tempval

if ( counter < 10 )
set counter to ( counter + 1 )
return
endif
set counter to 0
set currentmana to GetMagicka ; store current mana
ModCurrentMagicka 30000 ; maximize magicka
set magickamax to GetMagicka ; store max mana
if ( magickamax > 0.01 )
set magickaperc to ( ( currentmana / magickamax ) * 100 )
else
set magickaperc to 0
endif
set tempval to ( currentmana - magickamax )
ModCurrentMagicka tempval
messagebox "[Sabrina's magicka is at %.0f percent]" magickaperc


StopScript NON_SabrinaMagicReport

End

So now all my three initial problems are solved! Hopefully I won't find any new ones soon. I've removed the scripts from the original post for clarity, but if anyone is interested with similar problems, I can repost the fixed versions.

User avatar
maria Dwyer
 
Posts: 3422
Joined: Sat Jan 27, 2007 11:24 am


Return to III - Morrowind