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

Solved Name of client in PrintHintTextToAll


Post New Thread Reply   
 
Thread Tools Display Modes
91346706501435897134
Member
Join Date: Oct 2017
Old 11-26-2017 , 12:22   Re: Name of client in PrintHintTextToAll
Reply With Quote #11

Code:
#include <sourcemod>



#pragma newdecls        required
#pragma semicolon        1



#define PLUGIN_AUTHOR    "91346706501435897134"
#define PLUGIN_VERSION    "1.0"

#define COOLDOWN_TIME    30.0



bool bCooldown[MAXPLAYERS+1] = false;

Handle cooldown_timer[MAXPLAYERS+1];



public Plugin myinfo =
{
    name = "Request Heal",
    author = PLUGIN_AUTHOR,
    description = "Request heal",
    version = PLUGIN_VERSION,
    url = "http://steamcommunity.com/profiles/76561198356491749"
};



public void OnPluginStart()
{
    RegConsoleCmd("sm_healmenu", cmd_openmenu, "Opens heal menu.");
    RegConsoleCmd("sm_requestheal", cmd_requestheal, "Request heal.");
}



public Action cmd_openmenu(int client, int args)
{
    Handle menu = CreateMenu(healmenu);
    SetMenuTitle(menu, "Heal menu");
    AddMenuItem(menu, "option1", "Request Heal");

    SetMenuExitButton(menu, true);

    DisplayMenu(menu, client, 60);



    return Plugin_Handled;
}



public int healmenu(Menu menu, MenuAction action, int client, int selection)
{
    switch (action)
    {
        case MenuAction_Select:
        {
            char item[64];
            GetMenuItem(menu, selection, item, sizeof(item));

            if (StrEqual(item, "option1", true))
            {
                cmd_requestheal(client, 0);
                RedrawMenu(client);
            }
        }
        case MenuAction_End:
        {
            CancelMenu(menu);
        }
    }
}



void RedrawMenu(int client)
{
    cmd_openmenu(client, 0);

}



public Action cmd_requestheal(int client, int args)
{
    if (!bCooldown[client])
    {
        PrintHintTextToAll("%N want heal!", client);

        bCooldown[client] = true;

        cooldown_timer[client] = CreateTimer(COOLDOWN_TIME, cooldown, client);
    }
    else
    {
        ReplyToCommand(client, ">> Command is in cooldown.");
    }



    return Plugin_Handled;
}



public Action cooldown(Handle timer, int client)
{
    bCooldown[client] = false;
}
Try that.
Attached Files
File Type: sp Get Plugin or Get Source (test.sp - 200 views - 1.8 KB)
91346706501435897134 is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 11-26-2017 , 12:36   Re: Name of client in PrintHintTextToAll
Reply With Quote #12

Quote:
Originally Posted by shanapu View Post
there is no need for GetClientName. You can just use %N for nickname

PHP Code:
PrintHintTextToAll("%N want heal!"client); 
Thanks for info, next time i will use it..
Javierko is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 11-26-2017 , 13:40   Re: Name of client in PrintHintTextToAll
Reply With Quote #13

Well I post mine too, even if people are faster than me :^)
PHP Code:
#include <sourcemod>
#define REQUESTHEAL "#heal"

Handle Delay[MAXPLAYERS+1] = null;
int TimerCount[MAXPLAYERS+1];

public 
Plugin:myinfo =
{
    
name "HealRequestMenu",
    
author "Walgrim",
    
description "Displays a menu to request heal",
    
version "1.0",
    
url "http://steamcommunity.com/id/walgrim/"
};

public 
void OnPluginStart() {
  
RegConsoleCmd("sm_menu"Command_DisplayMenu"A command that displays the menu");
}

public 
int MenuHandler(Menu menuMenuAction actionint param1int param2) {
  switch (
action) {
    case 
MenuAction_Select:
    {
      
char info[32];
      
menu.GetItem(param2infosizeof(info));
      if (
StrEqual(infoREQUESTHEAL)) {
        if (
TimerCount[param1] < 1) {
          
CreateTimer(0.1PrintHintGetClientUserId(param1));
          
Delay[param1] = CreateTimer(1.0Timer_CountdownGetClientUserId(param1), TIMER_REPEAT);
        }
      }
    }
    case 
MenuAction_DisplayItem:
    {
      
char info[32], display[64];
      
menu.GetItem(param2infosizeof(info));
      if (
TimerCount[param1] < 30 && TimerCount[param1] > 0) {
        if (
StrEqual(infoREQUESTHEAL)) {
          
Format(displaysizeof(display), "Request Heal (Available in %i secs)"30 TimerCount[param1]);
          return 
RedrawMenuItem(display);
        }
      }
    }
    case 
MenuAction_DrawItem:
    {
      
char info[32];
      
menu.GetItem(param2infosizeof(info));
      if (
TimerCount[param1] < 30 && TimerCount[param1] > 0) {
        if (
StrEqual(infoREQUESTHEAL)) {
          return 
ITEMDRAW_DISABLED;
        }
      }
    }
    case 
MenuAction_End:
    {
      
delete menu;
    }
  }
  return 
0;
}

public 
Action Command_DisplayMenu(int clientint args) {
  
Menu menu = new Menu(MenuHandlerMenuAction_Select|MenuAction_DisplayItem|MenuAction_DrawItem|MenuAction_End);
  
menu.SetTitle("Your menu title");
  
menu.AddItem(REQUESTHEAL"Request Heal");
  
menu.ExitButton true;
  
menu.Display(client35);
  return 
Plugin_Handled;
}

public 
Action PrintHint(Handle Timerint clientid)
{
    
int client GetClientOfUserId(clientid);
    if (
client == 0) {
      return 
Plugin_Continue;
    }
    
PrintHintTextToAll("%N want heal!"client);
    return 
Plugin_Continue;
}

public 
Action Timer_Countdown(Handle Timerint clientid) {
    
int client GetClientOfUserId(clientid);
    if (
client == 0) {
        return 
Plugin_Continue;
    }
    
TimerCount[client]++;
    if (
TimerCount[client] > 30) {
    
ClearTimer(Delay[client]);
    
TimerCount[client] = 0;
    }
    return 
Plugin_Continue;
}

stock ClearTimer(&Handle:hTimer) {
    if (
hTimer != null) {
        
KillTimer(hTimer);
        
hTimer null;
    }

(I would be interested if someone tells me a better way to do a countdown like I did (with secs displaying))
Attached Files
File Type: sp Get Plugin or Get Source (HealRequestMenu.sp - 224 views - 2.7 KB)
__________________

Last edited by Walgrim; 11-29-2017 at 08:58.
Walgrim is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 11-26-2017 , 14:33   Re: Name of client in PrintHintTextToAll
Reply With Quote #14

Wow! Very nice job, i will use it into my plugin! Big thanks, i am sure, this topic is solved...

Thanks guys ^^
Javierko is offline
Reply


Thread Tools
Display Modes

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


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