Jump to content

[LE] Creating a Spellcaster-esque object


Recommended Posts

Hey everyone!

 

To start: I was trying to create a script attached to an object. The object would fire a spell at a random actor (and check to see if the NPC - including the player - is in "myfaction") in its vicinity, somewhat like the spellcasting soul gems in dungeons.

The "myfaction" part is not pivotal; just the player would suffice, if it is much harder to implement. I've looked at the soul gem scripts and several on the wiki, but none of them seem to be what I'm searching for.

 

Basics:

- Distance is set to 1200

- Time between each cast should be 6 seconds (timer resets after every shot)

- Randomly selects target in its vicinity (optionally only those in "myfaction", otherwise only player)

- Plays the "activated" animation on the object

- Can be turned off via hidden lever

 

Currently, I've found a similar script in Oblivion, though the script doesn't translate well into Skyrim... this is my attempt at fixing it:

 

-----------------------------------------------------------------------------------------------

float timer
short ready
short disabled
objectreference mySelf
objectreference myParent
short next
Begin OnActivate
if Game.FindRandomActorFromRef(Game.GetPlayer(), 1200)
if disabled == 0
disabled = 1
timer = 0
else
disabled = 0
endif
endif
End
Begin GameMode
if disabled == 0
if getDistance player < 1200 && timer <= 0
inRange = 1
endif
endif
if timer <= 0 && inRange == 1
playgroup forward 0
ready = 1
timer = 6
inRange = 0
endif
if next == 1 && timer <= 5
set mySelf to getSelf
set myParent to getParentRef
myParent.activate mySelf 1
next = 0
endif
if timer <=4 && ready = 1
if getDistance player < 1200 && getDistance player > 400
cast Spell player
endif
endif
ready = 0
endif
if timer > 0
timer = timer - getSecondsPassed
endif
End

-----------------------------------------------------------------------------------------------

 

If anyone can give me some help with the script, it would be well appreciated.

Link to comment
Share on other sites

Event OnActivate( ObjectReference QRef )
	Actor TempActor = FindRandomActorFromRef( QPlayer , 1200.0 )
	
	If( TempActor )
		If( TempActor.IsInFaction( QFaction ) )
			
			; NPC is in Faction, do stuff here
			
		Else
		
			; NPC is not in Faction, do ELSE stuff here
		
		EndIf
	Else
	
		; Can't find NPC
		; im not sure about this part, but sometimes it works :)
	
	EndIf
EndEvent

Version with refreshing every 6 sec:

Event OnInit()
	RegisterForUpdate( 6.0 )
EndEvent

Event OnUpdate()
	Actor TempActor = FindRandomActorFromRef( QPlayer , 1200.0 )
	
	If( TempActor )
		If( TempActor.IsInFaction( QFaction ) )
			
			; NPC is in Faction, do stuff here
			
		Else
		
			; NPC is not in Faction, do ELSE stuff here
		
		EndIf
	Else
	
		; Can't find NPC
		; im not sure about this part, but sometimes it works :)
	
	EndIf
EndEvent

If you explain what you want using easy english i can help you more,

however atm, script find actor around player and check if this actor is in selected faction :x...

 

#lol

 

i can't test this script so try to compile and show me errors if any erros shows

Edited by TobiaszPL
Link to comment
Share on other sites

Thanks for answering!

 

Checked it in-game, functions like you wrote.

To keep it simple: object (say, soul gem) fires a spell at random npcs (TempActor) in close distance if they are *NOT* (sorry, noticed this later) of a certain faction (QFaction). It does this every 6 seconds, and plays an "on activation" animation each time (like soul gem flashing). So 1200 distance from self (soul gem with script), not the Player. Simply fixed with adding self in property.

 

I've modified the script to fit right, there were no errors, so good work! :thumbsup:

 

Import Game
Actor Property QPlayer Auto
Faction Property QFaction Auto
Spell Property Spell Auto

Event OnInit()
RegisterForUpdate( 6.0 )
EndEvent

Event OnUpdate()
Actor TempActor = FindRandomActorFromRef( QPlayer , 1200.0 ) ; distance from Self, not player

If( TempActor )
If( TempActor.IsInFaction( QFaction ) )
; NPC is in Faction, do stuff here
Else
Spell.Cast(Self, TempActor) ; this is all good, but missing animation to go with it, like "PlayAnimationAndWait("Close", "done")"
EndIf
Else
; Can't find NPC
; im not sure about this part, but sometimes it works :smile:
EndIf
EndEvent

Edited by nikolaf
Link to comment
Share on other sites

  • Recently Browsing   0 members

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