Jump to content

How to acquire the race name?


Asterra

Recommended Posts

@Arocide

Just as a test, i took any AV (in this case, SpeedMult) to see changes and the way script worked.
Funny enough, i think im gonna fall on your code and try if it works because my doesnt.
My for instance, my current part of the code check race:

 

Event OnInit()

Utility.Wait(5)
If PlayerRef.GetRace() == "ArgonianRace"

PlayerRef.SetAV("SpeedMult", 120)

Debug.Notification("Argonian race | RaceID: "+(PlayerRef.GetRace()))

elseIf PlayerRef.GetRace() == "KhajiitRace"

PlayerRef.SetAV("SpeedMult", 140)

Debug.Notification("Khajiit race | RaceID: "+(PlayerRef.GetRace()))

etc....

else ;Unknown race.

PlayerRef.SetAV("SpeedMult", 50)

Debug.Notification("UNSUPPORTED RACE! [RaceID: "+(PlayerRef.GetRace())+"]")

Debug.Notification("NOT A NORD!")

TimeToDie()

endif

EndEvent

 

Function TimeToDie() ; A very good way to tell that your code failed.

if Kill == 0

Debug.Notification("TIME TO DIE")

Timer = Utility.GetCurrentRealTime() + 5

Kill = 1

endif

if Kill == 1 && Utility.GetCurrentRealTime() > Timer ; xD

Debug.Notification("Just kidding.")

Timer = Utility.GetCurrentRealTime() + 5

Kill = 2

if Kill == 2 && Utility.GetCurrentRealTime() > Timer ; xD

Debug.Notification("nope") ; >:D
Utility.Wait(2)

PlayerRef.Kill() ; FAILURE NOT ACCEPTED AND RESULTS IN DEATH!

endif

EndFunction

 

Later it should give the name in a MsgBox with some more info etc. But cant make it work just to identify the race in the first place.

