Skip to content

Instantly share code, notes, and snippets.

@LaughingLeader
Last active October 9, 2018 22:18
Show Gist options
  • Save LaughingLeader/a6a861fb3fc9f08ac82e12ae5bc741c6 to your computer and use it in GitHub Desktop.
Save LaughingLeader/a6a861fb3fc9f08ac82e12ae5bc741c6 to your computer and use it in GitHub Desktop.
DOS2DE - Puzzle Story Script System
/*
* The follow rules all depend upon a specific database being defined:
* DB_MyMod_Puzzle_Settings(_PuzzleID, _PuzzleFlag, _MaxTotal, _OnEvent, _OffEvent)
____________________
* Parameters:
* _PuzzleID - A string identifier to make this database entry unique. Can be anything you want to name your puzzle.
* _PuzzleFlag - The global flag to set when the puzzle's total reaches the max set in the DB. You could change this to an object or user flag by modifying the MyMod_Puzzle_TotalChanged proc (we're already passing in the character / item triggering the events).
* _MaxTotal - The total number of objects that should be "on" that should happen, i.e. the total number of levers/pressure plates that should be flipped "on".
* _OnEvent - The "On" CharacterItem event that increases the total by 1. Needs to be the same event set on the pressure plate or lever.
* _OffEvent - The "Off" CharacterItem event that decreases the total by 1. Needs to be the same event set on the pressure plate or lever.
_____________________
* Example Entry:
* DB_MyMod_Puzzle_Settings("Puzzle1", "MyMod_Puzzle1Solved", 2, "MyMod_Puzzle1_PlateOn", "MyMod_Puzzle1_PlateOff");
*/
//REGION On & Off Events
IF
CharacterItemEvent(_Character, _Item, _OnEvent)
AND
DB_MyMod_Puzzle_Settings(_PuzzleID, _PuzzleFlag, _MaxTotal, _OnEvent, _OffEvent)
THEN
MyMod_Puzzle_ModifyTotal(_Character, _Item, _PuzzleID, 1);
IF
CharacterItemEvent(_Character, _Item, _OffEvent)
AND
DB_MyMod_Puzzle_Settings(_PuzzleID, _PuzzleFlag, _MaxTotal, _OnEvent, _OffEvent)
THEN
MyMod_Puzzle_ModifyTotal(_Character, _Item, _PuzzleID, -1);
//END_REGION
//REGION Changing the Total Value
//Initialize the _Total value if an entry for this puzzle doesn't exist in the DB.
PROC
MyMod_Puzzle_ModifyTotal((CHARACTERGUID)_Character, (ITEMGUID)_Item, (STRING)_PuzzleID, (INTEGER)_ByAmount)
AND
NOT DB_MyMod_Puzzle_Temp_Total(_PuzzleID, _)
THEN
DB_MyMod_Puzzle_Temp_Total(_PuzzleID, 0);
PROC
MyMod_Puzzle_ModifyTotal((CHARACTERGUID)_Character, (ITEMGUID)_Item, (STRING)_PuzzleID, (INTEGER)_ByAmount)
AND
DB_MyMod_Puzzle_Temp_Total(_PuzzleID, _Total)
AND
IntegerSum(_Total, _ByAmount, _NewTotal)
THEN
// Remove the previous amount, so we only ever have 1 DB entry for this puzzle.
NOT DB_MyMod_Puzzle_Temp_Total(_PuzzleID, _Total);
// Add the new total to the DB
DB_MyMod_Puzzle_Temp_Total(_PuzzleID, _NewTotal);
// Run a custom proc to signal that the total was changed.
MyMod_Puzzle_TotalChanged(_Character, _Item, _PuzzleID, _Total);
//Safety check. The _Total should never be below 0.
IF
DB_MyMod_Puzzle_Temp_Total(_PuzzleID, _Total)
AND
_Total < 0
THEN
NOT DB_MyMod_Puzzle_Temp_Total(_PuzzleID, _Total);
DB_MyMod_Puzzle_Temp_Total(_PuzzleID, 0);
//END_REGION
//REGION Puzzle Flag Setting/Clearing
PROC
MyMod_Puzzle_TotalChanged((CHARACTERGUID)_Character, (ITEMGUID)_Item, (STRING)_PuzzleID, (INTEGER)_Total)
AND
DB_MyMod_Puzzle_Settings(_PuzzleID, _PuzzleFlag, _MaxTotal, _OnEvent, _OffEvent)
AND
_Total >= _MaxTotal
THEN
GlobalSetFlag(_PuzzleFlag);
PROC
MyMod_Puzzle_TotalChanged((CHARACTERGUID)_Character, (ITEMGUID)_Item, (STRING)_PuzzleID, (INTEGER)_Total)
AND
DB_MyMod_Puzzle_Settings(_PuzzleID, _PuzzleFlag, _MaxTotal, _OnEvent, _OffEvent)
AND
_Total < _MaxTotal
AND
DB_GlobalFlag(_PuzzleFlag)
THEN
GlobalClearFlag(_PuzzleFlag);
//END_REGION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment