Any way to get a partial name of an item?

Post » Tue Nov 20, 2012 11:20 am

Please help, I'm using Haskeyword in my script for renaming certain items, but would like to filter out even more-so
by excluding items that contain parts of words. GetName() returns the full name. I tested the word GetName() == "Lock"
to see if a Lockpick would be returned but it doesn't.

Is there a way to get just a partial name, a GetNameContains() or something? Having a hard time navigating that wiki and I wouldn't know which script something like that would even be under.

Would greatly appreciate some input on this, thanks.

-Mush-
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am

Post » Tue Nov 20, 2012 7:13 am

Perhaps you may find SKSE's string functions useful? From the SKSE PSC file "StringUtil":

Spoiler
Scriptname StringUtil Hidden

; Note about the internal Skyrim implementation of the string classes used for scripting:
; the strings are case-insensitive. Each BSFixedString is managed in a cache and reused
; everywhere it is needed. This means that strings like "O" and "o" are technically equivalent;
; Which string is used depends greatly on which version is found first. We are investigating
; how to manage this, but for the time being be aware that the distinction between uppercase
; and lowercase may not exist. It also means that functions below returning an integer
; for the character may not correspond exactly. Also GetNthChar("Hello Skyrim!", 4) will
; return a string with either "O" or "o" depnding on which might be registered first. All
; my tests so far have it return the uppercase, eventhough in the string it is lowercase.
; We may solve this problem by switching back to returning an integer rather than a string
; for GetNthChar, but this will still have problems.

; return the length of the string
int Function GetLength(string s) global native

; returns a single character string with the character at index
string Function GetNthChar(string s, int index) global native

; Functions to work on Chars
; returns information about a specific character
; assumes a single character string. If a multicharacter string is passed
; the information about the first character is returned
bool Function IsLetter(string c) global native
bool Function IsDigit(string c) global native
bool Function IsPunctuation(string c) global native
bool Function IsPrintable(string c) global native

; returns the index of the first character of toFind inside string s
; returns -1 if toFind is not part of the string or if startIndex is invalid
int Function Find(string s, string toFind, int startIndex = 0) global native

; returns a substring of the specified string starting at startIndex and going for len characters
; or until the end of the string. Default len of 0 means for the entire string
string Function Substring(string s, int startIndex, int len = 0) global native

; returns the numeric value of the first character as an int
int Function AsOrd(string c) global native

; returns a single character string interpreting c as a character
string Function AsChar(int c) global native
User avatar
Frank Firefly
 
Posts: 3429
Joined: Sun Aug 19, 2007 9:34 am

Post » Tue Nov 20, 2012 11:57 am

StringUtil's http://www.creationkit.com/Find_-_StringUtil might pull it off.

Bool bLockIsInName = StringUtil.Find(Lockpick.GetName(), "Lock") != -1
...perhaps?
User avatar
Spencey!
 
Posts: 3221
Joined: Thu Aug 17, 2006 12:18 am

Post » Tue Nov 20, 2012 4:03 pm

StringUtil's http://www.creationkit.com/Find_-_StringUtil might pull it off.

Bool bLockIsInName = StringUtil.Find(Lockpick.GetName(), "Lock") != -1
...perhaps?

Zartar & JustinOther: Thanks for the info. :smile: From reading those pages, and trying out the above I tweaked it and came up with this which works great in game:

On the playeralias script:

Spoiler
;; partial piece;elseif (akBaseItem.HasKeyword(VendorItemAnimalHide))			if bIsInName(akbaseItem, "Hide") || bIsInName(akbaseItem, "Pelt") || bIsInName(akbaseItem, "Skin")				if !CSHidesFLST.HasForm(akBaseItem)					CSHidesFLST.AddForm(akBaseItem)					akBaseItem.SetName("Hide - "+akBaseItem.GetName())				endif;;; and the bool function on the same script,Bool Function bIsInName(Form akBaseItem, String asInName) Global	if StringUtil.Find(akBaseItem.GetName(), asInName) != -1		return true	else		return false	endifEndFunction

I know it may not matter to some, but I feel that I should share what I've learned from others and post the results. I'm a happy individual once again. Just a real (nursing a nasty cold this week) and going through code when you're not all that familiar with it to start can be a pretty exhausting task. So I thank you all again. :smile:

-Mush-
User avatar
Robyn Lena
 
Posts: 3338
Joined: Mon Jan 01, 2007 6:17 am


Return to V - Skyrim