Jump to content

Need Help with Papyrus


Syfor

Recommended Posts

Sorry it took me so long I had to work a 4am shift today. Sucks to work 12 hrs on Sunday but the double pay is awesome =]. The script has an overcharged weapon workaround and checks the left hand for weapon types. I'll try to explain what doesn't seem apparent. Let me know if you have questions.

 

Scriptname WeaponChargerScript extends activemagiceffect  

int property charge = 50 auto
int property cost = 10 auto
;;;;You want these as properties simply so that they can be edited easily outside the script.

bool property casting = True auto
;;;;You want this to be a property so it will work anywhere in the script
;;;;Note properties are declared outside events. 
;;;;Regular variables only work inside the event or function they are declared.

Event OnEffectStart(Actor akTarget, Actor akCaster)
While casting
;;;; This is the main loop and will run as long as the property casting is true
If aktarget.GetAV("Magicka") < cost
casting = false
endif
;;;;Immediately ends the loop if you don't have enough magicka. Even if you hold down the spell nothing will happen.
If akTarget.GetEquippedItemType(0) > 0 ||  akTarget.GetEquippedItemType(0) < 9
;;;;Check to see if there is a weapon/staff in your left hand that can be charged
akTarget.ModAV("LeftItemCharge", charge)
akTarget.DamageActorValue("Magicka", cost)
debug.notification(Game.GetPlayer().GetActorValuePercentage("LeftItemCharge"))
utility.wait(1)
;;;;Charges the weapon, uses "cost" amount of magicka, then waits a second
else
casting = false
;;;;Ends the loop if you don't have the correct thing in you left hand (from earlier)
endif
endwhile
weapon LHItem = akTarget.GetEquippedWeapon(true) as weapon
akTarget.UnequipItem(LHItem, false, true)
akTarget.EquipItem(LHItem, false, true)
;;;;These three lines silently unequip and re-equip said weapon to eliminate using an overcharged weapon.
;;;;I tried the precentage method from steve but it always returned one otherwise this wouldn't be necessary.
endevent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
casting = false
endevent 
;;;;Ends the earlier loop if you stop casting

 

This is attached to a Magic Effect that has a Script Archtype, with a Concentration Casting Type, under the Conjuration Magic Skill. Everything else is default

The effect is attached to a spell that is Right Hand only.

Remember the mana cost is handled inside the script.

Edited by Spinner385
Link to comment
Share on other sites

Thank you very much for your help!

The script works now! I knew that it had to be something with condition for the while loop, but couldn't think of using an event when the spell finishes.

I had to tweak your script a bit:

Scriptname ChargeLHConc extends activemagiceffect  
{Charge the weapon equiped in Left Hand of caster}

bool loop = True

Event OnEffectStart(Actor Target, Actor Caster)
       Debug.Notification("Charging the weapon in your left hand")

       While loop == True
               Target.ModAV("LeftItemCharge", 5)
               Utility.Wait(0.1)
       EndWhile
EndEvent

Event OnEffectFinish(Actor Target, Actor Caster)
{this safeguard is redundant as the script will end when the spell ends}
       loop = False
       Debug.Notification("The weapon in your left hand has been charged")
EndEvent

 

The Event OnEffectFinish needed another input to make it work.

Another small tweak was to make it add 5 charge every 0.1 second. It just looks better.

 

Thank you again! I will add this spell as Soul Conversion in my mod Lost Magic soon.

Edited by Syfor
Link to comment
Share on other sites

It seems we were posting at the same time so I didn't see your new script when I posted it.

 

I checked the weapon type outside the script in the magic effect conditions window. It does exactly the same thing, but it is good to see how you check it in a script.

For the magicka cost, I think it can be handeled best by just modifying it in the spell window. Again I really appreciate it you show it in Papyrus. It will come in handy when I want another script.

Also I want damage the health of the caster "take part of his soul" every second. I did this with a seperate magic effect. I'm pretty sure it would have to work the same as with the magicka cost if I wanted it in the script.

 

I see you have renamed loop from your earlier script in casting. I think I get the principal now.

 

I knew about the overcharge problem but I couldn't figure out how to equip en re-equipe an item without knowing the ID of that item.

I still don't really get what you've done there, but it works. Do you make a new variable or can you just say LHitem and Papyrus knows that you want to unequip the lefthand item?

Anyway, I will add those lines to eliminate the overcharge problem.

 

There is one small bug. When finished charging the weapon in your left hand it re-equips in the right hand. Is there anyway to equip an item in a specific hand?

 

Many thanks!

Edited by Syfor
Link to comment
Share on other sites

weapon LHItem = akTarget.GetEquippedWeapon(true) as weapon

 

Makes a weapon variable called LHItem and stores the weapon in your left hand to it. The true part means left hand instead of right. And the "as weapon" may be redundant but just in case.

 

akTarget.UnequipItem(LHItem, false, true)

akTarget.EquipItem(LHItem, false, true)

 

Pretty self explanatory, except the true part says to make it not have notifications (silent) and the false part allows you to remove it (you can make someone permanently equip something with true).

 

I didn't see a way to equip to left hand. Sure there's some way but I couldn't find it. Steve is a much more experienced modder and may have a solution. I also tried to use his getavpercentage instead of unequipping/equipping the item. I could only get the percentage to return as 1 (or 100%), If it worked you could divide the current charge by the charge percent and get the max charge the weapon could hold. Ending the while loop when current >= max.

 