It always returns "[Race" for some reason. Tried all, even..
PlayerRef.GetBaseObject().GetRace() == "NordRace" (returns [Race as well)

PlayerRef.GetActorBase().GetRace() == "NordRace" (also returns [Race)
same result not matter how i check the race, apparently im a [Race and not a Nord. xD

So, the consistency of the value is right (since it returns the same value), the return value itself is wrong tho (Im supposed to be a Nord). xD

 

While PlayerRef.GetSex() for instance works as intended.

 

Link to comment
Share on other sites

	string Function GetEditorID(Form akForm) Global
		string fullID = akForm
		int temp = StringUtil.Find(fullID,"<",0)
		int subLength = StringUtil.Find(fullID," ", temp) - temp
		return StringUtil.SubString(fullID, temp + 1, subLength )
	EndFunction

So, this is not in the StringUtil added by SKSE? I must write this code in my script?

Lets try.

 

It works! I love you man. xD

 

You said it works on anything. So, including keywords?

Like, if i would put:

GetEditorID(PlayerRef.GetKeyword())

It would return the Editor ID of the keyword? It would make this Obsolete?

Current code to check keyword:

 

keyword kwDEAD

keyword kwSlow

keyword kwFast

Event OnInit()

kwDEAD = Keyword.GetKeyword("ActorTypeUndead")

kwSlow = Keyword.GetKeyword("MyKwSlow")

kwFast = Keyword.GetKeyword("MyKwFast")

 

if PlayerRef.HasKeyword(kwDEAD)

Debug.Notification("ZOMBIE!")

elseif PlayerRef.HasKeyword(kwSlow)

Debug.Notification("HURRY!")

elseif PlayerRef.HasKeyword(kwFast)

Debug.Notification("Almost there.")

endif

EndEvent

 

Because i got like 10 keyword variables, 10 keyword assigned to them and 10 if elseif to look for those keywords on the player.

This would essentially replace any of such procedures to just this:

 

Event OnInit()

if GetEditorID(PlayerRef.GetKeyword()) == "ActorTypeUndead"

Debug.Notification("ZOMBIE!")

elseif GetEditorID(PlayerRef.GetKeyword()) == "MyKwSlow"

Debug.Notification("So Slow!")

elseif GetEditorID(PlayerRef.GetKeyword()) == "MyKwFast"

Debug.Notification("Just right.")

endif

EndEvent

 

If it works with any ID, this needs to be added as a native function in StringUtil script! <3

And ofc, the less code the better, always.

Edited by theimmersion
Link to comment
Share on other sites

The function would work with any object with a form base type (and yea it's a function I made up so it's not part of StringUtil, so you'll need to write it), you know I never thought about using it to dynamically gather keywords hm... I guess it could do that but since you would need the keyword in the first place to gather the editorID it seems a bit redundant. HasKeywordString() would serve the same purpose and is native so personally I would go with that which would be:

    Event OnInit()

        if PlayerRef.HasKeywordString("ActorTypeUndead")

            Debug.Notification("ZOMBIE!")

        elseif PlayerRef.HasKeywordString("MyKwSlow")

            Debug.Notification("So Slow!")

        elseif PlayerRef.HasKeywordString("MyKwFast")

            Debug.Notification("Just right.")

        endif

    EndEvent

or alternatively there is always properties instead if you dislike strings, w/e works for ya.

Edited by Arocide
Link to comment
Share on other sites

I did not notice the HasKeywordString or rather it had some descripion that i did not understand so i thought it was to be used with the other keyword functions in tandem like the GetKeyword/HasKeyword.

I work a lot with strings, its the functions that get me. xD

But yeah, its in any case nice having a function that gets you EditorID no matter the type as long as it has a base form is invaluable!

 

Edit: i hate properties tho. xD

 

Edit 2: what you mean by:

"I guess it could do that but since you would need the keyword in the first place to gather the editorID it seems a bit redundant"?

 

 

 

Im looking for specific keywords, that have important role.

Lets say i make a speed changing mod, now i make specific speeds for the different vanilla races.
But if a modder made a custom race and liked my mod and wanted to make my mod control player speed but dosent want its default unknown race flag default speed set and instaed wants to use a set of speeds from one of the vanilla races, instead of recode or what ever or requesting from me to make a support patch etc, they can add those keywords to their race and my mod will read on that and apply the appropriate speed set.

Like you make a custom race, my mod wont recognize it and set it on a default speed set. If you want argonians speed set, you put the MyPresetArgonian keyword on your race from my .esm and my mod will apply argonian speed set to your custom race. Or MyPresetKhajiit or if its a beast race transformation, you could set it to MyPresetWerebear, MyPresetWerewolf or MyPresetVampireLord. Also, in addition, it will read the undead and vampire keywords and make appropirate changes to the stamina drains as well.

Thats why i need keywords. So all you have to do for a patch for my mod is a simple keyword to race and upload that plugin as a compatibility patch and thats it.

Now, if none of the speed sets fit your custom race, i can add to the script to check for your race EditorID string that should never change, and it will apply the set that you wanted me to use. Thast the plan for my mod anyway. xD
And thats why i need race name or editorID, Which ever doesnt plan to change. Even if it does, all i have to do is switch:

GetEditorID(PlayerRef.GetRace()) == MyBigBirdRace

to

GetEditorID(PlayerRef.GetRace()) == MyBirdRace

and thats it.

Now tell me im not a genius. xD

 

 

Arocide, a very important question tho.
Am i allowed to use your code as is from these posts (like GetEditorID) here and publish my mod with it or am i supposed to make my own version or something?
Im getting confused with the codes in scripts permissions and what not.

 

Edit: Also, one last problem im having and my script is ready for extensive testing. How do i compare GetEditorID?

Because, GetEditorID(PlayerRef.GetRace()) == "NordRace" doesnt work.

While checking via

Debug.Notification("RaceID: "+(GetEditorID(PlayerRef.GetRace())))

prints out NordRace. And yet it doesnt compare. o.O

Edited by theimmersion
Link to comment
Share on other sites

Oh I was afraid that would happen, I think you'll find it is also including the " " at the end of the word... I always seem to do that it should be:

	string Function GetEditorID(Form akForm) Global
		string fullID = akForm
		int temp = StringUtil.Find(fullID,"<",0) + 1
		int subLength = StringUtil.Find(fullID," ", temp) - temp
		return StringUtil.SubString(fullID, temp, subLength )
	EndFunction

That should work. If it was the mistake... which I think it was. My bad.

Link to comment
Share on other sites

I cant thank you enough! It works! Now to setup a few more races and its time for testing what i actually made. Releasing soon i hope. Ditched the keywording because of complexity, its easier for me to include any race via a simple compare of GetEditorID than making the keywords processed. <3 xD

Link to comment
Share on other sites

Noticed I didn't answer some of your questions:

 


Edit 2: what you mean by:

"I guess it could do that but since you would need the keyword in the first place to gather the editorID it seems a bit redundant"?

 

I mean that since HasKeywordString() exists the GetEditorID function is a little redundant for keywords as HasKeywordString() is native code and will execute much faster.. well maybe not I am not sure if it is frame locked or not it might be.

Oh and anything I post you can use, I'm not fussed about threads since I posted it with the intent for it to be used if it was helpful.

 

You might want to cache what the function gives you before your if blocks so it's not constantly calling the function which makes papyrus work more then it needs to so something like this would work a treat:

			string editorID = GetEditorID(PlayerRef.GetRace())
			
			if editorID == MyBigBirdRace
				;Do stuff for Big Birds
			elseif editorID == MyBirdRace
				;Do stuff for Birds
			EndIf
Edited by Arocide
Link to comment
Share on other sites

Well yeah, thats gonna be the idea but when im optimizing, right now, its all over the place, using all sorts of variables blocks etc and its in one script and its slow but thats ok, i can see the behavior of the mod and if everything works. After im finished testing and see that all features work, ill recode and make it as efficient as possible-skill wise ofc.
Right now, everything is in its own separate block. Because if theres errors or something skipping in the code etc, i know which block didnt execute and make adjustments to that block. When every block does its job, i than recode the whole script and essentially merge blocks (i do that with all my scripts). Right now, if it was like this, i would just know that the code didnt work somewhere, but i always knew where my exact problem was. Im no programmer tho. Duh. So i might actually doing it wrong. xD
I can release a beta build sooner if anyone is interested. The story behind the mod is funny. BTW, this mod is old as SKSE itself (Im recoding my old mods essentially to work with everyones setup). xD It works perfectly for me, but than again, im always a Nord and its pretty much always the same setup, same core gameplay mods etc. But if i want to release the mod, i have to take in account every race and potential mod compatibility etc.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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