Raised This Month: $ Target: $400
 0% 

Making a plugin tutorial?


Post New Thread Reply   
 
Thread Tools Display Modes
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 12-22-2011 , 12:41   Re: Making a plugin tutorial?
Reply With Quote #11

Quote:
Originally Posted by Bakuryu View Post
PHP Code:
new Handle:menu CreateMenu(MainMenuHandler)
AddMenuItem(Handle:menu"chooseclass""Choose Class");
    
if (
StrEqual,item1,"chooseclass")) 
haven't checked the logic, but your syntax is a bit off:
  • No need to change to Handle-tag of menu to Handle again.
    AddMenuItem(menu, "chooseclass", "Choose Class");
    You do that quite often, you might want to read this to understand better what tagging is. Though it is no problem in this specific case, it is still a key concept.
  • StrEqual is missing a (.
    if (StrEqual(item1,"chooseclass"))
__________________
einmal mit profis arbeiten. einmal.
Thrawn2 is offline
Bakuryu
Member
Join Date: Dec 2011
Old 12-22-2011 , 14:02   Re: Making a plugin tutorial?
Reply With Quote #12

Do I have to create a handle for each menu? For example do I have to make a handle so it knows that back means go to the previous menu? does it make a back button by default one of the tutorials put a line to make it not appear. Hmmm trying to build the menu inside the if statement and it says its not defined what am I doing wrong, does it have to be in the OnClientPutInServer as well? wouldn't that make both pop up then?


Edit: Compiler still keeps crashing probably because of all the errors.

PHP Code:
    public OnClientPutInServer(client)
    {
        
BuildMainmenu(client);
    }
    
    
BuildMainmenu(client)
    {
        new 
Handle:menu CreateMenu(MainMenuHandler)
        
AddMenuItem(menu"chooseclass""Choose Class");
        
AddMenuItem(menu"classinfo""Class Info");
        
SetMenuTitle(menu"Dead Fortress Menu");
        
DisplayMenu(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(menu,param2,item1,sizeof(item1));
            if (
StrEqual(item1,"chooseclass"))
            {
                
BuildClassMenu(client); //create another menu with a back button
                //also on MenuCancel_ExitBack build the clients previous menu.
                
                
BuildClassMenu(client);
                {
                    new 
Handle:classmenu CreateMenu(ClassMenuHandler)
                    
AddMenuItem(classmenu,"soldier","Soldier");
                    
AddMenuItem(classmenu,"scout","Scout");
                    
AddMenuItem(classmenu,"pyro","Pyro");
                    
AddMenuItem(classmenu,"demoman","Demoman");
                    
AddMenuItem(classmenu,"heavy","Heavy");
                    
AddMenuItem(classmenu,"sniper","Sniper");
                    
AddMenuItem(classmenu,"spy","Spy");
                    
AddMenuItem(classmenu,"engineer","Engineer");
                    
AddMenuItem(classmenu,"medic","Medic");
                    
AddMenuItem(classmenu,"back","Back");
                    
SetMenuTitle(classmenu,"Dead Fortress Class Menu");
                    
DisplayMenu(classmenuclientMENU_TIME_FOREVER);
                }
            
            else if (
StrEqual,item1,"classinfo"))
            {
                
BuildClassInfoMenu(client); //create another menu with a back button
                //also on MenuCancel_ExitBack build the clients previous menu.
                
                
BuildClassInfoMenu(client)
                {
                    new 
Handle:classinfo CreateMenu(ClassInfoMenuHandler)
                    
AddMenuItem(classinfo,"soldier","Soldier");
                    
AddMenuItem(classinfo,"scout","Scout");
                    
AddMenuItem(classinfo,"pyro","Pyro");
                    
AddMenuItem(classinfo,"demoman","Demoman");
                    
AddMenuItem(classinfo,"heavy","Heavy");
                    
AddMenuItem(classinfo,"sniper","Sniper")'
                    AddMenuItem(classinfo,"spy","Spy");
                    AddMenuItem(classinfo,"engineer","Engineer");
                    AddMenuItem(classinfo,"medic","Medic");
                    AddMenuItem(classinfo,"back","Back");
                    SetMenuTitle(classinfo,"Dead Fortress Class Menu");
                    DisplayMenu(classinfo, client, MENU_TIME_FOREVER);
                }
            }
        }
    } 

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

PHP Code:
                BuildClassMenu(client);
                {
                    new 
Handle:classmenu CreateMenu(ClassMenuHandler)
                    
AddMenuItem(classmenu,"soldier","Soldier");
                    
AddMenuItem(classmenu,"scout","Scout");
                    
AddMenuItem(classmenu,"pyro","Pyro");
                    
AddMenuItem(classmenu,"demoman","Demoman");
                    
AddMenuItem(classmenu,"heavy","Heavy");
                    
AddMenuItem(classmenu,"sniper","Sniper");
                    
AddMenuItem(classmenu,"spy","Spy");
                    
AddMenuItem(classmenu,"engineer","Engineer");
                    
AddMenuItem(classmenu,"medic","Medic");
                    
AddMenuItem(classmenu,"back","Back");
                    
SetMenuTitle(classmenu,"Dead Fortress Class Menu");
                    
DisplayMenu(classmenuclientMENU_TIME_FOREVER);
                } 
You're trying to put a function within a function. That's not possible. Also the ; at the end of BuildClassMenu(client) shouldn't be there. ; shouldn't be used when defining a function. Place the functions you have within the handler into the global scope.
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
Bakuryu
Member
Join Date: Dec 2011
Old 12-22-2011 , 21:28   Re: Making a plugin tutorial?
Reply With Quote #14

Edit: Figured it out turns out param1=client and I just named it wrong because I blindly copied examples, in my defines I have no idea sometimes what a variable.

I need to figure out how to make the back button work right now it just exits. Other then that i need to start making these menu's do things. Through chatting on IRC I have come to learn I need to use Hooks to make the the item I select actually do something with the player. For example right now I have it so it can do something when Soldier is hit. Right now these are what I want it to do: give 2 guns, multiple pipe bombs(not even sure this is possible I'm thinking maybe have a counter for how many had has that goes down, but gives him one till it reaches zero, not sure how refills are gonna work yet, but it could just reset the counter to its original position and give one.)fry pan (l4d2,pistol for l4d1). I have no idea where to start with this part, but thats why I'm just focusing on one class for right now and making sure I understand everything. I also need to strip the levels of pick up items except ammo, I know theres a stripper mod, but I don't know how picky you can be and if it even works on l4d/2/weapons.

