Quick Scripting Question

Questions specific to OpenMW-CS can be asked, and content development related topics can be discussed here
Post Reply
User avatar
ArashiAganawa
Posts: 64
Joined: 02 Feb 2017, 02:11

Quick Scripting Question

Post by ArashiAganawa » 31 Jan 2021, 08:18

So I'm working on a mod in the CS that incorporates the "resurrect" command functionality. Basically, the player is give a "Resurrection Stone" (an Harry Potter fans here?) and when they die, if the stone is in their inventory, it brings them back to life, casts Almsivi intervention, hits them with a custom restore spell (restore health/magic/fatigue/attributes) and is also removed from their inventory. Now, I want to make sure I do this right, so I'm going to write some pseudo code then ask my question, and just let me know if I'm on the right track please.

Code: Select all

Check for "Resurrection Stone" in PC inventory
while true
	if PC health == 0
		player->Resurrect
		player->addspell "Almsivi Intervention"
		player->addspell "custom restore"
		player->removeitem "Resurrection Stone ID"
		
Something to that effect anyway. I haven't looked over the documentation on scripting, so this is by no means what the code will actually look like. The questions I have are these
1. Am I correct in assuming that putting resurrect first in the list will avoid the pause screen that makes the player pick to either load or start a new game
2. Is there a way to make the Almsivi intervention spell actually cast on the player? Or will this just add another spell to their inventory which they would then have to cast? I want to force it on them so they have to go to the nearest tribunal temple.
3. Would a while loop really work (or something to a similar effect) or is there a better way to handle making sure the player has it? Such as a quick check at health == 0 instead?

That's all I need to know for now. I thank you for all the hard work you've all done. If it wasn't for OpenMW this sort of thing really wouldn't work. Being able to resurrect the player character without breaking the game is nice.

edit: after some testing the Resurrect command works before the death animation even has a chance, so that's good. Thus far I have a working script to res the player! It's not attached to anything, but it works!

-Gabe the N'wah
Wisdom ,without love, is foolishness. Knowledge, without heart, is ignorance.

EvilEye
Posts: 23
Joined: 12 Feb 2014, 13:45
Gitlab profile: https://gitlab.com/Assumeru

Re: Quick Scripting Question

Post by EvilEye » 31 Jan 2021, 11:19

2. What you did will simply teach the player the spell. If you want the effect applied to the player you can force the player to drink a potion:

Code: Select all

player->equip p_almsivi_intervention_s
3. A while loop will just freeze your game till it ends.

Code: Select all

player->OnDeath
would be the usual way of checking if an actor has died, but you'd have to test to see if that fires early enough for resurrection to work. Otherwise checking the player's health makes sense.

User avatar
ArashiAganawa
Posts: 64
Joined: 02 Feb 2017, 02:11

Re: Quick Scripting Question

Post by ArashiAganawa » 31 Jan 2021, 20:35

EvilEye wrote:
31 Jan 2021, 11:19
2. What you did will simply teach the player the spell. If you want the effect applied to the player you can force the player to drink a potion:
So will I also need to quickly add the potion to the inventory? Then equip it? Or will the act of equipping just work?
EvilEye wrote:
31 Jan 2021, 11:19
3. A while loop will just freeze your game till it ends.
Well I'm glad you told me that!

I do have a working script for now

Code: Select all

Begin test
Short onetime 
if Player->gethealth == 0
	if (onetime == 0)
		Player->Resurrect
		set onetime to 1
		endif
	endif
End test
The script will only be started when the item is added to the player inventory. I want to make sure to stop the script if they drop it as well. On top of that, the item in question will have a script on it to restart the "test" script if they do happen to pick it back up.

What I have right now in terms of the concept is this. Vivec offers the stone to the player during the main quest. Should they take it, it will use the dialogue system to add the stone and start the script. Once started it works (I tested it a few times) upon death however, it will be removed Player->removeitem custome_id_here 1. That will be added to the script. There will also be some kind of message saying it was destroyed in place of the Player dying, or something along those lines.

Things I need to do. Add the magics to the script (I don't need restore health as it turns out, and I've decided to knock the player out for a few seconds with a short drain fatigue spell), add the remove item to the script (and also create said item) and also have a conditional that checks to make sure the item is in the player's inventory and stop the script if it isn't.

Code: Select all

Begin test
Short onetime 
if Player->gethealth == 0
	if (onetime == 0)
		Player->Resurrect
		Player->equip p_almsivi_intervention_s
		player->equip p_custom_restore
		player->do something here that adds the effect to knock the player out and bypass magic resistance
		player->removeitem restone 1
		MessageBox "The stone was shattered upon your death, dying in place of you", "Ok"
		set onetime to 1
		endif
	endif
End test
Thanks for the advice and help! I'm really enjoying this whole learning scripting and coding thing I've been doing for the past year!
Wisdom ,without love, is foolishness. Knowledge, without heart, is ignorance.

User avatar
ArashiAganawa
Posts: 64
Joined: 02 Feb 2017, 02:11

Re: Quick Scripting Question

Post by ArashiAganawa » 31 Jan 2021, 20:52

As fate would have it, I don't need to add the potion to inventory

update:

Code: Select all

Begin test
Short onetime 
Short checkInventory
set checkInventory to (player->GetItemCount, ResStoneTest)
if (player->GetItemCount, ResStoneTest >= 1)
	if Player->gethealth == 0
		if (onetime == 0)
			Player->Resurrect
			Player->removeitem ResStoneTest 1
			Player->equip p_almsivi_intervention_s
			player->equip p_restore_all
			Messagebox "The stone was shattered", "ok"
			set onetime to 1
			endif
		endif
	endif
