Raised This Month: $51 Target: $400
 12% 

Keeping a WPanel opened until another panel is opened


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Synchroneyes
Junior Member
Join Date: Feb 2019
Old 02-27-2019 , 18:54   Keeping a WPanel opened until another panel is opened
Reply With Quote #1

Hi,
So i'm trying to keep a panel opened as long as another one is opened, and open this one back when the old one is closed.

For example;
I have InfoPanel that needs to be opened all time, can't be closes
If i want to open xPanel then xPanel shows up, InfoPanel get closed, and when xPanel get closed then InfoPanel get opened back

At the moment, i'm doing this
PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_spawn"TimerAfficherHubSpawn);
}

public 
Action:TimerAfficherHubSpawn(Handle:hEvent, const String:szName[], bool:bDontBroadcast)
{
    new 
iClient GetClientOfUserId(GetEventInt(hEvent"userid"));
    
CreateTimer(0.5afficherHUBRespawniClientTIMER_REPEAT);

public 
Action:afficherHUBRespawn(Handle timerclient)
{
    new 
Handle:WPanel CreatePanel(INVALID_HANDLE);
    
SetPanelTitle(WPanel"title");
    
DrawPanelText(WPanel"text: ?");
    
DrawPanelText(WPanel"text: ?");
    
DrawPanelText(WPanel"text: ?");
    
DrawPanelText(WPanel"text: ?");
    
DrawPanelText(WPanel"text: ?");
    
DrawPanelText(WPanel"text: ?");
    
SendPanelToClient(WPanelclientNullMenuHandler20);
    
//CloseHandle(WPanel);
}
public 
NullMenuHandler(Handle:WPanelMenuAction:actionparam1param2
{
    
CloseHandle(WPanel);

but, thing is if i do a command like /admin, the admin menu doesn't show up. It does but get insta closed...
Any idea on how i need to do this ?
Synchroneyes is offline
adma
Senior Member
Join Date: Oct 2015
Old 02-27-2019 , 21:39   Re: Keeping a WPanel opened until another panel is opened
Reply With Quote #2

At the top of the timer callback, check if client is in a menu using GetClientMenu(client) == MenuSource_None. The idea is you only draw the panel if the client is not in a menu. When the client closes the menu, the timer will see they are not in a menu and display your panel. When dealing with clients and timers, ALWAYS pass a serial / userid instead of the client index, because the client may not be valid by the timer fires. You should also be consistent with your syntax i.e. either use old syntax or new syntax, not both.

PHP Code:
public void OnPluginStart() 

  
HookEvent("player_spawn"TimerAfficherHubSpawn); 


public 
Action TimerAfficherHubSpawn(Event hEvent, const char[] szNamebool bDontBroadcast
{
  
// Use userid because client will be invalid if they disconnect before the timer callback is invoked
  
int iUserId hEvent.GetInt("userid"); 
  
CreateTimer(0.5afficherHUBRespawniUserIdTIMER_REPEAT); 
}  

public 
Action afficherHUBRespawn(Handle hTimerint iUserId
{
  
int iClient GetClientOfUserId(iUserId);

  
// This guarantees the timer will stop when they disconnect, including map change disconnects
  
if (iClient == || !IsClientInGame(iClient)) return Plugin_Stop;

  
// If the client is in a menu already, do not continue but keep the timer going
  
if (GetClientMenu(iClient) != MenuSource_None) return Plugin_Continue;

  
Panel WPanel = new Panel(null);

  
WPanel.SetTitle("title");

  
WPanel.DrawText("text: ?");
  
WPanel.DrawText("text: ?");
  
WPanel.DrawText("text: ?");
  
WPanel.DrawText("text: ?");
  
WPanel.DrawText("text: ?");
  
WPanel.DrawText("text: ?");

  
WPanel.Send(iClientNullMenuHandler20);

  
delete WPanel// Free the memory here because the handle is useless in the callback anyway
}

public 
int NullMenuHandler(Menu hMenuMenuAction actionint iParam1int iParam2)  
{
  
/* You can check MenuAction_Select and MenuAction_Cancel in here */
  
return 0;


Last edited by adma; 02-27-2019 at 21:41. Reason: client -> iClient
adma is offline
Synchroneyes
Junior Member
Join Date: Feb 2019
Old 02-28-2019 , 03:27   Re: Keeping a WPanel opened until another panel is opened
Reply With Quote #3

Thank you, it's working fine !
Synchroneyes is offline
adma
Senior Member
Join Date: Oct 2015
Old 02-28-2019 , 07:24   Re: Keeping a WPanel opened until another panel is opened
Reply With Quote #4

No worries, its also worth noting you probably want to track the timer handle and stop it each round because this will create multiple timers if a player spawns in more than once more map.
adma is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode