diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index f055ed6c..1115d0a7 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -390,6 +390,10 @@ Some utility/math functions are available: > object sfall_func0("outlined_object") - returns an object that is currently highlighted by hovering the mouse above it +> object sfall_func1("set_dude_obj", critter) +- take control of a given critter +- passing 0 will reset control back to "real" dude + ------------------------ ------ MORE INFO ------- diff --git a/sfall/Modules/PartyControl.cpp b/sfall/Modules/PartyControl.cpp index bf2e91ea..198413c0 100644 --- a/sfall/Modules/PartyControl.cpp +++ b/sfall/Modules/PartyControl.cpp @@ -92,7 +92,7 @@ static void SaveRealDudeState() { } // take control of the NPC -static void TakeControlOfNPC(fo::GameObject* npc) { +static void SetCurrentDude(fo::GameObject* npc) { // remove skill tags long tagSkill[4]; std::fill(std::begin(tagSkill), std::end(tagSkill), -1); @@ -146,6 +146,8 @@ static void TakeControlOfNPC(fo::GameObject* npc) { // restores the real dude state static void RestoreRealDudeState() { + assert(real_dude != nullptr); + fo::var::obj_dude = real_dude; fo::var::inven_dude = real_dude; @@ -173,7 +175,6 @@ static void RestoreRealDudeState() { SetInventoryCheck(false); isControllingNPC = false; - real_dude = nullptr; } // return values: 0 - use vanilla handler, 1 - skip vanilla handler, return 0 (normal status), -1 - skip vanilla, return -1 (game ended) @@ -181,7 +182,7 @@ static int _stdcall CombatWrapperInner(fo::GameObject* obj) { if ((obj != fo::var::obj_dude) && (allowedCritterPids.size() == 0 || IsInPidList(obj)) && (controlMode == 1 || fo::func::isPartyMember(obj))) { // save "real" dude state SaveRealDudeState(); - TakeControlOfNPC(obj); + SetCurrentDude(obj); // Do combat turn int turnResult = fo::func::combat_turn(obj, 1); @@ -322,7 +323,7 @@ void PartyControl::SwitchToCritter(fo::GameObject* critter) { SaveRealDudeState(); } if (critter != nullptr && critter != real_dude) { - TakeControlOfNPC(critter); + SetCurrentDude(critter); } }