Frictional Games Forum (read-only)
[SCRIPT] Display message when player tries to use lantern - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Display message when player tries to use lantern (/thread-48489.html)



Display message when player tries to use lantern - serbusfish - 05-27-2016

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?


RE: Display message when player tries to use lantern - Slanderous - 05-27-2016

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


Should work.


RE: Display message when player tries to use lantern - Mudbill - 05-27-2016

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.


RE: Display message when player tries to use lantern - serbusfish - 05-27-2016

(05-27-2016, 10:39 AM)Slanderous Wrote:
PHP Code:
    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.


RE: Display message when player tries to use lantern - Slanderous - 05-27-2016

PHP Code:
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:
RemoveTimer("tmr_check");
return; 
these into your getlanternactive func


RE: Display message when player tries to use lantern - Daemian - 05-27-2016

Another option:

PHP Code:
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:
SetLanternLitCallback(""); 



RE: Display message when player tries to use lantern - Mudbill - 05-27-2016

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:
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.


RE: Display message when player tries to use lantern - serbusfish - 06-01-2016

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.