elseagoat Posted March 20, 2012 Share Posted March 20, 2012 I need to somehow check to see if a Hazard object still exists in the game. This is my script so far (its my first one, go easy on me!). Scriptname soulharvestscript extends activemagiceffect ActorBase Property shade Auto Float Property distancefeet Auto ObjectReference targetobj ObjectReference marker Actor spawnedshade Actor target Bool update Float distanceunits Event OnEffectStart(Actor akTarget, Actor akCaster) update = true target = akTarget marker = akCaster targetobj = akTarget distanceunits = (distancefeet * 21.345) spawnedshade = target.PlaceActorAtMe(shade) spawnedshade.StartCombat(target) RegisterForSingleUpdate(0.5) endEvent Event OnUpdate() If update == true If (spawnedshade.GetCombatTarget() != target) spawnedshade.StartCombat(target) endif If (marker.GetDistance(targetobj) > distanceunits) Dispel() endIf If (marker.IsEnabled() != true) Dispel() endIf RegisterForSingleUpdate(0.5) endIf endEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) update = false Utility.wait(1) spawnedshade.DisableNoWait(true) spawnedshade.Delete() endEvent Basically, I have a spell with a magic effect called Soul Harvest, that places a Hazard object at the players location.The Hazard object exists for 40 seconds with a radius of 40, checking for targets every 0.5 seconds and casting another spell on these targets.This second spell has a magic effect that lasts for 40 seconds, and runs two scripts. One script works perfect, the other only kind-of works. Basically what I want to happen is I charge up the spell like a master level spell, cast it, and a glowy thing appears on the ground. Enemies that come near the glowy thing on the ground become "afflicted" with this script effect, which will soul trap them (currently works great) and spawns a single NPC ghost to attack them. All of this is working so far. However, this part appears to do nothing: If (marker.GetDistance(targetobj) > distanceunits) Dispel() endIf If (marker.IsEnabled() != true) Dispel() endIf Basically, I want the effect to stay on enemies that remain near the glowy hazard object on the ground, and be immediately removed when the enemy leaves the area OR the hazard de-spawns. Currently this is not working, and an enemy that leaves will continue to be chased by a ghost and an enemy that comes near the hazard right before it gets de-spawned will get a full 40 seconds of ghost chasing after it. Any help is much appreciated! Thanks guys! Link to comment Share on other sites More sharing options...
fg109 Posted March 20, 2012 Share Posted March 20, 2012 I think it might be because the 'marker' variable is actually empty. Try adding this to your OnEffectStart: if (marker) Debug.Notification("Marker variable is filled.") else Debug.Notification("Hazards are not actors.") endif Link to comment Share on other sites More sharing options...
elseagoat Posted March 20, 2012 Author Share Posted March 20, 2012 I think it might be because the 'marker' variable is actually empty. Try adding this to your OnEffectStart: if (marker) Debug.Notification("Marker variable is filled.") else Debug.Notification("Hazards are not actors.") endifthanks! however, if marker is empty because hazards are not actors and thus akCaster (which I assume is the hazard, and not the actor that cast the spell that created the hazard) is unable to pass the hazard to the variable marker... Then what do I do? By the way, marker is an objectreference, not an actor. Either way though, I need to somehow get ahold of the hazard reference and I have no idea how to do that without akCaster from the OnEffectStart. That is the only possible way that I see to do it. I have thought of even creating an activator with the same spell that creates the hazard in the same place, then attaching a script to that activator that somehow passes its own self as an objectreference through a property that the activemagiceffect script could then get(). But really I have no idea. Link to comment Share on other sites More sharing options...
fg109 Posted March 20, 2012 Share Posted March 20, 2012 Try using FindClosestReferenceOfTypeFromRef. Link to comment Share on other sites More sharing options...
EnaiSiaion Posted March 20, 2012 Share Posted March 20, 2012 In that case, replace the hazard with an invisible conjured actor that doesn't move and has a perk that gives it a certain ability. You can add an oneffectstart script to this ability and it will trigger when the unit is spawned. Link to comment Share on other sites More sharing options...
elseagoat Posted March 20, 2012 Author Share Posted March 20, 2012 Both of those methods seem... I dunno. I just don't think that would be the best way to do it. Is there a way to pass information between scripts using properties? Like for example, instead of assigning a float to a property through the editor, could I just do it in the script and thus have it be a variable? So basically, the FIRST magic effect that spawns the hazard object would get a script that immediately does game.getplayer().getpositionx() and y, and z, then stores it in an array. That array then gets copied into a property array and set in the script. Then the hazard object's spell, which has the script to cast soul trap and also the script to spawn ghosts that chase people would then also have the same property and retrieve the x, y, and z from the property array then do a distance check between the target and the activator. then do the same thing for some random boolean that basically says if the activator exists or not. Anyone know how to do this with properties? Link to comment Share on other sites More sharing options...
fg109 Posted March 20, 2012 Share Posted March 20, 2012 Actually, I think my idea with using FindClosestReferenceOfTypeFromRef is pretty good. Your script wouldn't even change that much, just a couple added lines: Scriptname soulharvestscript extends activemagiceffect ActorBase Property shade Auto Float Property distancefeet Auto Hazard Property MyHazardBaseObject Auto ObjectReference marker Actor spawnedshade Actor target Bool update Float distanceunits Event OnEffectStart(Actor akTarget, Actor akCaster) update = true target = akTarget distanceunits = (distancefeet * 21.345) marker = Game.FindClosestReferenceOfTypeFromRef(MyHazardBaseObject, target, distanceunits) spawnedshade = target.PlaceActorAtMe(shade) spawnedshade.StartCombat(target) RegisterForSingleUpdate(0.5) endEvent Event OnUpdate() If update == true If (spawnedshade.GetCombatTarget() != target) spawnedshade.StartCombat(target) endif If (marker.GetDistance(target) > distanceunits) Dispel() endIf If (marker.IsEnabled() != true) Dispel() endIf RegisterForSingleUpdate(0.5) endIf endEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) update = false Utility.wait(1) spawnedshade.DisableNoWait(true) spawnedshade.Delete() endEvent Well, to address your suggestion, before you can access the properties from another script, you need to know which object that the other script is on. The way it accesses it looks something like this: object.property So you actually need to have a reference to the object the script is on in order for this to work. This is easy with something like a quest or the unique actors like the player, because you can assign them to a property in your script while in the Creation Kit. But accessing properties from a magic effect script that's on one of possibly many identical magic effects on multiple unknown actors? I don't know how to do it... Not to say that your idea is bad, just can't do it the exact way you suggested. It would actually be much easier to store the player's location in three global variables and access those from the magic effect's script. Otherwise, instead of setting the properties in the magic effect's script, just have the magic effect script read the properties from something else, like a quest script. So when the spell is first cast, you save the location of the player to a script on a quest. Then in your magic effect script, you read the location from the quest's script. Of course, you'll need a dummy quest for this to hold the values. Link to comment Share on other sites More sharing options...
elseagoat Posted March 20, 2012 Author Share Posted March 20, 2012 That seemed to work well! Thanks so much! It is a bit buggy. I used it a bunch and most of the time it worked great, but sometimes it acted funny. For example, one time I used it on a single enemy, and the ghost attacked it like normal, then all the sudden stopped attacking and stood there, getting beaten on. Another time I used it on two enemies, and as soon as the first one died and got soul trapped, the spell started acting completely crazy, and it would still spawn the normal 1 ghost per enemy, but there were 3 more ghosts that would rapidly appear and dissapear like crazy near the guy that died. The problem went away when I walked away from the dead body and continued casting the spell. The spell also looks ass ugly. I couldn't find a good effect for it. I really want to make it get dark, but only around the area where it is cast. So stepping into the area makes it dark as night, but leaving the area makes it normal again. Anyone know how to do that? Link to comment Share on other sites More sharing options...
fg109 Posted March 20, 2012 Share Posted March 20, 2012 (edited) I think you might want to take a look at image space modifiers for the lighting effects. I've never used them though so I don't really know how it works. I know you can set one for a spell, but not sure if that'll work the way you want it to. I think you should also be able to spawn one using PlaceAtMe. As for the bugs, did that happen before you did what I suggested or after? Anyway, I think I know the reason behind the second one. Magic effects work on dead actors. They get dispelled immediately, but they do work for a moment. So you might want to add a check for whether or not the target is dead. Something like: Event OnEffectStart(Actor akTarget, Actor akCaster) if (akTarget.IsDead()) Dispel() endif ;;; Endif Edited March 20, 2012 by fg109 Link to comment Share on other sites More sharing options...
elseagoat Posted March 20, 2012 Author Share Posted March 20, 2012 I think you might want to take a look at image space modifiers for the lighting effects. I've never used them though so I don't really know how it works. I know you can set one for a spell, but not sure if that'll work the way you want it to. I think you should also be able to spawn one using PlaceAtMe. As for the bugs, did that happen before you did what I suggested or after? Anyway, I think I know the reason behind the second one. Magic effects work on dead actors. They get dispelled immediately, but they do work for a moment. So you might want to add a check for whether or not the target is dead. Something like: Event OnEffectStart(Actor akTarget, Actor akCaster) if (akTarget.IsDead()) Dispel() endif ;;; Endif Ooooh, I didn't know that. I knew magic effects didn't work on dead actors, but I did not know that it briefly appears on the actor. THat would be the source of my flashing in and out of existance ghosts! The hazard is repeatedly trying to cast the spell on the dead actor and it spawns a ghost for a split second. Thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts