Dynamic Items in Menu and Plugin API
Introduction:
I've seen many users ask how to create dynamic classes or items with sub-plugins like in Zombie Plague. This tutorial will teach you just how to do that. This tutorial is not for new users to AMXX scripting! In this tutorial, you will need knowledge of:
For this tutorial, I'm going to use a "shop" for an example. It will show a menu on spawn which contains the items. Integration File (.inc): Let's call it shop.inc: Code:
That code will make sure if included more than once in a single plugin, it won't duplicate its contents. First, you will need a custom library for this. Let's call it "shop" Code:
Next, you will need 2 functions that will integrate your plugins:
If the sub-plugin is going to be an item, then you will need to pass all the information about the item into the function. To keep it simple, we will only need:
So, here is how our function would look. Code:
The function should return a unique item index so it can be separate from other plugins. In the forward when the player selects the item, it will need to pass the player's index and the unique item index. So, here is how the forward would look. Code:
Here is our complete shop.inc file: Code:
Main Plugin: I commented the plugin very well. If you have knowledge that was listed above, you should be able to understand everything with just the comments. Code:
Sub-Plugin: Code:
Here is how it would be done with specific callback functions. Introduction: I've seen many users ask how to create dynamic classes or items with sub-plugins like in Zombie Plague. This tutorial will teach you just how to do that. This tutorial is not for new users to AMXX scripting! In this tutorial, you will need knowledge of:
For this tutorial, I'm going to use a "shop" for an example. It will show a menu on spawn which contains the items. Integration File (.inc): Let's call it shop.inc: Code:
That code will make sure if included more than once in a single plugin, it won't duplicate its contents. First, you will need a custom library for this. Let's call it "shop" Code:
Next, you will need 2 functions that will integrate your plugins:
If the sub-plugin is going to be an item, then you will need to pass all the information about the item into the function. To keep it simple, we will only need:
So, here is how our function would look. Code:
The function should uses a callback handler so it can be separate from other plugins. Here is our complete shop.inc file: Code:
Main Plugin: I commented the plugin very well. If you have knowledge that was listed above, you should be able to understand everything with just the comments. Code:
Sub-Plugin: Code:
___________________________ Last Notes: Don't post here asking how to fix your mod. Feel free to post if you don't understand something about this or if you have suggestions to better this information. |
Re: Dynamic Items in Menu and Plugin API
Nice! A guy requested me this last week, but I haven't got time to do this, so thank you Exolent.
|
Re: Dynamic Items in Menu and Plugin API
I'm glad you find it useful. :)
|
Re: Dynamic Items in Menu and Plugin API
Nice :up:
|
Re: Dynamic Items in Menu and Plugin API
I had a few people ask me how this type of thing would work (natives to interact with the base plugin) and they were using ZP as an example, which confused them. A lot. This is certainly a better example.
Awesome job. :lol: |
Re: Dynamic Items in Menu and Plugin API
Coool i needed this for my ZP New Modes
|
Re: Dynamic Items in Menu and Plugin API
@Exolent
How about making specific forwards for each menu item? Code:
|
Re: Dynamic Items in Menu and Plugin API
Quote:
I can add more features to this like what you're suggesting, but people can figure those features out themselves. They normally have problems just figuring out how to do this basic API. |
Re: Dynamic Items in Menu and Plugin API
Quote:
|
Re: Dynamic Items in Menu and Plugin API
nice tutorial.
I just don't understand the #pragma thing. And don't we include the shop in the plugin? Can you explain that? |
Re: Dynamic Items in Menu and Plugin API
Quote:
Quote:
The main plugin doesn't require the API to work, so you don't include it. EDIT: Added specific callback function example. |
Re: Dynamic Items in Menu and Plugin API
this may sound noobish, but can you define API?
|
Re: Dynamic Items in Menu and Plugin API
Quote:
|
Re: Dynamic Items in Menu and Plugin API
tnx
|
Re: Dynamic Items in Menu and Plugin API
If menu got 3 pages, on 1st and 2nd page key 9 will be more, and key 0 exit on 1st page, and on 2nd page 0 will be back? Know what I mean?
And if my line to format szItem is that: Code:
formatex( szItem, charsmax( szItem ), "%s", serwer[i] ); Code:
new key = str_to_num(szNum); |
Re: Dynamic Items in Menu and Plugin API
Pages:
About your second question; yes, that'd work if you were able to manually have clients connect like that, but I'm pretty sure Valve patched that. Not sure, though. |
Re: Dynamic Items in Menu and Plugin API
Quote:
EDIT: Oh and Exolent.. this clears a few things up for me. Thanks. :D |
Re: Dynamic Items in Menu and Plugin API
Thank You Very Much. Ive been waiting :D
|
Re: Dynamic Items in Menu and Plugin API
Thanks, I make some similar in Kz-Arg.
|
Re: Dynamic Items in Menu and Plugin API
Quote:
|
Re: Dynamic Items in Menu and Plugin API
Great tutorial. Thanks.
|
Re: Dynamic Items in Menu and Plugin API
Exolent, you repeated the tutorial 2 times.
Btw, nice job. |
Re: Dynamic Items in Menu and Plugin API
Quote:
Quote:
|
Re: Dynamic Items in Menu and Plugin API
Quote:
It will connect with g_ip[19] according to my second question? |
Re: Dynamic Items in Menu and Plugin API
Array indices begin at 0. So if you pick 7, you should get g_serwer[6]. It all depends on your for loop. If you're starting from 1, you won't get the first server from the array.
|
Re: Dynamic Items in Menu and Plugin API
Anyway, if there is on third page 7. g_serwer[18]
and I'll make new key = str_to_num(szNum) and use g_ip[key] key will be = 18? |
Re: Dynamic Items in Menu and Plugin API
What? If you want the key to correspond with the server indice, just do client_cmd( id, "Connect %s", serwer[key-1] )
|
Re: Dynamic Items in Menu and Plugin API
But it will be working fine on page higher than one? I'm not sure if szKey is number which someone pressed, or number of item in menu(including or not including 9. Back and 0. Exit)
|
Re: Dynamic Items in Menu and Plugin API
Don't worry about the back and next items, they don't count when you get the data (menu_item_getinfo), so your key will be the same as what you added in the menu_additem.
|
Re: Dynamic Items in Menu and Plugin API
You are getting off topic. Make another thread in Scripting Help.
|
Re: Dynamic Items in Menu and Plugin API
Quote:
And thanks for this tutorial anyway :) Good job ;] |
Re: Dynamic Items in Menu and Plugin API
Quote:
In the tutorial linked for the new menu system, it tells you all you need to know. |
Re: Dynamic Items in Menu and Plugin API
Yup, but there also it isn't pointed ;]
|
Re: Dynamic Items in Menu and Plugin API
Quote:
To the shop.inc, then to shophandler.sma and made a sub plugin, and then it writes they cant find shop_add_item at the include file.(well they dont write that they cant find it there, but compiler wont find the function iteself... :| |
Re: Dynamic Items in Menu and Plugin API
Quote:
|
Re: Dynamic Items in Menu and Plugin API
Check your post for lots of problems, hope you'll find it useful.
|
Re: Dynamic Items in Menu and Plugin API
Quote:
I had defined the function as shop_item_add() but in the sub-plugin it called shop_add_item(). There are no more errors now. |
Re: Dynamic Items in Menu and Plugin API
Quote:
shop_item_add("Low Gravity", 2000, "ShopLowGravity" ); public ShowLowGravity( iPlayer ) :arrow: shop_item_add("Low Gravity", 2000, "ShopLowGravity" ); public ShopLowGravity( iPlayer ) |
Re: Dynamic Items in Menu and Plugin API
Quote:
I thought 2's company. |
Re: Dynamic Items in Menu and Plugin API
Quote:
Quote:
Quote:
|
All times are GMT -4. The time now is 16:22. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.