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
Problem with door closing
Spazatron Offline
Junior Member

Posts: 33
Threads: 17
Joined: Oct 2012
Reputation: 2
#1
Problem with door closing

I have a script where if the player goes through an area where a door is, and has certain items in their inventory, the door will close and lock itself behind them. When they go through the area, I'm using HasItem(); to check that they have the items, but the door doesn't close or lock.

My code:
void OnStart()
{
    AddEntityCollideCallback("Player", "enabledoorscript", "DoorScript", false, 1); //area to check if the door should close or not depending on if the player has items
}

void DoorScript(string &in asParent, string &in asChild, int alState)
{
    if(HasItem("ITEM1") && HasItem("ITEM2") && HasItem("ITEM3")) //checking for items
    {
        AddEntityCollideCallback("Player", "closedoor", "CloseDoor", true, 1); //they do, so add the collision callback for the area
    }
}

void CloseDoor(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("door1", true, true); //close the door
    SetSwingDoorLocked("door1", true, true); //lock the door
}
10-13-2014, 05:18 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#2
RE: Problem with door closing

You've got the idea, but you forgot to check if it's true or false that you have it...

if you go here:
http://wiki.frictionalgames.com/hpl2/amn..._functions
You'll notice that "HasItem" requires a bool. (It says 'bool' to the left of it).

A bool is either "true" or "false".

So, to make your script correct, it should look like this.

PHP Code: (Select All)
void OnStart()
{
    
AddEntityCollideCallback("Player""enabledoorscript""DoorScript"false1); //area to check if the door should close or not depending on if the player has items
}

void DoorScript(string &in asParentstring &in asChildint alState)
{
    if(
HasItem("ITEM1") == true && HasItem("ITEM2") == true && HasItem("ITEM3") == true//checking for items
    
{
        
SetSwingDoorLocked("door1"truetrue); //lock the door when true
    
}


This should work.

I also added some adjustments

Trying is the first step to success.
(This post was last modified: 10-13-2014, 05:40 PM by FlawlessHappiness.)
10-13-2014, 05:39 PM
Find
Spazatron Offline
Junior Member

Posts: 33
Threads: 17
Joined: Oct 2012
Reputation: 2
#3
RE: Problem with door closing

(10-13-2014, 05:39 PM)FlawlessHappiness Wrote: You've got the idea, but you forgot to check if it's true or false that you have it...

if you go here:
http://wiki.frictionalgames.com/hpl2/amn..._functions
You'll notice that "HasItem" requires a bool. (It says 'bool' to the left of it).

A bool is either "true" or "false".

So, to make your script correct, it should look like this.

PHP Code: (Select All)
void OnStart()
{
    
AddEntityCollideCallback("Player""enabledoorscript""DoorScript"false1); //area to check if the door should close or not depending on if the player has items
}

void DoorScript(string &in asParentstring &in asChildint alState)
{
    if(
HasItem("ITEM1") == true && HasItem("ITEM2") == true && HasItem("ITEM3") == true//checking for items
    
{
        
SetSwingDoorLocked("door1"truetrue); //lock the door when true
    
}


This should work.

I also added some adjustments

Thanks for the reply. I corrected the code, but it still isn't working. The door also behaves strangely after I enter the area that should lock it. It only lets me grab the door in certain places at the top of the door while (I think) I'm inside the script area. :S

EDIT: I'm so stupid. I made a typo on one of the entity's names. Sorry for the inconvenience XD

Fixed it.
(This post was last modified: 10-13-2014, 06:27 PM by Spazatron.)
10-13-2014, 06:03 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#4
RE: Problem with door closing

So everything works?

Trying is the first step to success.
10-13-2014, 06:49 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#5
RE: Problem with door closing

Just as a side note, the original boolean statements were correct. You don't explicitly need to define a true or false to the boolean in question. If undefined, it assumes true. Another way of doing false would be do to
PHP Code: (Select All)
if(!HasItem("Name")) 

10-13-2014, 09:33 PM
Find
MrBehemoth Offline
Senior Member

Posts: 408
Threads: 19
Joined: Feb 2014
Reputation: 40
#6
RE: Problem with door closing

(10-13-2014, 09:33 PM)Mudbill Wrote: Just as a side note, the original boolean statements were correct. You don't explicitly need to define a true or false to the boolean in question. If undefined, it assumes true. Another way of doing false would be do to
PHP Code: (Select All)
if(!HasItem("Name")) 

This.

Actually, the reason this works is because the "if" statement is checking whether the whole condition (the entire contents of the brackets) works out as "true", eg:

if(true)
if(!false)
if(1 + 1 == 2)
if(2 == 2)
if(x == x)
if(false == false)
if(false != true)
if(false == !true)
if((false == true) == (true == false))
if((false == !true) == (true == !false))
if(StringToBool("true"))

...are all different ways of saying "if(true)", and the condition would pass.

(This post was last modified: 10-13-2014, 10:25 PM by MrBehemoth.)
10-13-2014, 10:17 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#7
RE: Problem with door closing

^ Good points.

10-13-2014, 11:15 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#8
RE: Problem with door closing

So eh... That means it was all correct from the beginning?

How come it worked when he put " == true" on it then...?



Maybe because of the "Adjustments" I made... Not sure.

Trying is the first step to success.
(This post was last modified: 10-13-2014, 11:26 PM by FlawlessHappiness.)
10-13-2014, 11:25 PM
Find
MrBehemoth Offline
Senior Member

Posts: 408
Threads: 19
Joined: Feb 2014
Reputation: 40
#9
RE: Problem with door closing

(10-13-2014, 06:03 PM)NickD Wrote: EDIT: I'm so stupid. I made a typo on one of the entity's names. Sorry for the inconvenience XD

Fixed it.

I guess that was the problem all along.

10-13-2014, 11:48 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#10
RE: Problem with door closing

(10-13-2014, 11:48 PM)MrBehemoth Wrote:
(10-13-2014, 06:03 PM)NickD Wrote: EDIT: I'm so stupid. I made a typo on one of the entity's names. Sorry for the inconvenience XD

Fixed it.

I guess that was the problem all along.

Haha!
^-^

Oh well, I learned stuff! Thank you!

Trying is the first step to success.
10-14-2014, 12:34 AM
Find




Users browsing this thread: 1 Guest(s)