Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing Wrong Key From Inventory
sixsevensix Offline
Junior Member

Posts: 2
Threads: 1
Joined: Dec 2010
Reputation: 0
#1
Removing Wrong Key From Inventory

I have run into trouble, I have made a puzzle that requires the player to go through and try different keys on a door to open it, one of the six keys are correct (this part works) and unlocks the door, the other 5 are wrong and need to be discarded, the problem I am having is creating a function general enough to work for any key that is NOT the key to the door. Is there a way to go about this without using an add item callback for each key?

Code:
////////////////////////////
// wrongkey function

void WrongOne(string &in asItem, string &in asEntity)
{
if(asItem!="LanternKey"){
PlaySoundAtEntity("", "lock_door.snt", "LanternDoor", 0.0f, false);
RemoveItem(asItem);
}
}


////////////////////////////
// Run when entering map
void OnEnter()
{

AddUseItemCallback("", "Wrong1", "LanternDoor", "WrongOne", false);

}
///////////
12-23-2010, 12:07 PM
Find
Dark88 Offline
Junior Member

Posts: 48
Threads: 6
Joined: Dec 2010
Reputation: 0
#2
RE: Removing Wrong Key From Inventory

(12-23-2010, 12:07 PM)sixsevensix Wrote: I have run into trouble, I have made a puzzle that requires the player to go through and try different keys on a door to open it, one of the six keys are correct (this part works) and unlocks the door, the other 5 are wrong and need to be discarded, the problem I am having is creating a function general enough to work for any key that is NOT the key to the door. Is there a way to go about this without using an add item callback for each key?

Code:
////////////////////////////
// wrongkey function

void WrongOne(string &in asItem, string &in asEntity)
{
if(asItem!="LanternKey"){
PlaySoundAtEntity("", "lock_door.snt", "LanternDoor", 0.0f, false);
RemoveItem(asItem);
}
}


////////////////////////////
// Run when entering map
void OnEnter()
{

AddUseItemCallback("", "Wrong1", "LanternDoor", "WrongOne", false);

}
///////////

I just recently started scripting but I'm pretty sure you could name the 5 wrong keys Wrong_1, Wrong_2, etc and in the AddUseItemCallback for the entity put "Wrong_*" As for discarding the keys just don't remove item until the correct key is used then in that function run RemoveItem("Wrong_*); and RemoveItem("Right").

That should work in giving you just one general function for the wrong keys instead of 5.
12-23-2010, 05:05 PM
Find
sixsevensix Offline
Junior Member

Posts: 2
Threads: 1
Joined: Dec 2010
Reputation: 0
#3
RE: Removing Wrong Key From Inventory

(12-23-2010, 05:05 PM)Dark88 Wrote: I just recently started scripting but I'm pretty sure you could name the 5 wrong keys Wrong_1, Wrong_2, etc and in the AddUseItemCallback for the entity put "Wrong_*" As for discarding the keys just don't remove item until the correct key is used then in that function run RemoveItem("Wrong_*); and RemoveItem("Right").

That should work in giving you just one general function for the wrong keys instead of 5.

Sadly this did not work, the "Wrong_*" did not recognize any of the keys when they were wrong. For discarding I want it to remove the keys as you use them, since this is a beginning puzzle I don't want the user to have to sift through tons of keys just yet.

Current Code section:

////////////////////////////
// wrongkey function

void WrongOne(string &in asItem, string &in asEntity)
{
if(asItem!="LanternKey"){
PlaySoundAtEntity("", "lock_door.snt", "LanternDoor", 0.0f, false);
RemoveItem("Wrong_*");
}
}



////////////////////////////
// Run when entering map
void OnEnter()
{

// This addsfor right key
AddUseItemCallback("", "LanternKey", "LanternDoor", "LanternComp", true);

//This adds for wrong key(s)
AddUseItemCallback("", "Wrong_*", "LanternDoor", "WrongOne", false);


}
12-23-2010, 08:57 PM
Find
Dark88 Offline
Junior Member

Posts: 48
Threads: 6
Joined: Dec 2010
Reputation: 0
#4
RE: Removing Wrong Key From Inventory

Hmmm I'll do some experimentation and I have an idea how to get it to remove the key once its used I'll try them out on my test map and see if I can't figure something out.

Edit: Alright this is what I was able to come up with.
void OnStart()
{
    AddUseItemCallback("", "Right", "Castle", "UsedRightKeyOnDoor", true);
    AddUseItemCallback("", "Wrong_1", "Castle", "UsedWrongKeyOnDoor", false);
    AddUseItemCallback("", "Wrong_2", "Castle", "UsedWrongKeyOnDoor", false);
    AddUseItemCallback("", "Wrong_3", "Castle", "UsedWrongKeyOnDoor", false);
    AddUseItemCallback("", "Wrong_4", "Castle", "UsedWrongKeyOnDoor", false);
    AddUseItemCallback("", "Wrong_5", "Castle", "UsedWrongKeyOnDoor", false);
}

void UsedRightKeyOnDoor (string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("Castle", false, true);
    RemoveItem("Right");
    RemoveItem("Wrong_1");
    RemoveItem("Wrong_2");
    RemoveItem("Wrong_3");
    RemoveItem("Wrong_4");
    RemoveItem("Wrong_5");
    AddDebugMessage("Works", false);
}

void UsedWrongKeyOnDoor (string &in asItem, string &in asEntity)
{
    AddDebugMessage("Fail", false);
    if (asItem == "Wrong_1")
    {
        RemoveItem("Wrong_1");
        AddDebugMessage("Key should be gone", false);
    }
    if (asItem == "Wrong_2")
    {
        RemoveItem("Wrong_2");
        AddDebugMessage("Key should be gone", false);
    }
    if (asItem == "Wrong_3")
    {
        RemoveItem("Wrong_3");
        AddDebugMessage("Key should be gone", false);
    }
    if (asItem == "Wrong_4")
    {
        RemoveItem("Wrong_4");
        AddDebugMessage("Key should be gone", false);
    }
    if (asItem == "Wrong_5")
    {
        RemoveItem("Wrong_5");
        AddDebugMessage("Key should be gone", false);
    }
}

Alright using this I was able to kind of get what you seem to be describing obviously changing and adding other things as necessary. Still requires a bunch of lines of code but it only uses 2 functions which is better than having 5 similar functions wasting space. It does require you to still create an AddUseItemCallback for each key but that's just copy and paste and a number change.
(This post was last modified: 12-23-2010, 10:13 PM by Dark88.)
12-23-2010, 09:29 PM
Find




Users browsing this thread: 2 Guest(s)