Jump to content

Photo

Script help: disable and delete function do not work properly


  • Please log in to reply
6 replies to this topic

#1
ughfhhyg4555786

ughfhhyg4555786

    Newbie

  • Premium Member
  • 15 posts

Due to my poor knowledge of script, especially to write a function, I'm experiencing some difficulty to accomplish my last script for my spell.

This spell is basically used for NPC only. When their enemies equip the bow and cross bow, two StoneShelter will be placed in front and back of the caster. And also a Turret will be placed above caster to shot the enemy. When enemies change their equaltype to onehand weapon or twohanded weapon, the StoneShelter and turret will be removed. 

 

The disable and delete function doesn't work properly in the function RemoveStoneShelter(), objects TurretRef and StoneWallRef seems already delete, but not exactly. And this cause a problem that "SpellRef.RemoteCast(TurretRef,Caster,EnemyTarget)" is still shooting even if the TurretRef is gone to my function TurretTrigger(). In addition, there is also problem in the function StoneShelter(). The function only place StoneWallRef but not placing StoneWallRef2 ???

 

(Also, through few tests, The FindRandomReferenceOfTypeFromRef work perfectly for a Turret with NPC or Player, the only disadvantage is the limited of distance (this require a searching radius). The GetCombatTarget function work perfectly fine only with NPC not player. I think this is because the NPC always point out their sight point cross to their target, but obviously player cannot do that.)

 

Below is script. 

Import Game
Import Utility
Import Math

Static Property StoneWall auto
Static Property StoneWall2 auto
Activator Property Turret auto
Activator Property SummonFx auto
Float Property SearchRadius = 3000.0 auto
Float Property fBaseTime = 1.0 auto
Float Property fBaseTime2 = 3.0 auto
Spell Property SpellRef auto
Spell Property SpellRef2 auto

Actor Caster
Actor Target
ObjectReference StoneWallRef
ObjectReference StoneWallRef2
ObjectReference TurretRef

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Caster = akCaster
	Target = akTarget
	RegisterForSingleUpdate(1.0)
EndEvent


Event OnUpdate()
	Actor EnemyTarget = Caster.GetCombatTarget()
	 
		if (EnemyTarget.GetEquippedItemType(0)==7)
			if (FindRandomReferenceOfTypeFromRef(StoneWall,Caster,SearchRadius) == none)
				StoneShelter()
			else
				TurretTrigger()
			EndIf
		elseif (EnemyTarget.GetEquippedItemType(0)==12)
			if (FindRandomReferenceOfTypeFromRef(StoneWall,Caster,SearchRadius) == none)
				StoneShelter()
			else
				TurretTrigger()
			EndIf
		elseif ((EnemyTarget.GetEquippedItemType(0)==9)||(EnemyTarget.GetEquippedItemType(1)==9))
			if (FindRandomReferenceOfTypeFromRef(StoneWall,Caster,SearchRadius) == none)
				SpellRef2.Cast(Caster)
			else
				TurretTrigger()
			EndIf
		else
			if  (StoneWallRef!= none || StoneWallRef2!= none || TurretRef!= none)
				RemoveStoneShelter()
			EndIf
		Endif
		RegisterForSingleUpdate(fBaseTime)
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	RemoveStoneShelter()
EndEvent


Function StoneShelter()
	TurretRef = Caster.PlaceAtMe(Turret)
	TurretRef.SetPosition(Caster.GetPositionX(),Caster.GetPositionY(),Caster.GetPositionZ()+ 440)
	StoneWallRef = Caster.PlaceAtMe(StoneWall)
	StoneWallRef.SetPosition(Caster.GetPositionX(),Caster.GetPositionY(),Caster.GetPositionZ())
	StoneWallRef.PlaceAtMe(SummonFx)
	StoneWallRef2 = Caster.PlaceAtMe(StoneWall2)
	StoneWallRef2.MoveTo(Caster,-40*sin(Caster.GetAngleZ()),-40*cos(Caster.GetAngleZ()),Caster.GetPositionZ())
	StoneWallRef2.PlaceAtMe(SummonFx)
EndFunction


Function TurretTrigger()
	Actor EnemyTarget = Caster.GetCombatTarget()
	if TurretRef != none
		SpellRef.RemoteCast(TurretRef,Caster,EnemyTarget)
	else
		RegisterForSingleUpdate(fBaseTime)
	EndIf
EndFunction


