GetIsRace Help

Post » Fri Nov 16, 2012 5:08 pm

Hello,

I'm trying to condition the start of a script attached to the player based on the race. I have the PlayerRef as alias (specific reference) and a match condition with the following parameters:

Target: Subject
Function Name: GetIsRace
Function Info: the correct race selected...
Comp: ==
Value: 1.00

The condition doesn't seem to recognize the race. The script just doesn't fire at all. Removing the condition, the script works fine. I know for sure that I am using the correct race. I have tried changing the target to player, target, reference and linked reference without any success. I have also tried to put the condition directly inside the script with the GetRace function and the code inside an "if". Again, the "if" part of the code doesn't fire.

Oddly, this in the script works (before the "if") and gives me the correct race back:
debug.messagebox("My Current Race is: " + Game.GetPlayer().GetRace())

The code I'm using in the script is:
If ArmorsVanilla.HasForm(akBaseObject) && Game.GetPlayer().GetRace() == Player_Race

Player_Race is a property of type "Race" and points to the specific race.

At first I thought it was a bug, but as it happens with both the condition GetIsRace and also the function GetRace, it has to be an error on my part.

I am using a non vanilla race, but I don't think that should be a problem.

I did a search on the forum and found a single thread where the GetIsRace appeared, but nothing about this problem.

Can anybody please help?
User avatar
k a t e
 
Posts: 3378
Joined: Fri Jan 19, 2007 9:00 am

Post » Sat Nov 17, 2012 2:44 am

[redacted]
User avatar
Katey Meyer
 
Posts: 3464
Joined: Sat Dec 30, 2006 10:14 pm

Post » Fri Nov 16, 2012 10:52 pm

Thanks again, JustinOther!

But the message box worked with the aforementioned code.

Still, I rewrote the "if" part to the following:
	Race PlayerRace = Game.GetPlayer().GetActorBase().GetRace()	If ArmorsVanilla.HasForm(akBaseObject) && PlayerRace == Player_Race

It still isn't firing. The message box shows up fine, though.


Edit: Ok... I think I found the problem, but I just don't know what it means. The logs spit out this error on the race property:

error: Property Player_Race on script ArmorReplace attached to alias ArmorRepAlias on quest ArmorReplacement (200012C4) cannot be bound because (2000BA27) is not the right type
User avatar
Rudi Carter
 
Posts: 3365
Joined: Fri Sep 01, 2006 11:09 pm

Post » Sat Nov 17, 2012 3:19 am

Oh! Sorry. There are two GetRace functions; one for Actor and the other for ActorBase. Perhaps one will work where the other won't?


Edit: Are you sure the FormList property is filled and that akBaseObject is in the FormList? ALso, there's a hyphen in one instance of PlayerRace and not in the other, but I'd imagine that's just a typo as it wouldn't compile as shown. If that's not it, post the whole script.
User avatar
Yvonne Gruening
 
Posts: 3503
Joined: Mon Apr 23, 2007 7:31 pm

Post » Fri Nov 16, 2012 8:14 pm

Both FormList properties are filled, both contain two armors.

It's not a typo, one is a property, the other is a reference, but yes, both names are very similar, maybe I'll change that. But I think the problem lies in the property that points to the race, as I keep getting the error I mentioned before. I set the property type to "Race", but I'm not sure that is correct, as I couldn't find a list of property types anywhere. By the way, the script compiles fine. I get the error from the log on runtime.

In any case, you're right, I better post the whole script, might be easier to pinpoint the problem so.

Scriptname ArmorReplace extends ReferenceAliasActor Property PlayerREF AutoFormList property ArmorsVanilla AutoFormList property ArmorsModified AutoRace Property Player_Race AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference);ActorBase PlayerBase = Game.GetPlayer().GetBaseObject() as ActorBasedebug.messagebox("My Current Race is: " + Game.GetPlayer().GetRace());Race PlayerRace = Game.GetPlayer().GetActorBase().GetRace()ActorBase PlayerBase = Game.GetPlayer().GetBaseObject() as ActorBaseRace PlayerRace = PlayerBase.GetRace()If ArmorsVanilla.HasForm(akBaseObject) && PlayerRace == Player_Race  Debug.Trace("I just equipped a vanilla armor!")		Int iIndex = ArmorsVanilla.GetSize() - 1		While (akBaseObject != ArmorsVanilla.GetAt(iIndex)) && iIndex > 0			iIndex -= 1		EndWhile		PlayerREF.RemoveItem(akBaseObject, 1, True)		PlayerREF.EquipItem(ArmorsModified.GetAt(iIndex), False, True)	EndIfEndEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)If ArmorsModified.HasForm(akBaseObject)  Debug.Trace("I just unequipped a replaced armor!")		Int iIndex = ArmorsModified.GetSize() - 1		While (akBaseObject != ArmorsModified.GetAt(iIndex)) && iIndex > 0			iIndex -= 1		EndWhile		PlayerREF.RemoveItem(akBaseObject, 1, True)		PlayerREF.AddItem(ArmorsVanilla.GetAt(iIndex), 1, True)	EndIfEndEvent

