Raised This Month: $32 Target: $400
 8% 

Bring a sourcemod Menu API automaticly when a player join the server ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
weaponmen
Member
Join Date: Jun 2009
Old 03-02-2011 , 15:06   Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #1

Hello, I'm still new to sourcemod codding

for
PHP Code:
public OnPluginStart() {     RegConsoleCmd("menu_test1"Menu_Test1); } 
How shall I make this come automatically when a player join the server ?

I bet it's
PHP Code:
RegConsoleCmd 
to be replaced with an other command

Thanks !
__________________

weaponmen is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 03-02-2011 , 15:19   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #2

You create a separate function and fire it in player_spawn or similar event. It's the rule of thumb to create your function as "flat", and wrap events, console commands or natives around them.
__________________
FaTony is offline
weaponmen
Member
Join Date: Jun 2009
Old 03-02-2011 , 15:20   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #3

Quote:
Originally Posted by FaTony View Post
You create a separate function and fire it in player_spawn or similar event. It's the rule of thumb to create your function as "flat", and wrap events, console commands or natives around them.
Thanks a lot !! But, hm what event shall I choose if it has to come before the player spawn ?
__________________

weaponmen is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 03-02-2011 , 15:24   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #4

Player_spawn is fired when client join a spectator team before he chooses his team in CS:S. There's also player_activate, forgot how it works. Search.
__________________
FaTony is offline
weaponmen
Member
Join Date: Jun 2009
Old 03-02-2011 , 15:31   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #5

Quote:
Originally Posted by FaTony View Post
Player_spawn is fired when client join a spectator team before he chooses his team in CS:S. There's also player_activate, forgot how it works. Search.
Thanks a lot !!
__________________

weaponmen is offline
weaponmen
Member
Join Date: Jun 2009
Old 03-02-2011 , 16:14   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #6

PHP Code:
//Colorful_Peace http://steamcommunity.com/id/colorfulpeace

//Includes:

#include <sourcemod>
#pragma semicolon 1

// Info:

public Plugin:myinfo =
{
    
name "n/a",
    
author "Colorful Peace",
    
description "n/a",
    
version "1.0.0.0",
    
url "N/A"
};


  public 
OnPluginStart()
{
  
HookEvent("player_spawn"Event_player_spawn);
}
  public 
Event_player_spawn(Handle:menuMenuAction:actionparam1param2)
{
    
/* If an option was selected, tell the client about the item. */
    
if (action == MenuAction_Select)
    {
        new 
String:info[32];
        new 
bool:found GetMenuItem(menuparam2infosizeof(info));
        
PrintToConsole(param1"You selected item: %d (found? %d info: %s)"param2foundinfo);
    }
    
/* If the menu was cancelled, print a message to the server about it. */
    
else if (action == MenuAction_Cancel)
    {
        
PrintToServer("Client %d's menu was cancelled.  Reason: %d"param1param2);
    }
    
/* If the menu has ended, destroy it */
    
else if (action == MenuAction_End)
    {
        
CloseHandle(menu);
    }
}
 
