The forum has been set to read-only mode. For community discussion and questions, head over to our Discord: https://discord.taleoftwowastelands.com

Help detecting Perk Rank Via Script

General mod discussion and requests.
mr01
Posts: 21
Joined: Sat Nov 23, 2013 8:29 pm

Help detecting Perk Rank Via Script

Post by mr01 » Tue Dec 03, 2013 2:14 am

Hi, I am trying to write a script that will detect the correct level of perk rank and have run into a wall. The function HasPerk will only reply with either a 0 or a 1 if done with a script; therefore, I have been looking for another way of detecting perk ranks.


I decided on two different methods that both work. One method would be to add a hidden Ability to the perk that does nothing other than being there to be detected by the script via IsSpellTarget. The second method would be to add a hidden ability that will change a global variable, which will then be detected by the script. Both of these methods work wonderfully; however, there is a problem.


Both of these methods don't activate if the player already has the perk. It only activates when the player recieves the perk. For example, the perk i wish to detect ranks for is Demolition Expert. New players will have the script detect the ranks just fine; however, players with a save that already has demoliton expert will not activate or have the ability added until another rank of the perk is recieved. This is a problem for players that already have 3 ranks of the perk. Anyone have any idea how to circumvent this problem? Any help would be appreciated.



User avatar
rickerhk
Posts: 123
Joined: Mon Sep 17, 2012 1:50 pm

Take a look at the Intense

Post by rickerhk » Tue Dec 03, 2013 3:10 am

Take a look at the Intense Training perk. It has 10 ranks and uses a different quest stage for each rank to apply the buff.



mr01
Posts: 21
Joined: Sat Nov 23, 2013 8:29 pm

Nah that wont work either. I

Post by mr01 » Tue Dec 03, 2013 3:17 am

Nah that wont work either. I tried that as well. It will work wonderfully for a player that have not had the perk added, but it wouldn't activate for someone who already has the perk on their save (unless you make a script to re-add the perk...then it will be the same problem of how do you detect how many ranks of the perk to add back in).



Gribbleshnibit8
Posts: 481
Joined: Sun Nov 04, 2012 2:06 am

Did you test HasPerk

Post by Gribbleshnibit8 » Tue Dec 03, 2013 4:02 am

Did you test HasPerk returning only 1 or 0? Vanilla challenge scripts use it to determine what to do and if the challenge should be show a message or not.


int rank;

set rank to (player.HasPerk LordDeathChallengePerk)

if (rank < 3) set rank to (player.addperk LordDeathChallengePerk)

showmessage ChallengeMessageLordDeath

endif



JaxFirehart
Posts: 3003
Joined: Wed Sep 12, 2012 12:33 am

It says it only returns 0 or

Post by JaxFirehart » Tue Dec 03, 2013 4:08 am

It says it only returns 0 or 1 on the wiki, but I imagine that was never updated for FNV. Worth trying.



mr01
Posts: 21
Joined: Sat Nov 23, 2013 8:29 pm

Yep...i tested the hasperk

Post by mr01 » Tue Dec 03, 2013 4:38 am

Yep...i tested the hasperk and it will only reply with either 1 or 0. I even wrote a quick and dirty script to test out the hasperk to display a message of how many ranks of Lord Death when i saw that their challenge scripts used it. The result is that it will always return a 1 despite me having all three ranks of Lord Death.


Although I am quite curious as to how the HasPerk function work when used in a challenge. It is clear that they used it for their challenges, but all i am getting from using the hasperk function is either 1 or 0 in my scripts.


Edit: from further looking at their challenge script, they used a work around specifically the line "set rank to (player.addperk <perk>)". Since the script is only running when you reach a challenge threshold, they don't have to worry about the script continuously adding more ranks of the perk. However, for my case, I am messing around with some damage effect on explosives; therefore, the script would also add in an extra rank with each use. 



Gribbleshnibit8
Posts: 481
Joined: Sun Nov 04, 2012 2:06 am

I guess I had a brain fart

Post by Gribbleshnibit8 » Tue Dec 03, 2013 6:34 am

I guess I had a brain fart there. Never really considered that the challenges are base form persistent objects, and their scripts will be around forever. I was just reading the EffectUpdate block and thinking they were only created when they were needed, like real actor effect scripts are.


 


For your application then no, I don't think there is an alternative that will do what you want. When I run across this problem I just put in my mod description/readme that it is known that it will NOT be a retroactive change, and detail a fix such as removing the perk and adding it back via console, one rank at a time, giving the script a chance to process each time. Not ideal, but there are certain limitations that just can't be worked around.



JaxFirehart
Posts: 3003
Joined: Wed Sep 12, 2012 12:33 am

Never expected to hear that

Post by JaxFirehart » Tue Dec 03, 2013 1:56 pm

Never expected to hear that from Gribbles!



mr01
Posts: 21
Joined: Sat Nov 23, 2013 8:29 pm

hmmm i figured as much. I

Post by mr01 » Wed Dec 04, 2013 12:03 am

hmmm i figured as much. I tried making a script that will try to circumvent this problem via the "Addperk" function. It will be able to recognize if the player has the 1st rank of a perk; however, the real problem is recognizing rank 2 from rank 3. They both will return a value of 3 since player.addperk will return the actual rank +1 unless the player has reach the last rank, in which case, it will simply cap off at the rank it is at. I tried to make a hidden and unplayble 4th rank of a perk to circumvent this but the game doesn't allow that (i.e. even if the perk has the 4th rank entry it isn't active until you specifically tell the perk that it has a 4th entry).


Argh....this would be so simple to solve if hasperk will tell me the rank...or if the removeperk function didn't remove every single rank of perks and only remove one rank at a time.



JaxFirehart
Posts: 3003
Joined: Wed Sep 12, 2012 12:33 am

Because he still needs to get

Post by JaxFirehart » Wed Dec 04, 2013 2:13 pm

Because he still needs to get the initial rank for players who took the perk before the mod loaded.


What about testing to see if the player has any rank of Demolition Expert and, if they do, remove perk and then add perk, getting the rank from addperk?



Post Reply