Frictional Games Forum (read-only)

Full Version: Need help on a script ;) [solved!]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wanna make if you interact something you teleport i made that.
But now i want that you need a key for it..
So if you didn't use the key on it starts SetMessage and then a text like. I'ts locked i need a key to enter. and if you interact then you teleport to the cellar.

If you don't understand what i mean i show some pictures to make it clear.

Script in spoiler
Spoiler below!

HPS.

////////////////////////////
// Run first time starting map
void OnStart()
{
//---- COLLIDE CALLBACKS ----//
AddUseItemCallback("", "Cellar_Key", "CellarDoor1", "OpenCellarDoor1", true);

}

void OpenCellarDoor1(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("CellarDoor1", false, true);
PlaySoundAtEntity("", "unlock_door", "CellarDoor1", 0, false);
RemoveItem("Cellar_Key");
}

void EnterCellar(string &in asEntity)
{
TeleportPlayer("InCellar");
SetMessage("Messages", "EnteringTheCellar", 5.0);
}

void LeaveCellar(string &in asEntity)
{
TeleportPlayer("OutCellar");
}
////////////////////////////
// Run when entering map
void OnEnter()
{

AutoSave();
}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}

LANG.

<LANGUAGE>
<RESOURCES>
</RESOURCES>
<CATEGORY Name="CustomStoryMain">
<Entry Name="Description">[br][br][br][br][br][br][br][br][br][br][br][br][br][br][br]</Entry>
</CATEGORY>

<CATEGORY Name="Messages">
<Entry Name="EnteringTheCellar">This seems like a storage, Maybe i can find something useful!</Entry>
</CATEGORY>

<CATEGORY Name="Inventory">
<Entry Name="ItemDesc_Cellar_Key">It's a Rusty Key, There is marked something on it, It is very rusty and hard to read[br]F*r Ent*r*ng Th*e C*ll*r.</Entry>
<Entry Name="ItemName_Cellar_Key">Rusty Key!</Entry>
</CATEGORY>

<CATEGORY Name="Journal">
<Entry Name="Note_DiaryJane_Name">Diary Jane 1/1</Entry>
<Entry Name="Note_DiaryJane_Text">My husband Jake is a miner.[br]He works in the mine here nearby already for 15 years.[br]Still im really scared that the mine is gonna colapsed,[br]The mine has been here for centuries![br]There is still a myth going around that there are some kind of monsters in there.[br]Me and Jake dont believe in myths,[br]But...What if they are really there.[br][br]Former.[br]Jane.</Entry>
</CATEGORY>

<CATEGORY Name="Levels">
</CATEGORY>

</LANGUAGE>


Pictures! Smile

Inside the cellar where it should go when used key and interact the door.

[Image: 10p5ybl.jpg]

The Cellar entrance at the back of the house.

[Image: 2052gr9.jpg]

Hope you can help me already thanks for helping!
Cheers Wink
I really don't understand your question, but you have no variable that activated the 'EnterCellar'-function.
(04-13-2013, 04:23 PM)Tiger Wrote: [ -> ]I really don't understand your question, but you have no variable that activated the 'EnterCellar'-function.

I mean i want that if you interact whitout using the key. it says you need a key to open this. something like that

After you used it you can interact and get teleported to the cellar location.
Create a script area around the door and make sure that it has ItemInteraction enabled. I named the area ScriptArea_1 in the script. You'll also need the change the entry name for the message.
PHP Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
    
SetLocalVarInt("CellarDoorOpen"0);
    
    
AddUseItemCallback("""Cellar_Key""ScriptArea_1""OpenCellarDoor1"true);
    
SetEntityPlayerInteractCallback("ScriptArea_1""EnterCellar"false);


void OpenCellarDoor1(string &in asItemstring &in asEntity)
{
    
AddLocalVarInt("CellarDoorOpen"1);
    
PlaySoundAtEntity("""unlock_door""CellarDoor1"0false);
    
RemoveItem("Cellar_Key");
}

void EnterCellar(string &in asEntity)
{
    if(
GetLocalVarInt("CellarDoorOpen") != 1) {
        
SetMessage("Messages""EntryName"0);
        return;
    }
    
    
TeleportPlayer("InCellar");
    
SetMessage("Messages""EnteringTheCellar"5.0);
}

void LeaveCellar(string &in asEntity)
{
    
TeleportPlayer("OutCellar");
}

////////////////////////////
// Run when entering map
void OnEnter()
{    
    
AutoSave();
}

////////////////////////////
// Run when leaving map
void OnLeave()
{


(04-13-2013, 05:34 PM)NaxEla Wrote: [ -> ]Create a script area around the door and make sure that it has ItemInteraction enabled. I named the area ScriptArea_1 in the script. You'll also need the change the entry name for the message.
PHP Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
    
SetLocalVarInt("CellarDoorOpen"0);
    
    
AddUseItemCallback("""Cellar_Key""ScriptArea_1""OpenCellarDoor1"true);
    
SetEntityPlayerInteractCallback("ScriptArea_1""EnterCellar"false);


void OpenCellarDoor1(string &in asItemstring &in asEntity)
{
    
AddLocalVarInt("CellarDoorOpen"1);
    
PlaySoundAtEntity("""unlock_door""CellarDoor1"0false);
    
RemoveItem("Cellar_Key");
}

void EnterCellar(string &in asEntity)
{
    if(
GetLocalVarInt("CellarDoorOpen") != 1) {
        
SetMessage("Messages""EntryName"0);
        return;
    }
    
    
TeleportPlayer("InCellar");
    
SetMessage("Messages""EnteringTheCellar"5.0);
}

void LeaveCellar(string &in asEntity)
{
    
TeleportPlayer("OutCellar");
}

////////////////////////////
// Run when entering map
void OnEnter()
{    
    
AutoSave();
}

////////////////////////////
// Run when leaving map
void OnLeave()
{


Not working 100% like i want to but thx anyway.
Really nice that the text shown when i interact but.
When i use the key its open but the text is still getting shown.
And also if i interact it again i don't teleport to the cellar Wink
That's strange :\ When I tested it, it worked perfectly

Here's the exact script I used to test it. I also made it so that the text will only show up the first time the player enters the cellar. You'll need to change the names teleport areas and .lang entries.
PHP Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
    
SetLocalVarInt("CellarDoorOpen"0);
    
SetLocalVarInt("FirstTimeCellar"1);
    
    
AddUseItemCallback("""Cellar_Key""ScriptArea_1""OpenCellarDoor1"true);
    
SetEntityPlayerInteractCallback("ScriptArea_1""EnterCellar"false);
    
SetEntityPlayerInteractCallback("ScriptArea_2""LeaveCellar"false);


void OpenCellarDoor1(string &in asItemstring &in asEntity)
{
    
SetLocalVarInt("CellarDoorOpen"1);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);
}

void EnterCellar(string &in asEntity)
{
    if(
GetLocalVarInt("CellarDoorOpen") != 1) {
        
SetMessage("Messages""DoorLocked"0);
        return;
    }
    
    
TeleportPlayer("InsideCellar");
    
    if(
GetLocalVarInt("FirstTimeCellar") == 1) {
        
SetMessage("Messages""EnteringTheCellar"0);
        
SetLocalVarInt("FirstTimeCellar"0);
    }
}

void LeaveCellar(string &in asEntity)
{
    
TeleportPlayer("OutsideCellar");
}

////////////////////////////
// Run when entering map
void OnEnter()
{    
    
AutoSave();
}

////////////////////////////
// Run when leaving map
void OnLeave()
{


(04-13-2013, 10:44 PM)NaxEla Wrote: [ -> ]That's strange :\ When I tested it, it worked perfectly

Here's the exact script I used to test it. I also made it so that the text will only show up the first time the player enters the cellar. You'll need to change the names teleport areas and .lang entries.
PHP Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
    
SetLocalVarInt("CellarDoorOpen"0);
    
SetLocalVarInt("FirstTimeCellar"1);
    
    
AddUseItemCallback("""Cellar_Key""ScriptArea_1""OpenCellarDoor1"true);
    
SetEntityPlayerInteractCallback("ScriptArea_1""EnterCellar"false);
    
SetEntityPlayerInteractCallback("ScriptArea_2""LeaveCellar"false);


void OpenCellarDoor1(string &in asItemstring &in asEntity)
{
    
SetLocalVarInt("CellarDoorOpen"1);
    
PlaySoundAtEntity("""unlock_door"asEntity0false);
    
RemoveItem(asItem);
}

void EnterCellar(string &in asEntity)
{
    if(
GetLocalVarInt("CellarDoorOpen") != 1) {
        
SetMessage("Messages""DoorLocked"0);
        return;
    }
    
    
TeleportPlayer("InsideCellar");
    
    if(
GetLocalVarInt("FirstTimeCellar") == 1) {
        
SetMessage("Messages""EnteringTheCellar"0);
        
SetLocalVarInt("FirstTimeCellar"0);
    }
}

void LeaveCellar(string &in asEntity)
{
    
TeleportPlayer("OutsideCellar");
}

////////////////////////////
// Run when entering map
void OnEnter()
{    
    
AutoSave();
}

////////////////////////////
// Run when leaving map
void OnLeave()
{


I have to add the script area at the door right or hatched whatever its called ;D
Well it works almost the only thing is i cant use the key on it.

Never mind working you just got + repp'd thanks allot Wink