End test
This code works perfectly so far. So long as the player has the item, they are revived. Now I just need to knock them out, which I'm musing about how to do. Equipping a potion won't work if they have 100% Magic resist. Adding a spell effect like one would if the player equipped an item (like a scripted constant effect spell) would bypass that. I want to see, however, if there is a way to check max fatigue, store that variable, set fatigue to zero, then set it back to full after five seconds. Upon further thought, this seems like an arbitrary thing to do, there really is no need. More testing is needed. I hope y'all don't mind me posting these codes here. I'm open to criticism on how to do it.
Wisdom ,without love, is foolishness. Knowledge, without heart, is ignorance.

User avatar
silentthief
Posts: 447
Joined: 18 Apr 2013, 01:20
Location: Currently traversing the Ascadian Isles

Re: Quick Scripting Question

Post by silentthief » 02 Feb 2021, 02:15

ArashiAganawa wrote:
31 Jan 2021, 20:52
As fate would have it, I don't need to add the potion to inventory

update:

Code: Select all

... Player->removeitem ResStoneTest 1...
This code works perfectly so far. So long as the player has the item, they are revived.
I'm glad that the item works as intended, but I would make sure that the item doesn't disappear if a player activates it (specifically, if you "activate" a potion - you use it, in theory you drink/eat it, and it disappears from your inventory)

ST
ps - not a dev, but I know a little about mod making and scripting
100% not a dev, but I know a little about Linux, MW, and scripting. I try to help. LMK if you have any questions.

Current MW quote: "I don't recall using teleportation. Yet there I was. Alone. Naked."

User avatar
ArashiAganawa
Posts: 64
Joined: 02 Feb 2017, 02:11

Re: Quick Scripting Question

Post by ArashiAganawa » 05 Feb 2021, 23:46

Out of curiosity, why wouldn't you remove the item from the player inventory? I'm wanting to make sure after it saves them it's gone for good. So far the code seems to work as it should, but I want to know if there's a reason it should be left in their inventory. It's not a consumable that you have to equip, it's a misc. item, if that makes a difference. It's auto used when they die, so you don't need to hotkey or drag and drop it on the inventory "paper doll" to use it. Is there a reason to not remove it? I'm genuinely curious, as I don't want to make a big mistake and screw up the mod as a whole. This being a small part of it. Advice is always welcome!
Wisdom ,without love, is foolishness. Knowledge, without heart, is ignorance.

User avatar
silentthief
Posts: 447
Joined: 18 Apr 2013, 01:20
Location: Currently traversing the Ascadian Isles

Re: Quick Scripting Question

Post by silentthief » 16 Feb 2021, 18:58

ArashiAganawa wrote:
05 Feb 2021, 23:46
Out of curiosity, why wouldn't you remove the item from the player inventory? I'm wanting to make sure after it saves them it's gone for good. So far the code seems to work as it should, but I want to know if there's a reason it should be left in their inventory. It's not a consumable that you have to equip, it's a misc. item, if that makes a difference. It's auto used when they die, so you don't need to hotkey or drag and drop it on the inventory "paper doll" to use it. Is there a reason to not remove it? I'm genuinely curious, as I don't want to make a big mistake and screw up the mod as a whole. This being a small part of it. Advice is always welcome!
I think that if it works as intended, then don't make any changes. What I was thinking though is if it was of the potions/ingredients category then you may want to make it something else. Specifically if the player accidentally activates it (as in, eats it) it is gone and not usable when needed. I only mention that as I made that mistake once when I was playing on Xbox with the quest item ingredient from this quest -> https://en.uesp.net/wiki/Bloodmoon:A_Wi ... etribution (had to restart, so I remember to not accidentally eat gems or other things I may need to save)

ST
PS - edited for clarity
100% not a dev, but I know a little about Linux, MW, and scripting. I try to help. LMK if you have any questions.

Current MW quote: "I don't recall using teleportation. Yet there I was. Alone. Naked."

User avatar
ArashiAganawa
Posts: 64
Joined: 02 Feb 2017, 02:11

Re: Quick Scripting Question

Post by ArashiAganawa » 16 Feb 2021, 23:55

silentthief wrote:
16 Feb 2021, 18:58
ArashiAganawa wrote:
05 Feb 2021, 23:46
Out of curiosity, why wouldn't you remove the item from the player inventory? I'm wanting to make sure after it saves them it's gone for good. So far the code seems to work as it should, but I want to know if there's a reason it should be left in their inventory. It's not a consumable that you have to equip, it's a misc. item, if that makes a difference. It's auto used when they die, so you don't need to hotkey or drag and drop it on the inventory "paper doll" to use it. Is there a reason to not remove it? I'm genuinely curious, as I don't want to make a big mistake and screw up the mod as a whole. This being a small part of it. Advice is always welcome!
I think that if it works as intended, then don't make any changes. What I was thinking though is if it was of the potions/ingredients category then you may want to make it something else. Specifically if the player accidentally activates it (as in, eats it) it is gone and not usable when needed. I only mention that as I made that mistake once when I was playing on Xbox with the quest item ingredient from this quest -> https://en.uesp.net/wiki/Bloodmoon:A_Wi ... etribution (had to restart, so I remember to not accidentally eat gems or other things I may need to save)

ST
PS - edited for clarity
It's a misc item, so can't be eaten, but that would be hilarious. Just imagine, you have a stone that can bring you back to life, and you accidentally eat it! Would be even more ironic if eating it was fatal... now I want to make a joke mod... :lol:
Wisdom ,without love, is foolishness. Knowledge, without heart, is ignorance.

Post Reply