| 
		
	
		| serbusfish   Member
 
 Posts: 211
 Threads: 75
 Joined: Aug 2012
 Reputation: 
0
 | 
			| 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 |  |  
	
		| Slanderous   Posting Freak
 
 Posts: 1,606
 Threads: 78
 Joined: Dec 2012
 Reputation: 
63
 | 
			| RE: Display message when player tries to use lantern 
 
				    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 |  |  
	
		| Mudbill   Muderator
 
 Posts: 3,881
 Threads: 59
 Joined: Apr 2013
 Reputation: 
179
 | 
			| 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 |  |  
	
		| serbusfish   Member
 
 Posts: 211
 Threads: 75
 Joined: Aug 2012
 Reputation: 
0
 | 
			| RE: Display message when player tries to use lantern 
 
				 (05-27-2016, 10:39 AM)Slanderous Wrote:      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 |  |  
	
		| Slanderous   Posting Freak
 
 Posts: 1,606
 Threads: 78
 Joined: Dec 2012
 Reputation: 
63
 | 
			| RE: Display message when player tries to use lantern 
 
				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  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 |  |  
	
		| Daemian   Posting Freak
 
 Posts: 1,129
 Threads: 42
 Joined: Dec 2012
 Reputation: 
49
 | 
			| RE: Display message when player tries to use lantern 
 
				Another option: void OnStart {SetLanternLitCallback("DenyLantern");
 }
 
 void DenyLantern( bool bState )
 {
 SetLanternActive(false, false);
 SetMessage("Messages", "NoLantern", 5);
 }
 
To let the player use the lantern again, use this:
 SetLanternLitCallback(""); 
 
				
(This post was last modified: 05-27-2016, 05:14 PM by Daemian.)
 |  |  
	| 05-27-2016, 05:12 PM |  |  
	
		| Mudbill   Muderator
 
 Posts: 3,881
 Threads: 59
 Joined: Apr 2013
 Reputation: 
179
 | 
			| 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: void OnStart(){
 SetLanternLitCallback("DenyLantern");
 }
 
 void DenyLantern(bool bState)
 {
 SetLanternActive(false, false);
 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 |  |  
	
		| serbusfish   Member
 
 Posts: 211
 Threads: 75
 Joined: Aug 2012
 Reputation: 
0
 | 
			| 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 |  |  |