public 
Action:Menu_Test1(clientargs)
{
    new 
Handle:menu CreateMenu(MenuHandler1);
    
SetMenuTitle(menu"Do you like apples?");
    
AddMenuItem(menu"yes""Yes");
    
AddMenuItem(menu"no""No");
    
SetMenuExitButton(menufalse);
    
DisplayMenu(menuclient20);
 
    return 
Plugin_Handled;

Hm, as I said I'm really new. Any Idea how to make this work ?
__________________

weaponmen is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 03-02-2011 , 16:49   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #7

Look at existing plugins on how to get the client from an event. Your code makes no sense.
AtomicStryker is offline
miniman
Senior Member
Join Date: Aug 2009
Location: Israel
Old 03-03-2011 , 00:10   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #8

Quote:
Originally Posted by weaponmen View Post
PHP Code:
//Colorful_Peace http://steamcommunity.com/id/colorfulpeace

//Includes:

#include <sourcemod>
#pragma semicolon 1

// Info:

public Plugin:myinfo =
{
    
name "n/a",
    
author "Colorful Peace",
    
description "n/a",
    
version "1.0.0.0",
    
url "N/A"
};


  public 
OnPluginStart()
{
  
HookEvent("player_spawn"Event_player_spawn);
}
  public 
Event_player_spawn(Handle:menuMenuAction:actionparam1param2)
{
    
/* If an option was selected, tell the client about the item. */
    
if (action == MenuAction_Select)
    {
        new 
String:info[32];
        new 
bool:found GetMenuItem(menuparam2infosizeof(info));
        
PrintToConsole(param1"You selected item: %d (found? %d info: %s)"param2foundinfo);
    }
    
/* If the menu was cancelled, print a message to the server about it. */
    
else if (action == MenuAction_Cancel)
    {
        
PrintToServer("Client %d's menu was cancelled.  Reason: %d"param1param2);
    }
    
/* If the menu has ended, destroy it */
    
else if (action == MenuAction_End)
    {
        
CloseHandle(menu);
    }
}
 
public 
Action:Menu_Test1(clientargs)
{
    new 
Handle:menu CreateMenu(MenuHandler1);
    
SetMenuTitle(menu"Do you like apples?");
    
AddMenuItem(menu"yes""Yes");
    
AddMenuItem(menu"no""No");
    
SetMenuExitButton(menufalse);
    
DisplayMenu(menuclient20);
 
    return 
Plugin_Handled;

Hm, as I said I'm really new. Any Idea how to make this work ?
1.You have to compile this or try to and give us the errors
2.You have no menuhandler
3.the event's callback parameters are so wrong
miniman is offline
FoxMulder
Senior Member
Join Date: Jan 2009
Location: Orlando, FL
Old 03-03-2011 , 06:36   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #9

This is based on what you have so far. Though the problems with such code is that it'll show it every time the player spawns. You would also need a variable that determines if a player should see the menu, true if they are just connecting and false once they've seen it.

Consider using:
OnClientAuthorized: http://docs.sourcemod.net/api/index....d=show&id=394&

PHP Code:
//Colorful_Peace http://steamcommunity.com/id/colorfulpeace

//Includes:

#include <sourcemod>
#pragma semicolon 1

// Info:

public Plugin:myinfo =
{
    
name "n/a",
    
author "Colorful Peace",
    
description "n/a",
    
version "1.0.0.0",
    
url "N/A"
}


  public 
OnPluginStart()
{
  
HookEvent("player_spawn"Event_player_spawn);
}
  public 
Event_player_spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
    
showMenu(client);
}

public 
Action:showMenu(client)
{    
    new 
Handle:menu CreateMenuEx(GetMenuStyleHandle(MenuStyle_Radio), MenuHandler1);
    
    
SetMenuTitle(menu"Do you like apples?");
    
AddMenuItem(menu"yes""Yes");
    
AddMenuItem(menu"no""No");
    
SetMenuExitButton(menufalse);
    
DisplayMenu(menuclient20);
}

public 
MenuHandler1(Handle:menuMenuAction:actionparam1param2)
{
    switch (
action
    {
        case 
MenuAction_Select
        {
            new 
String:info[32];
            new 
bool:found GetMenuItem(menuparam2infosizeof(info));
            
PrintToConsole(param1"You selected item: %d (found? %d info: %s)"param2foundinfo);
        }
        
        case 
MenuAction_Cancel:
        {
            
PrintToServer("Client %d's menu was cancelled.  Reason: %d"param1param2);
        }
        
        case 
MenuAction_End:
        {
            
CloseHandle(menu);
        }
    }

__________________
FoxMulder is offline
weaponmen
Member
Join Date: Jun 2009
Old 03-03-2011 , 08:30   Re: Bring a sourcemod Menu API automaticly when a player join the server ?
Reply With Quote #10

Thanks for all the help I really appreciate !! +1
__________________

weaponmen 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 04:13.


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