I'm quite sure it's a really stupid problem on my part, though... :ermm: I'm very newbie at scripting...
User avatar
Juan Suarez
 
Posts: 3395
Joined: Sun Nov 25, 2007 4:09 am

Post » Fri Nov 16, 2012 9:17 pm

Try
Spoiler
ScriptName ArmorReplace Extends ReferenceAliasActor Property PlayerREF AutoFormList property ArmorsVanilla AutoFormList property ArmorsModified AutoRace Property YourRace Auto ; <--- Point this at your custom raceEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	Debug.Notification("My Current Race is: " + Game.GetPlayer().GetRace())	If PlayerREF.GetRace() == YourRace		Debug.Notification("PlayerREF.GetRace() == YourRace: " + PlayerREF.GetRace() == YourRace)		If ArmorsVanilla.HasForm(akBaseObject) 			Debug.Notification("ArmorsVanilla.HasForm(akBaseObject): " + ArmorsVanilla.HasForm(akBaseObject))			Int iIndex = ArmorsVanilla.GetSize() - 1			While (akBaseObject != ArmorsVanilla.GetAt(iIndex)) && iIndex > 0				iIndex -= 1			EndWhile			PlayerREF.RemoveItem(akBaseObject, 1, True)			PlayerREF.EquipItem(ArmorsModified.GetAt(iIndex), False, True)		EndIf	EndIfEndEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)	If ArmorsModified.HasForm(akBaseObject) 		Debug.Trace("I just unequipped a replaced armor!")		Int iIndex = ArmorsModified.GetSize() - 1		While (akBaseObject != ArmorsModified.GetAt(iIndex)) && iIndex > 0			iIndex -= 1		EndWhile		PlayerREF.RemoveItem(akBaseObject, 1, True)		PlayerREF.AddItem(ArmorsVanilla.GetAt(iIndex), 1, True)	EndIfEndEvent
Can't see why it wouldn't work unless the property isn't filled or the player isn't YourRace.
User avatar
brenden casey
 
Posts: 3400
Joined: Mon Sep 17, 2007 9:58 pm

Post » Fri Nov 16, 2012 3:55 pm

Ok, I think I found the problem. If I change the property to point to the NordRace, the script runs correctly with that race. Changing back to the custom race, I get errors again.

So it has to do with the custom race. Checking the loaded plugins, the custom race esp is selected and loaded, and that's why I can select the race as a property in the CK. But saving doesn't seem to bind my esp to the custom race esp, and if I remember correctly, it worked like that on the GECK.

Now, if I close the CK and load my plugin, it loads the attached masters, but not the custom race esp. That's probably why it isn't working, my plugin is not bound to the race plugin!

Soo... Is there a way to bind my plugin to another esp? Do I have to convert it into a master first??? How does it work now?
User avatar
Karine laverre
 
Posts: 3439
Joined: Tue Mar 20, 2007 7:50 am

Post » Fri Nov 16, 2012 3:50 pm

I'm pretty sure I read on here that you can only use esm as masters (one of the New World crew will know for certain)

There is a way to convert ... Have a search on this board and you will find the tools/topics etc ...


(Is the mod you want as master yours? If someone else created it, then you might want to ask/tell? ... Just a thought)
User avatar
Krista Belle Davis
 
Posts: 3405
Joined: Tue Aug 22, 2006 3:00 am

Post » Fri Nov 16, 2012 3:11 pm

I would prefer not to change the original plugin.

It's strange though, that the following code actually gives me the correct race nontheless:
debug.messagebox("My Current Race is: " + Game.GetPlayer().GetRace())

Is there a way to compare the string it outputs with script? If I could just compare it, I could detect if the player is of the correct race without the other plugin...

Maybe a stupid idea, but maybe...


Edit: IT WORKED!!!! With the following code it actually worked without having to convert the esp into a master:
string RaceText = "[Race ]"If ArmorsVanilla.HasForm(akBaseObject) && Game.GetPlayer().GetRace() == RaceText
User avatar
Ludivine Dupuy
 
Posts: 3418
Joined: Tue Mar 27, 2007 6:51 pm

Post » Fri Nov 16, 2012 5:50 pm

You could give them a nameless spell in the races "Specials", then check for it?
User avatar
J.P loves
 
Posts: 3487
Joined: Thu Jun 21, 2007 9:03 am

Post » Sat Nov 17, 2012 5:45 am

I think you posted as I edited. Comparing strings actually worked. The good thing with this is that my plugin is now completely independent from the other plugin. The bad part is that for this to work, I have to get the id manually from the race, so when my load order changes, this will probably stop working.