Function RemoveStoneShelter()
	if TurretRef!= none
		TurretRef.PlaceAtMe(SummonFx)
		TurretRef.disable()
		TurretRef.delete()
	EndIf
	
	if StoneWallRef!= none
		StoneWallRef.PlaceAtMe(SummonFx)
		StoneWallRef.disable()
		StoneWallRef.delete()
	EndIf
	
	if StoneWallRef2!= none
		StoneWallRef2.PlaceAtMe(SummonFx)
		StoneWallRef2.disable()
		StoneWallRef2.delete()
	EndIf
EndFunction


#2
maxarturo

maxarturo

    Faithful poster

  • Members
  • PipPipPipPip
  • 1,839 posts
"The disable and delete function doesn't work properly in the function RemoveStoneShelter(), objects TurretRef and StoneWallRef seems already delete, but not exactly. And this cause a problem that "SpellRef.RemoteCast(TurretRef,Caster,EnemyTarget)" is still shooting even if the TurretRef is gone to my function TurretTrigger()."
 
Objects that are "Disabled" they still occupied / have an existence in world / cell, so the function will / can still use the "Disabled Object" to run the "Cast" function.
You need to add and "InterruptCast" to the "RemoveStoneShelter()".
Example:
Function RemoveStoneShelter()
if TurretRef!= none
                    TurretRef.InterruptCast()
                    TurretRef.PlaceAtMe(SummonFx)
                    TurretRef.disable()
                    TurretRef.delete()
            EndIf
EndFunction 
 
"In addition, there is also problem in the function StoneShelter(). The function only place StoneWallRef but not placing StoneWallRef2 ???"
Be sure that you have assign the "StoneWallRef2" in the script's properties, also try to use a little more different 'Names', try adding a '02', like "StoneWallRef02" (the Skyrim game engine is not the most reliable).
 
The "Delete" function does NOT occur when the script call it on an object, the object is just "Marked For Deletion" and it's still in its position / location until the cell in which the player is, gets 'unloaded' > from where the "Deletion" was called > until the system memory is reset / clean, only after that the object will stop existing on the 'Next Save File'.
 
* Sorry if i wasn't more detailed, but i'm making this post from my stupid tablet.
 
Have a happy modding.


#3
ughfhhyg4555786

ughfhhyg4555786

    Newbie

  • Premium Member
  • 15 posts

Hi  maxarturo,

Thank you for reply. I added the TurretRef.InterruptCast() to mu function, but it is still not working. Is because the delete function does not work well with OnUpdate event? I change StoneWallRef2 to StoneWallRef02, but the object is still not placing.  :sad:  Any idea?



#4
maxarturo

maxarturo

    Faithful poster

  • Members
  • PipPipPipPip
  • 1,839 posts
Your "Event OnUpdate()" is calling at the end a "RegisterForSingleUpdate(fBaseTime)", that's why is still "Casting", you need to "UnregisterForUpdate()" in the "RemoveStoneShelter()", sorry but i thought this was clear.
 
Function RemoveStoneShelter()
if TurretRef!= none
                    UnregisterForUpdate()
                    TurretRef.InterruptCast()
                    TurretRef.PlaceAtMe(SummonFx)
                    TurretRef.disable()
                    TurretRef.delete()
            EndIf
EndFunction 
 
I can't see any errors on your script, but in the other hand i'm looking at it with a small stupid tablet that i can barely see / read anything, plus i can not run any tests, i'm on vacations.
 
Maybe another expirienced modder with a PC available can take a look at it.
 
I'm so sorry....


#5
ughfhhyg4555786

ughfhhyg4555786

    Newbie

  • Premium Member
  • 15 posts

Thank you very much for reply, I will try this and I also have some idea about that. Once I have done the test, I will let you know. 



#6
ReDragon2013

ReDragon2013

    Old hand

  • Members
  • PipPipPip
  • 537 posts

As maxarturo has already written: "The "Delete" function does NOT occur when the script call it on an object, the object is just "Marked For Deletion" and it's still in its position"

syntax as follow:

IF ( oRef )
    oRef.DisableNoWait()
    oRef.Delete()
    oRef = None
ENDIF

I do not merged TurretRef.InterruptCast() into the code. If you need that, try it out.

 

ughTurretEffectScript

Spoiler

 



#7
ughfhhyg4555786

ughfhhyg4555786

    Newbie

  • Premium Member
  • 15 posts

That's amazing. I will need some times to read this






Page loaded in: 1.029 seconds