Raised This Month: $ Target: $400
 0% 

Making a plugin tutorial?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bakuryu
Member
Join Date: Dec 2011
Old 12-19-2011 , 12:40   Making a plugin tutorial?
Reply With Quote #1

I'm looking to make a plugin for L4D and L4D2 is there any tutorials on how to get started? I know entry level C++ I don't know if that's enough I'm kinda rusty XD
Bakuryu is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 12-19-2011 , 13:58   Re: Making a plugin tutorial?
Reply With Quote #2

Have fun: http://wiki.alliedmods.net/Category:SourceMod_Scripting
When you've done enough, look at other L4D(2) plugins to get an idea of some of the things you can do.
__________________
pheadxdll is offline
Bakuryu
Member
Join Date: Dec 2011
Old 12-19-2011 , 23:36   Re: Making a plugin tutorial?
Reply With Quote #3

Thank you for the tutorials it seems my C++ knowledge will transfer a little. The tutorial is still a little confusing or im just really rusty. for exmaple in

public Action:Command_Slap(client, arges) are these two parameters or what? If so where are they getting them from because the next part gets the arguments which maybe I'm confused between those, but its looking for the username and the amount of damage which is 2 arguments, but it does this by checking the parameter of arges which is 0 at this point isn't it? It makes sense to check for another argument because if its just sm_playerslap Bakuryu it slaps them for no damage, but if its 1 it still technically isn't passing the if statement as both arges needs to be >= 2 and the second argument needs to work. Also there seems to be a ton of variables that aren't declared anywhere maybe I'm missing something, but where did MAX_TARGET_LENGTH come from? Is this a keyword?

To start mine off I want to make some text and a menu pop up for the user I am assuming I need to make use of the menu functions, I'm just not sure which ones any examples of a simple menu system?
Bakuryu is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-20-2011 , 09:20   Re: Making a plugin tutorial?
Reply With Quote #4

Command_Slap is the callback for the command sm_slap, when a client invokes the command through chat/console his/her client id is passed to client and args contains the number of arguments he/she passed. The Command_Slap code block is then run to see what actions should happen. The arguments he/she passed can be retrieved in the form of a string with GetCmdArg. MAX_TARGET_LENGTH is defined in one of the includes the plugin has used to compile. If you look at sourcemod.inc you'll see that it includes other includes, this just creates a large tree of includes. There are many things that are defined with simply including sourcemod.inc. Some examples: NULL_VECTOR PLATFORM_MAX_PATH MAX_NAME_LENGTH
If you simply want to print stuff to the client, look at the various PrintTo... functions in the api.
Api here
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
Bakuryu
Member
Join Date: Dec 2011
Old 12-20-2011 , 12:11   Re: Making a plugin tutorial?
Reply With Quote #5

Ok that definitely makes a little more sense. Is client and arge a keyword though? alone with MAX_TARGET_LENGTH if so is there a list of these words what they are used for etc? Also won't the PrintTo functions only send texts? how do you make them menus? Shouldn't I look at the Menu functions?
Bakuryu is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-20-2011 , 13:19   Re: Making a plugin tutorial?
Reply With Quote #6

Every bold section in the api is an include file that sourcemod.inc includes in itself, with the exception of sdktools and its subsections. Clicking on a bold section will give you the overview of what that include file creates for use within your plugin, usually these are enums and #define variables. I assume you know how different tag types work and how functions return certain tag variables, if so go ahead and try creating a menu/panel by looking at the menus section in the api.
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
Bakuryu
Member
Join Date: Dec 2011
Old 12-20-2011 , 22:52   Re: Making a plugin tutorial?
Reply With Quote #7

Yea I just found the menu section, but its throwing me for a loop. The flow of the code is really weird if I am reading it right. On start it calls the function at the bottom of the code which is weird why do they have the function below what happens next? It generates a menu and then calls a function on how that menu works right? so if each of these pieces of code were assigned a number from top to bottom as 1, 2 and 3 it makes it seem like the order in which its executed is 1, 3, 2 unless I am not reading it right, even though this technically doesn't matter its still confusing to read.

