Jump to content

Script that checks an actors race?


Jarkon

Recommended Posts

I'm trying to create an effect script that checks the race of the actor its attached to and gives the player a different item depending on what it is (I.E. a green one when the actor is a member of the human race or a red one when its anything else).

 

However, whenever I test out the script in game on non-human enemies, it still gives me the human item. I've tried adding a debug message to at least understand what race is being scanned, but all it displays is "[Race". I have tried using different base commands (GetLeveledActorBase and GetBaseObject as ActorBase) but they end up doing the same thing. Does anyone have any idea what could be going wrong? Any input would be really appreciated!

 

Here's the script I'm using:

 

actor Victim
bool bHasBeenCasted = false
form Property requiredItem auto
form Property humanItem auto
form Property creatureItem auto
Race victimRace
;I manually placed the human race and ghoul race in here
Race [] Property humanRaces auto
Event OnInit()
victim = GetTargetActor()
EndEvent
Event OnDeath(Actor akKiller)
if(Game.GetPlayer().GetItemCount(requiredItem) > 0)
;At this point the script is supposed to check the race of the actor and see if its a member of the race array
ActorBase VictimBase = Victim.GetActorBase()
victimRace = VictimBase.GetRace()
if (humanRaces.Find(victimRace))
;In-game this always prints "[Race"
Debug.Notification(victimRace)
Game.GetPlayer().addItem(humanItem, 1, false)
Game.GetPlayer().removeItem(requiredItem, 1, true)
else
Game.GetPlayer().addItem(creatureItem, 1, false)
Game.GetPlayer().removeItem(requiredItem, 1, true)
endIf
endEvent
Link to comment
Share on other sites

You'll also want to use Debug.Trace not Debug.Notification if you want actually helpful data. Trace will give you the form ID and some naming information. Notification truncates and only displays simple data which isn't really helpful the way you want to use it. You'll need to then check the papyrus log file. It won't give you instant on screen info. You might also be able to use GetFormID() like: Debug.Notification(victimRace.GetFormID())

I'm guessing this script goes on a magic effect? If not you might also want to change all those properties to const in case you want to change them later. Unless you want the CK values upon first start to be sticky. If you ever changed them in CK after the script has been baked into a save you can't really. But if the script instance is created and destroyed frequently then it won't really matter.

Also either passing a player ref or in oninit setting a script local player ref will be more processor efficient than calling game.getplayer() repeatedly. Doing it once is probably ok but repeatedly it will become very inefficient. Personally I always pass it as a script property since the game has already done the work and made the ref.

Edited by BigAndFlabby
Link to comment
Share on other sites

  • Recently Browsing   0 members

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