Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ scriptName MyScript extends Quest
}
```

## Multiple Targets in a single line

```papyrus
; This will bind `MyScript` to the the player and three specified NPCs in Riverwood using some of the supported binding options
scriptName MyScript extends Actor
{
!BIND SvenRef|$Player|0x1348A|HildeRef
}
```

# Logs

> ℹ ️ If you run into any problems, check the `SkyrimScripting.Bind.log` in your
Expand Down
Binary file added Scripts/BindMeToMultipleTargets.pex
Binary file not shown.
1 change: 1 addition & 0 deletions Scripts/Bindings/BindExamples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
BindMeToPlayer $Player
BindMeToHodByID 0x1348A
BindMeToHodByEditorID HodRef
BindMeToMultipleTargets SvenRef|0x1348A|$Player|HildeRef
BindMeToGeneratedQuest $Quest
BindMeToGeneratedQuestWithName $Quest(MyCoolQuest)
BindMeToGeneratedObject $Object
Expand Down
Binary file added Scripts/DocStringBindToMultipleTargets.pex
Binary file not shown.
6 changes: 6 additions & 0 deletions Scripts/Source/BindMeToMultipleTargets.psc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
scriptName BindMeToMultipleTargets extends Actor

event OnInit()
string script = StringUtil.Substring(self, 1, StringUtil.Find(self, " ") - 1)
Debug.Trace("[BIND] Script " + script + " bound to " + self + " " + GetBaseObject().GetName())
endEvent
9 changes: 9 additions & 0 deletions Scripts/Source/DocStringBindToMultipleTargets.psc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
scriptName DocStringBindToMultipleTargets extends Actor
{
!BIND SvenRef|0x1348A|$Player|HildeRef
}

event OnInit()
string script = StringUtil.Substring(self, 1, StringUtil.Find(self, " ") - 1)
Debug.Trace("[BIND] Script " + script + " bound to " + self + " " + GetBaseObject().GetName())
endEvent
42 changes: 28 additions & 14 deletions plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ namespace SkyrimScripting::Bind {
rtrim(s);
ltrim(s);
}
std::vector<std::string> split(const std::string& text, char delim) {
std::string line;
std::vector<std::string> vec;
std::stringstream ss(text);
while (std::getline(ss, line, delim)) vec.push_back(line);
return vec;
}

RE::TESForm* LookupFormID(RE::FormID formID) {
auto* form = RE::TESForm::LookupByID(formID);
Expand Down Expand Up @@ -135,24 +142,15 @@ namespace SkyrimScripting::Bind {
logger::info("BIND ERROR [{}:{}] ({}) No default BIND behavior available for script which `extends` {}", FilePath, LineNumber, ScriptName, parentName);
}

void ProcessBindingLine(std::string line) {
if (line.empty()) return;
trim(line);
std::istringstream lineStream{line};
lineStream >> ScriptName;
if (ScriptName.empty() || ScriptName.starts_with('#') || ScriptName.starts_with("//")) return;
if (!vm->TypeIsValid(ScriptName)) {
logger::info("BIND ERROR [{}:{}] Script '{}' does not exist", FilePath, LineNumber, ScriptName);
return;
}
logger::info("\"{}\"", line);
std::string bindTarget;
lineStream >> bindTarget;
void ProcessBindingTarget(std::string bindTarget) {
trim(bindTarget);
LowerCase(bindTarget);
if (bindTarget.empty()) {
AutoBindBasedOnScriptExtends();
return;
} else if (bindTarget.starts_with("0x"))
} else if (bindTarget.contains('|'))
for (const auto& target : split(bindTarget, '|')) ProcessBindingTarget(target);
else if (bindTarget.starts_with("0x"))
Bind_FormID(std::stoi(bindTarget, 0, 16));
else if (bindTarget == "$player")
Bind_FormID(0x14);
Expand All @@ -170,6 +168,22 @@ namespace SkyrimScripting::Bind {
Bind_EditorID(bindTarget);
}

void ProcessBindingLine(std::string line) {
if (line.empty()) return;
trim(line);
std::istringstream lineStream{line};
lineStream >> ScriptName;
if (ScriptName.empty() || ScriptName.starts_with('#') || ScriptName.starts_with("//")) return;
if (!vm->TypeIsValid(ScriptName)) {
logger::info("BIND ERROR [{}:{}] Script '{}' does not exist", FilePath, LineNumber, ScriptName);
return;
}
logger::info("\"{}\"", line);
std::string bindTarget;
lineStream >> bindTarget;
ProcessBindingTarget(bindTarget);
}

void ProcessBindingFile() {
logger::info("Reading Binding File: {}", FilePath);
LineNumber = 1;
Expand Down