On top of that I'm trying to figure out how to make this menu pop up as soon as the client enters the server, so far I had no luck removing the register command line and inserting the code for creating the menu in its place. Not that I thought this would work, but it was wishful thinking.
Bakuryu is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-21-2011 , 13:11   Re: Making a plugin tutorial?
Reply With Quote #8

This should work to display a menu when a client gets put in server.
PHP Code:
public OnClientPutInServer(client)
{
    
BuildMyMenu(client);
}

BuildMyMenu(client)
{
    new 
Handle:menu CreateMenu(MyMenuHandler);
    
AddMenuItem(menu"mWelcome""Welcome");
    
SetMenuTitle(menu"My Menu");
    
SetMenuExitButton(menutrue);
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}

public 
MyMenuHandler(Handle:menuMenuAction:actionparam1param2)
{
    switch(
action)
    {
        case 
MenuAction_End:
        {
            
CloseHandle(menu);
        }
        case 
MenuAction_Cancel:
        {
            if (
param2 == MenuCancel_ExitBack)
            {
                
//if your menu has a back button display the previous menu here.
            
}
        }    
        case 
MenuAction_Select:
        {
            new 
String:item1[56];
            
GetMenuItem(menuparam2item1sizeof(item1));
            if(
StrEqual(item1"mWelcome"))
            {
                
//run actions when they select this.
            
}
            
//run actions here if you want something to run regardless of what they select.
        
}
    }

__________________

Last edited by McFlurry; 12-21-2011 at 21:16.
McFlurry is offline
Send a message via Skype™ to McFlurry
Bakuryu
Member
Join Date: Dec 2011
Old 12-22-2011 , 11:27   Re: Making a plugin tutorial?
Reply With Quote #9

I don't know if its my code or the compiler, but it won't let me try my code so maybe I made a big enough booboo to make the compiler crash here is my code. Based heavily on your example of course. I used if statements instead of case, not sure if that makes a difference or not I mirrored it as close as possible to the case version.

PHP Code:
    public OnPluginStart()
{

}
 
    public 
OnClientPutInServer(client)
    {
        
Mainmenu(client);
    }
    
    
Mainmenu(client)
    {
        new 
Handle:menu CreateMenu(MainMenuHandler)
        
AddMenuItem(Handle:menu"chooseclass""Choose Class");
        
AddMenuItem(Handle:menu"classinfo""Class Info");
        
SetMenuTitle(Handle:menu"Dead Fortress Menu");
        
DisplayMenu(Handle:menuclientMENU_TIME_FOREVER);
    }
    
    public 
MainMenuHandler(Handle:menuMenuAction:actionparam1param2)
    {
        if (
action == MenuAction_End)
        {
            
CloseHandle(menu);
        }
        else if (
action == MenuAction_Cancel)
        {
            if (
param2 == MenuCancel_ExitBack)
            {
            }
        }
        else if (
action == MenuAction_Select)
        {
            new 
String:item1[56];
            
GetMenuItem(Handle:menu,param2,item1,sizeof(item1));
            if (
StrEqual,item1,"chooseclass"))
            {
                
PrintToChat(client,"You picked  %d",item1);
            }
            else if (
StrEqual,item1,"classinfo"))
            {
                
PrintToChat(client,"You picked  %d",item1);
            }
        }
    } 

Last edited by Bakuryu; 12-22-2011 at 11:28.
Bakuryu is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 12-22-2011 , 11:41   Re: Making a plugin tutorial?
Reply With Quote #10

PHP Code:
if (StrEqual,item1,"chooseclass"))
{
    
PrintToChat(client,"You picked  %d",item1);

%d is used to mark integers, item1 is a string and nothing more. It seems what you want to do here is open a sub menu and list the class choices for the client to use. Example:
PHP Code:
if (StrEqual,item1,"chooseclass"))
{
    
BuildClassMenu(client); //create another menu with a back button
    //also on MenuCancel_ExitBack build the clients previous menu.

__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
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 21:52.


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