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
Script Help Display message when player tries to use lantern
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#1
Display message when player tries to use lantern

I would like to disable the lantern and have a message display when the player tries to use it. The message works ok prior to the lantern being disabled but it wont display once it has been. I was using 'SetLanternLitCallback' to set the message, is there another way to do it?

05-27-2016, 10:20 AM
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#2
RE: Display message when player tries to use lantern

PHP Code: (Select All)
    if(GetLanternActive())
            {
                
//do stuff
            


Should work.
(This post was last modified: 05-27-2016, 10:39 AM by Slanderous.)
05-27-2016, 10:39 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
RE: Display message when player tries to use lantern

How is your code?

It might be possible but I wouldn't recommend it: You could use a looping timer to check the lantern state and force it off though I don't expect it to be any better than that callback. That's why it's there anyway.

(This post was last modified: 05-27-2016, 12:47 PM by Mudbill.)
05-27-2016, 12:47 PM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#4
RE: Display message when player tries to use lantern

(05-27-2016, 10:39 AM)Slanderous Wrote:
PHP Code: (Select All)
    if(GetLanternActive())
            {
                
//do stuff
            


Should work.

I tried that but the game didnt like it and threw back errors, I probably did something wrong.

(05-27-2016, 12:47 PM)Mudbill Wrote: How is your code?

It might be possible but I wouldn't recommend it: You could use a looping timer to check the lantern state and force it off though I don't expect it to be any better than that callback. That's why it's there anyway.

I simply put a script area over the map start position so when they spawn they hit it straight away:

Quote:AddEntityCollideCallback("Player", "ScriptArea_16", "LanternOff", true, 1);

void LanternOff(string &in asParent, string &in asChild, int alState)

{
SetLanternDisabled(true);

}

And then I have:

Quote:SetLanternLitCallback("NoUse");

void NoUse(bool abLit)



{
SetMessage("Messages", "NoLantern", 5);
}

I understand why it doesnt work, the lantern is is disabled so it cant light, I just need to figure a way around it.

05-27-2016, 03:58 PM
Find
Slanderous Offline
Posting Freak

Posts: 1,606
Threads: 78
Joined: Dec 2012
Reputation: 63
#5
RE: Display message when player tries to use lantern

PHP Code: (Select All)
void OnStart()
{
    
AddTimer("tmr_check"0.01f"check_lantern");
}

void check_lantern(string &in asTimer)
{
    if(
GetLanternActive())
            {
            
//do stuff
            
            

    
AddTimer("tmr_check"0.01f"check_lantern");

Try this. This is a timer which is looped unless the lantern is on, once its on you can put anything you want to happen in there. If you want to remove the timer after the first time player lits the lantern, add
PHP Code: (Select All)
RemoveTimer("tmr_check");
return; 
these into your getlanternactive func
(This post was last modified: 05-27-2016, 05:03 PM by Slanderous.)
05-27-2016, 05:03 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#6
RE: Display message when player tries to use lantern

Another option:

PHP Code: (Select All)
void OnStart {
SetLanternLitCallback("DenyLantern");
}

void DenyLanternbool bState )
{
SetLanternActive(falsefalse);
SetMessage("Messages""NoLantern"5);


To let the player use the lantern again, use this:
PHP Code: (Select All)
SetLanternLitCallback(""); 

(This post was last modified: 05-27-2016, 05:14 PM by Daemian.)
05-27-2016, 05:12 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#7
RE: Display message when player tries to use lantern

Personally I'd go with Daemian's suggestion. It will immediately turn the lantern back off after attempted enabling, which will also trigger the callback. Though I guess he hastily wrote the code, as it's not 100% correct:

PHP Code: (Select All)
void OnStart()
{
    
SetLanternLitCallback("DenyLantern");
}

void DenyLantern(bool bState)
{
    
SetLanternActive(falsefalse);
    
SetMessage("Messages""NoLantern"5);


Keep in mind it will still play the sounds of the player enabling the lantern.

(This post was last modified: 05-27-2016, 06:33 PM by Mudbill.)
05-27-2016, 06:31 PM
Find
serbusfish Offline
Member

Posts: 211
Threads: 75
Joined: Aug 2012
Reputation: 0
#8
RE: Display message when player tries to use lantern

Thank you very much and sorry for the delay in replying, i've been working on other areas of my story as I had no luck getting it to work.

06-01-2016, 10:55 PM
Find




Users browsing this thread: 1 Guest(s)