Frictional Games Forum (read-only)

Full Version: [SOLVED] Still one problem to solve
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Okay so I have been busy with this script for a time now and I still can't seem to solve it I have this script the thing it should do is that when object_1-4 touches stickyArea_1-4 the puzzle should be completed. But now it doesn't really do anything.
this is the script:
Spoiler below!
const string[] oven_sticky_areas = {"OvenArea_1", "OvenArea_2", "OvenArea_3", "OvenArea_4"};
const string oven_object_name = "object";
const string oven_door_name = "extaction_oven_6";
const string oven_lever_name = "Lever_1";
void OnStart()
{
SetEntityConnectionStateChangeCallback(oven_lever_name, "CheckIngredients");
}
////////////LEVER CHECK/////////////////
void CheckIngredients(string &in asEntity, int alState)
{
if(alState == 1)
{
if (GetLocalVarInt(oven_sticky_areas[0]) == 1
&& GetLocalVarInt(oven_sticky_areas[1]) == 1
&& GetLocalVarInt(oven_sticky_areas[2]) == 1
&& GetLocalVarInt(oven_sticky_areas[3]) == 1)
{
AddDebugMessage("OvenPuzzle: Correct!", false);
AddTimer("CompleteOvenPuzzle", 1, "CompleteOvenPuzzle");
}
else
{
AddDebugMessage("OvenPuzzle: Wrong!", false);
SetMessage("Messages", "IncorrectCombination", 0);
}
}
}
void AttachObjectOven(string &in asStickyArea, string &in asBodyName)
{
if (StringContains(asBodyName, oven_object_name))
SetAllowStickyAreaAttachment(true);
else
{
SetAllowStickyAreaAttachment(false);
return;
}
AddDebugMessage(asStickyArea + " " + asBodyName, true);
asBodyName = StringSub(asBodyName, 0, oven_object_name.length() + 2);
AddDebugMessage(asBodyName, false);
if (StringContains(asStickyArea, "1") && StringContains(asBodyName, "1"))
SetLocalVarInt(asStickyArea, 1);
else if (StringContains(asStickyArea, "2") && StringContains(asBodyName, "2"))
SetLocalVarInt(asStickyArea, 1);
else if (StringContains(asStickyArea, "3") && StringContains(asBodyName, "3"))
SetLocalVarInt(asStickyArea, 1);
else if (StringContains(asStickyArea, "4") && StringContains(asBodyName, "4"))
SetLocalVarInt(asStickyArea, 1);
}
void DetachObjectOven(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt(asStickyArea, 0);
}
void CompleteOvenPuzzle(string &in asTimer)
{
SetSwingDoorLocked(oven_door_name, false, true);
SetMessage("Messages", "correctcombinationchemicals", 0);
}

nobody? If nobody know what wrong then I'm gonna try a making a new script...
Try SetMultiSliderCallback instead of SetEntityConnectionStateChangeCallback.
I think it should work then.
It's a complicated script. I don't really know what to do, because I know a little about sticky areas. I hate the inability to help people Sad
So basically you're trying to place 4 objects on 4 sticky area, but want to make it possible to place them in any order, right?
It probably isn't as complicated as you think it would be.

AttachObject gets called when you place the object on the sticky area, I think you already know how to configure this, if not, ask.
Code:
void AttachObject(string &in asArea, string &in asBody, string &in asEntity)
{
SetLocalVarInt(asArea, 1); //For example: Name your areas "sticky_1" "sticky_2" and so on
SetEntityInteractionDisabled(asEntity, true);
}

void CheckIngredients(string &in asEntity, int alState)
{
if(alState == 1)
{
if (GetLocalVarInt("sticky_1") == 1
&& GetLocalVarInt("sticky_2") == 1
&& GetLocalVarInt("sticky_3") == 1
&& GetLocalVarInt("sticky_4") == 1)
{
AddDebugMessage("OvenPuzzle: Correct!", false);
AddTimer("CompleteOvenPuzzle", 1, "CompleteOvenPuzzle");
}
}
}
Note: This will only work if any of the objects can be placed on any sticky area. You have to configure this by yourself if but it seems you've already done that.
(10-18-2012, 09:08 AM)Ongka Wrote: [ -> ]So basically you're trying to place 4 objects on 4 sticky area, but want to make it possible to place them in any order, right?
It probably isn't as complicated as you think it would be.

AttachObject gets called when you place the object on the sticky area, I think you already know how to configure this, if not, ask.
Code:
void AttachObject(string &in asArea, string &in asBody, string &in asEntity)
{
SetLocalVarInt(asArea, 1); //For example: Name your areas "sticky_1" "sticky_2" and so on
SetEntityInteractionDisabled(asEntity, true);
}

void CheckIngredients(string &in asEntity, int alState)
{
if(alState == 1)
{
if (GetLocalVarInt("sticky_1") == 1
&& GetLocalVarInt("sticky_2") == 1
&& GetLocalVarInt("sticky_3") == 1
&& GetLocalVarInt("sticky_4") == 1)
{
AddDebugMessage("OvenPuzzle: Correct!", false);
AddTimer("CompleteOvenPuzzle", 1, "CompleteOvenPuzzle");
}
}
}
Note: This will only work if any of the objects can be placed on any sticky area. You have to configure this by yourself if but it seems you've already done that.
well no it's only supposed to work if the correct objects are in the correct sticky area's so 1 for 1 an d 2 for 2 ect.
The areas are called sticky_1 - 4 and the entites which are placed on the areas are called _body_1 - 4
Code:
void AttachObject(string &in asArea, string &in asBody, string &in asEntity)
{
    if(asArea + asEntity == "sticky_1_body_1")
    {
    SetLocalVarInt(asArea, 1); //In this case the Var is called sticky_1
    SetEntityInteractionDisabled(asEntity, true);
    }
    else if(asArea + asEntity == "sticky_2_body_2")
    {
    SetLocalVarInt(asArea, 1); //In this case the Var is called sticky_2
    SetEntityInteractionDisabled(asEntity, true);
    }
    else if(asArea + asEntity == "sticky_3_body_3")
    {
    SetLocalVarInt(asArea, 1); //In this case the Var is called sticky_3
    SetEntityInteractionDisabled(asEntity, true);
    }
    else if(asArea + asEntity == "sticky_4_body_4")
    SetEntityInteractionDisabled(asEntity, true);
    {
    SetLocalVarInt(asArea, 1); //In this case the Var is called sticky_4
    SetEntityInteractionDisabled(asEntity, true);
    }
    else
    {
    AddDebugMessage(asEntity + " doesn't fit on " + asArea, false);
    }    
}

void CheckIngredients(string &in asEntity, int alState)
{
if(alState == 1)
{
if (GetLocalVarInt("sticky_1") == 1
&& GetLocalVarInt("sticky_2") == 1
&& GetLocalVarInt("sticky_3") == 1
&& GetLocalVarInt("sticky_4") == 1)
{
AddDebugMessage("OvenPuzzle: Correct!", false);
AddTimer("CompleteOvenPuzzle", 1, "CompleteOvenPuzzle");
}
}
}
Try it out, may or may not work.
Try GetEntitiesCollide instead of making variables?
There surely are easier ways to script it, but i usually don't use sticky areas.
I finaly did it with this script I made;
Spoiler below!
void OnStart()
{
SetEntityConnectionStateChangeCallback("Lever_1", "CheckIngredients");
}
////////////LEVER CHECK/////////////////
void CheckIngredients(string &in asEntity, int alState)
{
if(alState == 1)
{
if (GetLocalVarInt("oven_1_correct") == 1
&& GetLocalVarInt("oven_2_correct") == 1
&& GetLocalVarInt("oven_3_correct") == 1
&& GetLocalVarInt("oven_4_correct") == 1)
{

AddDebugMessage("OvenPuzzle: Correct!", false);
AddTimer("ovencomplete", 1, "CompleteOvenPuzzle");
}
else
{
AddDebugMessage("OvenPuzzle: Wrong!", false);
SetMessage("Messages", "IncorrectCombination", 0);
}
}
}

void PutObjectOven_1(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_1_correct", 1);
}
void DetachObjectOven_1(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_1_correct", 0);
}
void PutObjectOven_2(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_2_correct", 1);
}
void DetachObjectOven_2(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_2_correct", 0);
}
void PutObjectOven_3(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_3_correct", 1);
}
void DetachObjectOven_3(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_3_correct", 0);
}
void PutObjectOven_4(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_4_correct", 1);
}
void DetachObjectOven_4(string &in asStickyArea, string &in asBodyName)
{
SetLocalVarInt("oven_4_correct", 0);
}
void CompleteOvenPuzzle(string &in asTimer)
{
SetSwingDoorLocked("extaction_oven_6", false, true);
SetMessage("Messages", "correctcombinationchemicals", 0);
}