Thank you btw for everyone who posted on here's help and anyone who helped in IRC, I know I'm a noob and this is probably way over me, but I really wanna do it and it something I've been wanting to do for a while. Although I didn't know I'd have to write a plugin to do it, though maybe just maybe I could use L4D sdk tools :\.

Recent Code:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
public Plugin:myinfo =
{
    
name "Dead Fortress",
    
author "Bakuryu",
    
description "Team Fortress Meets Left 4 Dead",
    
version "0.0.0.1",
    
url "http://www.sourcemod.net/"
}

    public 
OnPluginStart()
{

}
 
    public 
OnClientPutInServer(client)
    {
        
BuildMainmenu(client);
    }
    
    
BuildMainmenu(client)
    {
        new 
Handle:menu CreateMenu(MainMenuHandler);
        
AddMenuItem(menu"chooseclass""Choose Class");
        
AddMenuItem(menu"classinfo""Class Info");
        
SetMenuTitle(menu"Dead Fortress Menu");
        
DisplayMenu(menuclientMENU_TIME_FOREVER);
    }
    
    public 
MainMenuHandler(Handle:menu,MenuAction:actionclientparam2)
    {
        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(menu,param2,item1,sizeof(item1));
            if (
StrEqual(item1,"chooseclass"))
            {
              
BuildClassMenu(client); //create another menu with a back button
                //also on MenuCancel_ExitBack build the clients previous menu. 
            
}
                else if (
StrEqual(item1,"classinfo"))
            {
                
BuildClassInfoMenu(client); //create another menu with a back button
                //also on MenuCancel_ExitBack build the clients previous menu.
            
}
        }
    }  
    
BuildClassMenu(client)
     {
        new 
Handle:classmenu CreateMenu(ClassMenuHandler);
        
AddMenuItem(classmenu,"soldier","Soldier");
        
AddMenuItem(classmenu,"scout","Scout");
        
AddMenuItem(classmenu,"pyro","Pyro");
        
AddMenuItem(classmenu,"demoman","Demoman");
        
AddMenuItem(classmenu,"heavy","Heavy");
        
AddMenuItem(classmenu,"sniper","Sniper");
        
AddMenuItem(classmenu,"spy","Spy");
        
AddMenuItem(classmenu,"engineer","Engineer");
        
AddMenuItem(classmenu,"medic","Medic");
        
AddMenuItem(classmenu,"back","Back");
        
SetMenuTitle(classmenu,"Dead Fortress Class Menu");
        
DisplayMenu(classmenuclientMENU_TIME_FOREVER);
    }
    
    public 
ClassMenuHandler(Handle:classmenu,MenuAction:action,client,param2)
    {
        if (
action == MenuAction_End)
        {
            
CloseHandle(classmenu);
        }
        else if (
action == MenuAction_Cancel)
        {
            if (
param2 == MenuCancel_ExitBack)
            {
            }
        }
        else if (
action == MenuAction_Select)
            {
                new 
String:item1[56];
                
GetMenuItem(classmenu,param2,item1,sizeof(item1));
                if (
StrEqual(item1,"solider"))
                {
                    
CloseHandle(classmenu);
                }
            }
        
    }
        
BuildClassInfoMenu(client)
    {
        new 
Handle:classinfo CreateMenu(ClassInfoMenuHandler)
        
AddMenuItem(classinfo,"soldier","Soldier");
        
AddMenuItem(classinfo,"scout","Scout");
        
AddMenuItem(classinfo,"pyro","Pyro");
        
AddMenuItem(classinfo,"demoman","Demoman");
        
AddMenuItem(classinfo,"heavy","Heavy");
        
AddMenuItem(classinfo,"sniper","Sniper");
        
AddMenuItem(classinfo,"spy","Spy");
        
AddMenuItem(classinfo,"engineer","Engineer");
        
AddMenuItem(classinfo,"medic","Medic");
        
AddMenuItem(classinfo,"back","Back");
        
SetMenuTitle(classinfo,"Dead Fortress Class Menu");
        
DisplayMenu(classinfoclientMENU_TIME_FOREVER);
    }
    
    public 
ClassInfoMenuHandler(Handle:classinfomenu,MenuAction:action,client,param2)
    {
        if (
action == MenuAction_End)
        {
            
CloseHandle(classinfomenu);
        }
        else if (
action == MenuAction_Cancel)
        {
            if (
param2 == MenuCancel_ExitBack)
            {
            }
        }
        else if (
action == MenuAction_Select)
        {
            new 
String:item1[56];
            
GetMenuItem(classinfomenu,param2,item1,sizeof(item1));
            if (
StrEqual(item1,"solider"))
            {
                
CloseHandle(classinfomenu);
            }
        }
    } 

Last edited by Bakuryu; 12-23-2011 at 00:00.
Bakuryu 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 14:49.


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