Larian Banner: Baldur's Gate Patch 9
Previous Thread
Next Thread
Print Thread
#556508 06/10/14 06:34 PM
Joined: Jul 2014
Z
stranger
OP Offline
stranger
Z
Joined: Jul 2014
So basically I scripted a simple puzzle to test databases. The basic idea is: if all the right items are inside the trigger, something will start.

This is the working script(Which doesen't really use databases as I wanted to).

Code
TriggerRegisterForItems(TRIGGER_HIB_ENIGMA02_Optable);

DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART1);
DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART2);
DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART3);

IF
ItemEnteredTrigger(_Item,TRIGGER_HIB_ENIGMA02_Optable,_Player)
AND
DB_Enigma02_bodyparts(_Item)
AND
ItemIsInTrigger(ITEM_HIB_ENIGMA02_BODYPART1,TRIGGER_HIB_ENIGMA02_Optable,1)
AND
ItemIsInTrigger(ITEM_HIB_ENIGMA02_BODYPART2,TRIGGER_HIB_ENIGMA02_Optable,1)
AND
ItemIsInTrigger(ITEM_HIB_ENIGMA02_BODYPART3,TRIGGER_HIB_ENIGMA02_Optable,1)
THEN
CharacterDisplayText(CHARACTER_CHARACTER_Player1, "PENNY_01");


This script as I said works, but if I want to add more items in the puzzle I need to copy/paste the same condition over and over again. So I tried this code

Code
TriggerRegisterForItems(TRIGGER_HIB_ENIGMA02_Optable);

DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART1);
DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART2);
DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART3);

IF
ItemEnteredTrigger(_Item,TRIGGER_HIB_ENIGMA02_Optable,_Player)
AND
DB_Enigma02_bodyparts(_Item)
AND
ItemIsInTrigger(_Item,TRIGGER_HIB_ENIGMA02_Optable,1)
THEN
CharacterDisplayText(CHARACTER_CHARACTER_Player1, "PENNY_01");


But the script doesen't work, what it does instead is to trigger the CharacterDisplayText everytime I put even only one item.

Joined: Jul 2014
R
addict
Offline
addict
R
Joined: Jul 2014
The reason it's triggering when even one items is present is because 1) ItemEnteredTrigger triggers, and 2) The item is indeed in the database, so 3) The text is displayed on the first item.

You might want to check and see if this code works:
Code
TriggerRegisterForItems(TRIGGER_HIB_ENIGMA02_Optable);

DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART1);
DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART2);
DB_Enigma02_bodyparts(ITEM_HIB_ENIGMA02_BODYPART3);

IF
ItemEnteredTrigger(_Item,TRIGGER_HIB_ENIGMA02_Optable,_Player)
AND
DB_Enigma02_bodyparts(_Item)
THEN
PopulateTempList();
DisplayWhenAllItemsArePresent();
RemoveTempTrigger();


PROC
PopulateTempList()
AND
DB_Enigma02_bodyparts(_Item)
THEN
NOT DB_Enigma02_bodyparts(_Item);
DB_TempList(_Item);
PopulateTempList();
NOT DB_TempList(_Item);
DB_Enigma02_bodyparts(_Item);

IF
DB_TempList(_Item)
AND
ItemIsInTrigger(_Item, ITEM_HIB_ENIGMA02_Optable, 0)
THEN
DB_NotInTrigger(1);

PROC
DisplayWhenAllItemsArePresent()
AND
NOT DB_NotInTrigger(1)
THEN
CharacterDisplayText(CHARACTER_CHARACTER_Player1, "PENNY_01");

PROC
RemoveTempTrigger()
AND
DB_NotInTrigger(_Num)
THEN
NOT DB_NotInTrigger(_Num);
RemoveTempTrigger();

If I wrote the code correctly (read: I haven't tested this), then it should be making use of Recursive PROCs to iterate through the list of items and checking whether they are in the trigger, and flagging it if they're not. Then it displays the text if it wasn't flagged.

Joined: Sep 2014
S
stranger
Offline
stranger
S
Joined: Sep 2014
Here's a slightly more concise version of Rhidian's solution. Tested and confirmed working.

Code
TriggerRegisterForItems(TRIGGER_test);

DB_Enigma02_bodyparts(ITEM_test1);
DB_Enigma02_bodyparts(ITEM_test2);
DB_Enigma02_bodyparts(ITEM_test3);


IF
ItemEnteredTrigger(_Item,TRIGGER_test,_Player)
AND
DB_Enigma02_bodyparts(_Item)
THEN
DB_AllInTrigger(1);
TestAllInTrigger();
DisplayWhenAllItemsArePresent(_Player);

PROC TestAllInTrigger()
AND
DB_Enigma02_bodyparts(_Item)
AND
ItemIsInTrigger(_Item,TRIGGER_test,0)
THEN
NOT DB_AllInTrigger(1);

PROC
DisplayWhenAllItemsArePresent((CHARACTER) _player)
AND
DB_AllInTrigger(1)
THEN
CharacterDisplayText(_player, "PENNY_01");



Note that by passing player to the proc we can ensure that the text will display over the character that moved the object.

Joined: Jul 2014
Z
stranger
OP Offline
stranger
Z
Joined: Jul 2014
Thanks for the replies! I got the basic idead around databases, I think. Still, I suppose isn't that worthed using them in this particular script.

Just one thing about DB_AllInTrigger(1). Is this 1 a var or a way to add things to the database? In this case the item_bodyparts?

Joined: Jul 2014
R
addict
Offline
addict
R
Joined: Jul 2014
When a Database is in a THEN statement, the game creates that database when it is reached. Databases can be created and values added (or removed) mid-game, which is one of the few ways for different functions to communicate with each other.

In svansted's example, DB_AllInTrigger(1) is creating a new database with an Integer entry of 1. The next part of the code then removes this flag if an item is not within the trigger area (by using NOT DB_AllInTrigger(1); in the THEN statement). Finally the last part checks whether the Database still exists, and displays the result if so.


Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.5