I figured you may remove the mana or equipping part. If you can get the max charge vs. current charge thing to work the mana use may be needed in the script. Otherwise you will still be using mana even though outside the casting loop.

 

NP glad to help =]

Edited by Spinner385
Link to comment
Share on other sites

The Event OnEffectFinish needed another input to make it work.

 

Oops, yeah, sorry. I was scripting off the top of my head without a compiler handy.

 

I'm not exactly sure how to query the maximum charge that a weapon can hold. Would the BaseAV be it's maximum charge, perhaps?

If it is, then something like this might prevent overcharging without needing to unequip/re-equip:

 

Scriptname ChargeLHConc extends activemagiceffect   
{Charge the weapon equiped in Left Hand of caster} 

bool loop = True 

Event OnEffectStart(Actor Target, Actor Caster) 
Debug.Notification("Charging the weapon in your left hand") 

float base = Target.GetBaseAV("LeftItemCharge") 

While loop == True 
	If Target.GetAV("LeftItemCharge") < base - 5
		Target.ModAV("LeftItemCharge", 5)
	EndIf
	Utility.Wait(0.1) 
EndWhile 
EndEvent 

Event OnEffectFinish(Actor Target, Actor Caster) 
{this safeguard is redundant as the script will end when the spell ends} 
loop = False 
Debug.Notification("The weapon in your left hand has been charged") 
EndEvent

 

If you want to "dispel" the spell as soon as the weapon is charged, something like this might work:

 

While loop == True 
	If Target.GetAV("LeftItemCharge") < base - 5
		Target.ModAV("LeftItemCharge", 5)
	Else
		Dispel()
		loop = False
	EndIf
	Utility.Wait(0.1) 
EndWhile 

 

 

Give that a try and let us know how it goes.

 

 

About equipping in the left hand, there doesn't seem to be an obvious way to force equipping in the left hand.

I have no idea if this will actually work, but maybe worth testing:

 

weapon LHItem = akTarget.GetEquippedWeapon(true) as weapon
akTarget.UnequipItem(LHItem, false, true)
SetAnimationVariableInt("iLeftHandEquipped", 1) 
akTarget.EquipItem(LHItem, false, true)

 

Possibly the SetAnimationVariableInt command might need to go after EquipItem. The info about animation variables is here. Documentation is lacking, so I'm just guessing on how this function might work. It might actually be a read-only flag, in which case we won't be able to use it to force equipping in the left hand.

 

Again, I haven't tested these scripts, I'm just brainstorming :tongue: .

Edited by steve40
Link to comment
Share on other sites

That's odd. GetAV will return the current charge, it should not be the same as GetBaseAV. Could it be that the weapon was fully charged, so the two values would be the same?

 

Why is there no "GetMaxAV" Bethesda? :wallbash:

Edited by steve40
Link to comment
Share on other sites

Actually I'm a dummy. I copy and pasted the "max" variable with GetBaseAV and didn't change it to GetAV for the "current" variable.

 

What it does is saves your charge at the start of the spell as BaseAV. Every time you cast the spell it starts at AV = BaseAV then AV grows as you charge it.

 

I can't think of a way for this to help you. It could tell you how much you charged per use. Which may be useful in some other form but not to stop overcharging. Wonder how they made soul gems not overcharge when you use them. *starts digging*

Edited by Spinner385
Link to comment
Share on other sites

This is from what I understand about the 'wonders' of the actorvalues LeftItemCharge and RightItemCharge:

-When using (peak) value modifier in the magic effects it can only recharge up to the chargelevel when it was drawn, so an empty weapon cannot be recharged this way. We need Papyrus to do it.

-Upon sheating and redrawing, the item's charge will reset to it's maximum when the charge was higher then the maximum.

-Soul gems seem to be hard-coded in the creation kit. I couldn't see any script attached to it to prevent overcharing (or any other script)

 

I think this is going on when you draw an enchanted weapon:

-Skyrim sets AV "LeftItemCharge" as the current base or maximum, that would explain why (peak) value modifier doesn't work correctly

-When unequiping, that value stored in "LeftItemCharge" is returned to weapon stats.

-Some kind of script kicks in when the value is higher than the max charge stat of the weapon, probably the same script that prevents soulgems from overcharging

-When you draw the weapon again, the value send back as the new "LeftItemCharge" will be the maximum charge.

 

I haven't been able to find any kind of script for soulgems or in the weaponstats. This is what I think is going on, now see how we can use it in Papyrus.

 

My idea would be this:

- Store the current charge in a variable

- Overcharge the weapon to an insane level (99999 charge or something)

- Force a redraw of the weapon to get it's maximum

- Store the maximum charge in a variable

- Set the "LeftItemCharge" back to it's old value

- Now we can use a condition to prevent the current value from going beyond the maximum charge

 

Many thanks Steve and Spinner, I think we're really getting somewhere now.

Edited by Syfor
Link to comment
Share on other sites

Excellent Idea!

One minor problem with that. After the initial unequip/re-equip to find its maximum it will be in the right hand. Would you be willing to make the spell left hand only? I'll start whipping up some code for you.

 

Edit: I saw you said sheathing and redrawing fixes the overcharge. I'll double check that but I thought it didn't work before and you have to unequip it.

...

Checked it has to be unequiped

Edited by Spinner385
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...