Maxandmov Posted August 14, 2014 Share Posted August 14, 2014 Hello again. I've been scripting some interesting script with NVSE, but struck into a problem. I need to have my gun taken from me and given another one with a click of a button. The given one should have the same condition as my taken gun does. I've tried two ways of doing this percentage thing to work, both were a failure. Please help me to deal with this. There are these variants down there.So, first variant. Via mostly NVSE functions (which don't happen to work correctly to me, my given gun gets maximal health instead of the one it got in the variable or something is done wrong here) float GunHealth short GunEquipped begin GameMode set GunEquipped to player.GetEquipped NVDLC02Weap45AutoPistolUnique if IsKeyPressed 16 == 1 if GunEquipped == 1 set GunHealth to player.GetEqCurHealth 5 player.removeitem NVDLC02Weap45AutoPistolUnique 1 1 player.AddItem NVDLC02Weap45AutoPistolUniqueMeleePlayable 1 1 player.equipitem NVDLC02Weap45AutoPistolUniqueMeleePlayable 0 1 player.SetEqCurHealth GunHealth 5 endif endif end Another one is via AddItemHealthPercent and one of NVSE functions. This would even appear to be better than the first one since I'd use this one better than the previous one (because gun used as a melee breaks faster than the same gun used to shoot) float GunHealth short GunBaseHealth short GunEquipped begin GameMode set GunEquipped to player.GetEquipped NVDLC02Weap45AutoPistolUnique if IsKeyPressed 16 == 1 if GunEquipped == 1 set GunHealth to player.GetEqCurHealth 5 set GunBaseHealth to NVDLC02Weap45AutoPistolUnique.GetHealth player.removeitem NVDLC02Weap45AutoPistolUnique 1 1 player.AddItemHealthPercent NVDLC02Weap45AutoPistolUniqueMeleePlayable 1 GunHealth/GunBaseHealth 1 player.equipitem NVDLC02Weap45AutoPistolUniqueMeleePlayable 0 1 endif endif end Remiding you that those two doesn't work as expected..I'm very thankful for any help you can provide to me. Link to comment Share on other sites More sharing options...
jazzisparis Posted August 14, 2014 Share Posted August 14, 2014 Try this: float GunHealth begin GameMode if player.GetEquipped NVDLC02Weap45AutoPistolUnique if IsKeyPressed 16 set GunHealth to player.GetWeaponHealthPerc / 100 player.removeitem NVDLC02Weap45AutoPistolUnique 1 1 player.AddItemHealthPercent NVDLC02Weap45AutoPistolUniqueMeleePlayable 1 GunHealth 1 player.equipitem NVDLC02Weap45AutoPistolUniqueMeleePlayable 0 1 endif endif end Link to comment Share on other sites More sharing options...
Maxandmov Posted August 14, 2014 Author Share Posted August 14, 2014 No, it still has zero health while given an item. Hell if I knew what's wrong really. Link to comment Share on other sites More sharing options...
Ladez Posted August 16, 2014 Share Posted August 16, 2014 You own scripts won't work because GetEqCurHealth and SetEqCurHealth don't work the way you expect them to. They don't treat the health as a percentage, but rather as the actual current value of their health. A Light Shining in Darkness has 250 health at full condition while the melee version only has 100, so even if the gun was damaged as low as 40% you would still get a full condition melee version. For it to work your way, both versions would have to have the same health at full condition. The script jazzis posted should do what you want - I tested it and it works in my game. Could you post the script you're using now so we can see if you did something wrong? Link to comment Share on other sites More sharing options...
Maxandmov Posted August 16, 2014 Author Share Posted August 16, 2014 (edited) SCN NVDLC02JoshuaGunPickupSCRIPT ;DM 1/27/11 - Created ;Removes non-interactable weapons from Joshua's corpse when the player picks up the unique weapon BEGIN OnAdd NVDLC02JoshuaREF.RemoveItem NVDLC02Weap45AutoPistolUniqueMelee 1; NVDLC02JoshuaREF.RemoveItem NVDLC02Weap45AutoPistolUniqueNPC 1; END ;mod lines ahead. ;FOSE REQUIRED!! float GunHealth short GunBaseHealth ;short GunEquipped ;begin GameMode ;set GunEquipped to player.GetEquipped NVDLC02Weap45AutoPistolUnique ;if IsKeyPressed 16 == 1 ;if GunEquipped == 1 ;set GunHealth to player.GetEqCurHealth 5 ;set GunBaseHealth to NVDLC02Weap45AutoPistolUnique.GetHealth ;player.removeitem NVDLC02Weap45AutoPistolUnique 1 1 ;;player.AddItem NVDLC02Weap45AutoPistolUniqueMeleePlayable 1 1 ;player.AddItemHealthPercent NVDLC02Weap45AutoPistolUniqueMeleePlayable 1 GunHealth/GunBaseHealth 1 ;player.equipitem NVDLC02Weap45AutoPistolUniqueMeleePlayable 0 1 ;;player.SetEqCurHealth GunHealth 5 ;endif ;endif ;end begin GameMode if player.GetEquipped NVDLC02Weap45AutoPistolUnique if IsKeyPressed 16 set GunHealth to player.GetWeaponHealthPerc / 100 player.removeitem NVDLC02Weap45AutoPistolUnique 1 1 player.AddItemHealthPercent NVDLC02Weap45AutoPistolUniqueMeleePlayable 1 GunHealth 1 player.equipitem NVDLC02Weap45AutoPistolUniqueMeleePlayable 0 1 endif endif end This is the whole script as it is for now. I've retried the script again. It DOES NOT work. I don't know why, I wish I could know or I wish it wouldn't be bugging my mind. Lots of mods can't be the reason of this happening, can they? :wacko:  UPD: I've edited melee version's health even before you've asked. They two have same health. I did it just because I expected the thing to work wrong.  Edited August 16, 2014 by Maxandmov Link to comment Share on other sites More sharing options...
Ladez Posted August 16, 2014 Share Posted August 16, 2014 (edited) Good, now I get what the problem is. Assuming that you've just modified the original script for the gun, you're running the script as an object script on the reference of the gun that is added to your inventory. When you remove that gun from your inventory with RemoveItem, the script has no reference to run on anymore. The script will execute the last few lines, but it seems like the variables are flushed immediately, causing AddItemHealthPercent to use an empty variable - ie. zero - for the health percentage. You should a quest script instead, it is guaranteed to run as long as the quest is active. First off, take the script from jazzis post and save it as a separate script, and make sure that you set the script type to quest. Then you need to create a new quest, but you only need to change a couple settings in it. You should turn on "start game enabled" and apply the quest script you just created to it. You should probably also set a script processing delay to something small like 0.1 second, so the hotkey is more responsive. For reference, the default delay is 5 seconds. Also, don't forget to restore the original script, so you don't have them both trying to do the same thing. Edited August 16, 2014 by Ladez Link to comment Share on other sites More sharing options...
Maxandmov Posted August 16, 2014 Author Share Posted August 16, 2014 Good, now I get what the problem is. Assuming that you've just modified the original script for the gun, you're running the script as an object script on the reference of the gun that is added to your inventory. When you remove that gun from your inventory with RemoveItem, the script has no reference to run on anymore. The script will execute the last few lines, but it seems like the variables are flushed immediately, causing AddItemHealthPercent to use an empty variable - ie. zero - for the health percentage. You should a quest script instead, it is guaranteed to run as long as the quest is active. First off, take the script from jazzis post and save it as a separate script, and make sure that you set the script type to quest. Then you need to create a new quest, but you only need to change a couple settings in it. You should turn on "start game enabled" and apply the quest script you just created to it. You should probably also set a script processing delay to something small like 0.1 second, so the hotkey is more responsive. For reference, the default delay is 5 seconds. Also, don't forget to restore the original script, so you don't have them both trying to do the same thing.I will try it tomorrow; it's kinda late today. Thanks for the help no matter if it helps anyways. Link to comment Share on other sites More sharing options...
Ladez Posted August 16, 2014 Share Posted August 16, 2014 No problem - let me know if it works out for you :) Link to comment Share on other sites More sharing options...
Maxandmov Posted August 17, 2014 Author Share Posted August 17, 2014 (edited) Now it actually works!Thanks both of you. You can't even imagine how much you helped me, really.Kudos to both of you given. Edited August 17, 2014 by Maxandmov Link to comment Share on other sites More sharing options...
Ladez Posted August 17, 2014 Share Posted August 17, 2014 Glad I could be of help. Link to comment Share on other sites More sharing options...
Recommended Posts