Jump to content

Problem with Cast function


Recommended Posts

Hi to everyone.

I'm creating a mod which makes you able to add and remove armors and saddles from horses. I use a scroll with a scripted effect to place the saddle/armor model and it works perfectly. I then show a menu when you activate the horse in sneaking mode, and you are given the possibility of taking off the saddle/armor. If you choose so, the player or an activator should cast a spell with another scripted effect to remove the model.

 

Unfortunately, I can't seem to make it work. I read somewhere in the wiki that with player.cast you cannot force a player to cast a spell with a target other than self, so I tried with an activator, but it still doesn't work. The activator is properly teleported in place but the script will not make it cast.

 

I tried both player and activator, with spell set to target, touch and self. It doesn't appear to be cast at all. Spell has a fire effect to see if it's cast properly. I read about player not able to cast in menumode situations, so I tried with activator.

 

Some ideas about what's wrong in all this? May it be related to this being a quest script?

 

Just to be clear, the two effects do work properly if tested outside of the menu. I can add and remove armor by casting everything from console. I just can't seem to make the "remove" casting work from the menu.

 

I'll post the horse/menu script only in here, please tell me if you need the other code.

 

Thanks in advance if you are spending time reading all this :)

 

 

ScriptName AxelMountsActionMenuScript

; Public variables
ref mount
ref unarmorspell
ref unsaddlespell
ref mounttype

; Private variables

float fQuestDelayTime

short initdone
short countdown
short choice
long section

Begin GameMode
if ( initdone != 1 )
	let fQuestDelayTime := 0.001
	let countdown := 0
	let section := -1
	let initdone := 1
endif

if ( section == 0 )
	let initdone := 0
	StopQuest AxelMountsActionMenuQuest
	return
elseif ( section > 0 ) && ( choice == -1 )
	if ( countdown < 30 )
		let choice := GetButtonPressed
		if ( choice == -1 )
			if ( MenuMode 1001 == 0 )
				if (MenuMode 1004 == 0) && (MenuMode 1005 == 0) && (MenuMode 1006 == 0) && (MenuMode 1010 == 0) && (MenuMode 1011 == 0) && (MenuMode 1013 == 0) && (MenuMode 1015 == 0) && (MenuMode 1016 == 0) && (MenuMode 1017 == 0) && (MenuMode 1018 == 0) && (MenuMode 1019 == 0) && (MenuMode 1020 == 0) && (MenuMode 1021 == 0) && (MenuMode 1024 == 0) && (MenuMode 1038 == 0) && (MenuMode 1039 == 0) && (MenuMode 1044 == 0) && (MenuMode 1045 == 0) && (MenuMode 1046 == 0) && (MenuMode 1047 == 0) && (MenuMode 1057 == 0)
					let countdown := countdown + 1
				endif
			else	;MenuMode 1001
				let countdown := 0
			endif
		else	;Choice > -1
			let countdown := 0
		endif
	else ;Display menu again
		let section := -( section )
		let countdown := 0
	endif
elseif ( section == -1 )
	MessageBox "Manage your mount:" "Follow" "Stay" "Calm" "Access Saddlebag" "Remove Saddle" "Remove Armor" "Nevermind"
	let section := 1
	let choice := -1
elseif ( section == 1 )
	if ( choice == 0 )
		let section := 0
	elseif ( choice == 1 )
		let section := 0
	elseif ( choice == 2 )
		let section := 0
	elseif ( choice == 3 )
		let section := 0
	elseif ( choice == 4 )
		if ( unsaddlespell != 0 )
			let section := 0
			player.Cast unsaddlespell player
		else
			MessageBox "Your mount has no saddle to remove"
			let section := -1
		endif
	elseif ( choice == 5 )
		if ( unarmorspell != 0 )
			let section := 0

;
; THIS IS THE ACTIVATOR/PLAYER CASTING CODE
;

			float xp

			AxelSystemGenericActivatorRef.Disable
			AxelSystemGenericActivatorRef.MoveTo player 0, 0, 100
			AxelSystemGenericActivatorRef.Enable
			let xp := AxelSystemGenericActivatorRef.GetPos X
			AxelSystemGenericActivatorRef.SetPos X xp
			AxelSystemGenericActivatorRef.Cast unarmorspell mount
;				player.Cast unarmorspell mount

;
; CASTING CODE END
;


		else
			MessageBox "Your mount has no armor to remove"
			let section := -1
		endif
	elseif ( choice == 6 )
		let section := 0
	endif
endif
End

Link to comment
Share on other sites

Ok, so it seems I've been able to solve it by trials and errors. I will post my results here so they may be of help to someone.

 

I was wrong in the previous post: "player.cast" with spell set to "self" actually works, so I decided to use it and adapt the spell script instead.

 

Here are the steps I used to make it work:

 

- I Activate the horse in sneak mode

- The horse script first puts its own reference into a variable on my custom quest, with "let MyCustomQuest.activemount := GetSelf"

- Then it boots the quest with "StartQuest MyCustomQuest". This will start the Menu code placed into the custom quest

- As soon as I choose the Remove Armor option from the menu, I simply call "player.cast myremovearmorspell player"

- Now, to equip the armor I used a Range Touch spell, which gives me the target automatically; I just check if it's my horse and voila'. The remove armor spell, instead, must be set to Range Self, so I have no reference. I solved this by taking it directly from the quest variable "MyCustomQuest.activemount" I set before.

 

And it works! (So, I hope you will have your dressable horses soon ;))

 

By the way, I'm using OBSE and I still have not too much experience on scripting. If you think something may be made better in a way or another, please tell me and I'll try to correct everything as soon as possible.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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