Frictional Games Forum (read-only)
[SOLVED] If 'something' collides with area function - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SOLVED] If 'something' collides with area function (/thread-15660.html)



[SOLVED] If 'something' collides with area function - FlawlessHappiness - 05-27-2012

Yea so i have a bookshelf in one room, with 3 empty spaces.


In another room there is a lot of books spread out.

I want the player to take three books, from all of those books on the floor, and put them into the three spaces.

So there has to be a script in the bookshelf which adds and subtracts 1, for every book colliding and not-colliding with it. And this collide-area has to have a certain script that makes the script trigger if 'something' collides with it.

Nothing else can collide with the script, because the spaces are just as small as the books are.

Does this kind of script exist?

I searched a bit for it, and i got that i could take the books names and make a 'for' script.

Is there an easier way around?


RE: If 'something' collides with area function - Your Computer - 05-27-2012

Sticky areas.


RE: If 'something' collides with area function - FlawlessHappiness - 05-27-2012

Thank you! Still haven't explored all the possibilities of HPL Wink I will check it out!

I placed "Add_variable_1" and 2 and 3, under AttachFunction.

Here is my script so far

Spoiler below!


void Add_variable_1(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("book_placement_1", 1);

if(GetLocalVarInt("book_placement_1") == 1)
{
if(GetLocalVarInt("book_placement_2") == 1)
{
if(GetLocalVarInt("book_placement_3") == 1)
{
StartEffectFlash(1, 1.0, 1);
AddTimer("", 1, "RealLife_timer");
}
}
}
}

void Add_variable_2(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("book_placement_2", 1);

if(GetLocalVarInt("book_placement_1") == 1)
{
if(GetLocalVarInt("book_placement_2") == 1)
{
if(GetLocalVarInt("book_placement_3") == 1)
{
StartEffectFlash(1, 1.0, 1);
AddTimer("", 1, "RealLife_timer");
}
}
}
}

void Add_variable_3(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("book_placement_3", 1);

if(GetLocalVarInt("book_placement_1") == 1)
{
if(GetLocalVarInt("book_placement_2") == 1)
{
if(GetLocalVarInt("book_placement_3") == 1)
{
StartEffectFlash(1, 1.0, 1);
AddTimer("", 1, "RealLife_timer");
}
}
}
}

///TIMERS

void RealLife_timer(string &in asTimer)
{
TeleportPlayer("PlayerStartArea_3");
}


I had some problems with it, but now it works.

Remember to place something in the AttachAbleBodyName Smile


RE: If 'something' collides with area function - Twitchez - 05-27-2012

Something similar I used for my mod (but with cogwheels) was that I put three script-areas in the places I wanted the cogs to be. Then I took each cog and made a copy of them, assigned them to static and "non-active". The last thing I did was to use the AddEntityCallBack, so when each cog entered the area near where it should have been, the static cog became "visible" and the one you were moving "non-visible".

And if you want to run some sort of script when all the books are in the bookshelf, add 1 to your LocalVarInt for every time you add a book, and for each time the Player puts a book in the bookshelf, run an "if" function. "If LocalVarInt ==3...".

//Kind Regards


RE: If 'something' collides with area function - FlawlessHappiness - 05-27-2012

Yep. The problem would just be that it wouldn't be the same book that appears, than the one you place


RE: If 'something' collides with area function - Twitchez - 05-27-2012

(05-27-2012, 10:50 PM)beecake Wrote: Yep. The problem would just be that it wouldn't be the same book that appears, than the one you place
You don't have to make it a static, it's just a suggestion. Otherwise, AddEntityCollideCallback is a good suggestion for running your code and for AddLocalVarInt.


RE: If 'something' collides with area function - FlawlessHappiness - 05-27-2012

Yea Smile Except with that function i have to specify an item. I just want the player to grab 3 books and put them into the spaces Wink But anyway i have found a solution. The sticky area works perfectly!


RE: If 'something' collides with area function - Your Computer - 05-28-2012

(05-27-2012, 07:14 PM)beecake Wrote: I placed "Add_variable_1" and 2 and 3, under AttachFunction.

Here is my script so far

Spoiler below!


void Add_variable_1(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("book_placement_1", 1);

if(GetLocalVarInt("book_placement_1") == 1)
{
if(GetLocalVarInt("book_placement_2") == 1)
{
if(GetLocalVarInt("book_placement_3") == 1)
{
StartEffectFlash(1, 1.0, 1);
AddTimer("", 1, "RealLife_timer");
}
}
}
}

void Add_variable_2(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("book_placement_2", 1);

if(GetLocalVarInt("book_placement_1") == 1)
{
if(GetLocalVarInt("book_placement_2") == 1)
{
if(GetLocalVarInt("book_placement_3") == 1)
{
StartEffectFlash(1, 1.0, 1);
AddTimer("", 1, "RealLife_timer");
}
}
}
}

void Add_variable_3(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("book_placement_3", 1);

if(GetLocalVarInt("book_placement_1") == 1)
{
if(GetLocalVarInt("book_placement_2") == 1)
{
if(GetLocalVarInt("book_placement_3") == 1)
{
StartEffectFlash(1, 1.0, 1);
AddTimer("", 1, "RealLife_timer");
}
}
}
}

///TIMERS

void RealLife_timer(string &in asTimer)
{
TeleportPlayer("PlayerStartArea_3");
}


I had some problems with it, but now it works.

Remember to place something in the AttachAbleBodyName Smile

Here's the code i would have used; there's no need to add an AttachAbleBodyName to the sticky area:

PHP Code:
void AttachFunction(string &in areastring &in object)
{
    
AddDebugMessage(objectfalse);

    if (!
StringContains(object"BookSyntax"))
    {
        
SetAllowStickyAreaAttachment(false);
        return;
    }

    
SetAllowStickyAreaAttachment(true);
    
AddLocalVarInt("AttachedBooks"1);

    if (
GetLocalVarInt("AttachedBooks") == 3)
    {
        
AddDebugMessage("Puzzle completed!"false);

        
// Complete puzzle
    
}
}

void DetachFunction(string &in areastring &in object)
{
    
AddDebugMessage("Detaching: "+objectfalse);
    
AddLocalVarInt("AttachedBooks", -1);




RE: [SOLVED] If 'something' collides with area function - FlawlessHappiness - 05-28-2012

Yea.. well i don't know.. It works for me with my script Wink