So, binding it to the race plugin still will be needed. I can live with this for the moment, as I'm using it mostly for me, though... At least while testing.

Anyway, thanks a lot for your help and time, JustinOther. Very much appreciated!
User avatar
Steven Nicholson
 
Posts: 3468
Joined: Mon Jun 18, 2007 1:24 pm

Post » Fri Nov 16, 2012 7:48 pm

You can get around that by using http://www.creationkit.com/GetFormFromFile_-_Game to set the property.

CustomRaceProperty = Game.GetFormFromFile(0x00XXXXXX, "Race Mod.esp") As Race
Just replace the XXXXXX with the last six characters in the races FormID.
User avatar
Isaiah Burdeau
 
Posts: 3431
Joined: Mon Nov 26, 2007 9:58 am

Post » Sat Nov 17, 2012 5:54 am

It works! I tried moving the plugins around in the load order, and it actually works!

Thaks thanks thanks!!! :biggrin:
User avatar
Marquis deVille
 
Posts: 3409
Joined: Thu Jul 26, 2007 8:24 am

Post » Fri Nov 16, 2012 4:33 pm

Right on! :) That one's my new favorite function.
User avatar
Shae Munro
 
Posts: 3443
Joined: Fri Feb 23, 2007 11:32 am

Post » Fri Nov 16, 2012 9:58 pm

By the way, it worked directly. I could dump the string mess... Now it's all in one single line! You're a genius!
If ArmorsVanilla.HasForm(akBaseObject) && Game.GetPlayer().GetRace() == Game.GetFormFromFile(0x0000BA27, "Race Mod.esp")
User avatar
Stephanie Valentine
 
Posts: 3281
Joined: Wed Jun 28, 2006 2:09 pm

Post » Sat Nov 17, 2012 2:01 am

By the way, it worked directly. I could dump the string mess... Now it's all in one single line! You're a genius!
If ArmorsVanilla.HasForm(akBaseObject) && Game.GetPlayer().GetRace() == Game.GetFormFromFile(0x0000BA27, "Race Mod.esp")
Thanks, but I just got a head start with Papyrus is all :blush:

May I suggest suggest caching the race and using a PlayerREF property? Game.GetPlayer() is substantially more 'expensive' than a property. Also, a one-liner can also prove substantially more 'expensive' as all of the conditions will be checked even if the first one is 'False'.
Spoiler
ScriptName ArmorReplaceQuestScript Extends QuestArmorReplace Property PlayerAliasScript AutoEvent OnInit()	PlayerAliasScript.YourRace = Game.GetFormFromFile(0x0000BA27, "Race Mod.esp") As RaceEndEvent
ScriptName ArmorReplace Extends ReferenceAliasActor Property PlayerREF AutoFormList Property ArmorsVanilla Auto ; Corresponding...FormList Property ArmorsModified Auto ; ...indicesRace Property YourRace AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	If ArmorsVanilla.HasForm(akBaseObject)		If PlayerREF.GetRace() == YourRace			Int iIndex = ArmorsVanilla.GetSize() - 1			While (akBaseObject != ArmorsVanilla.GetAt(iIndex)) && iIndex > 0				iIndex -= 1			EndWhile			PlayerREF.RemoveItem(akBaseObject, 1, True)			PlayerREF.EquipItem(ArmorsModified.GetAt(iIndex), False, True)		EndIf	EndIfEndEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)	If ArmorsModified.HasForm(akBaseObject)		Int iIndex = ArmorsModified.GetSize() - 1		While (akBaseObject != ArmorsModified.GetAt(iIndex)) && iIndex > 0			iIndex -= 1		EndWhile		PlayerREF.RemoveItem(akBaseObject, 1, True)		PlayerREF.AddItem(ArmorsVanilla.GetAt(iIndex), 1, True)	EndIfEndEvent
User avatar
Robert Jr
 
Posts: 3447
Joined: Fri Nov 23, 2007 7:49 pm

Post » Fri Nov 16, 2012 6:28 pm

I just changed the line into several "if"'s as you suggested, but the code inside the OnInit event (Game.GetFormFromFile) gives errors as soon as I try to assign it to a property. The same happens with the PlayerRef property, but Game.GetPlayer().GetRace() seems to work correctly. It's strange, because I'm using PlayerRef already for additem and removeitem without problems, taken from the code you posted at the start of the thread...
User avatar
Laura Wilson
 
Posts: 3445
Joined: Thu Oct 05, 2006 3:57 pm

Post » Fri Nov 16, 2012 9:49 pm

Ah. I'd forgotten the 'As Race'.

PlayerREF: It should be working with Actor.GetRace(). Make sure it's not of the ObjectReference type.
User avatar
Klaire
 
Posts: 3405
Joined: Wed Sep 27, 2006 7:56 am


Return to V - Skyrim