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

Knife Deathmatch Shop


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Gameplay       
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 05-07-2015 , 02:52   Knife Deathmatch Shop
Reply With Quote #1

Knife Deathmatch Shop
- last update: 13.05.2015 - latest version: 3.4

Introduction
A Shop that designed for Knife Server owners to make their players' gameplay different.
Players can purchase interesting items for spending their Frags. More frags means better items they can purchase.
Here's the list of currently supported items:
  1. Glow
  2. Extra Health
  3. Hook (Needs Hook plugin)
  4. Speed
  5. GodMode
Requirements
  • AMX Mod 1.8.3 (latest development version)
  • Hook plugin (for hook item working)
Credits
  • xEhsaan - Idea & Coding
  • MohaMMadReZa - Testing & Coding Advisor
  • The.Mahdi.Hero - Persian translation
  • Jujitosis - Spanish translation
  • Pars-Strike guys - Testing
  • Kia & HamletEagle & Jhob94 - Coding advises and useful snippets

Compile Notes
If you want use this plugin in AMX Mod 1.8.2 or lower, you have to compile the plugin yourself, before compile, add this to plugin header:
PHP Code:
#define MAX_PLAYERS 32
#include <colorchat> 
Colorchat module is Required
Console Commands
  • amx_setfrags (Level C): Set given score to selected player or team.
  • amx_addfrags (Level C): Adds given scores to user current scores.
  • amx_expire_bonus (Level C): Expire player bonus timers manually.
CVars
  • dmb_tag: Prefix for all client chat messages (Default: DM Shop)
  • dmb_glow_price: Glow cost (Default: 50)
  • dmb_glow_time: Time limit for Glow item (Default: 60)
  • dmb_hp_price: Extra Health cost (Default: 100)
  • dmb_hp_value: Extra health value (Default: 200)
  • dmb_hook_price: Hook cost (Default: 150)
  • dmb_hook_time: Time limit for hooking (Default: 60)
  • dmb_godmode_price: GodMode activation cost (Default: 200)
  • dmb_godmode_time: Time limit for GodMode deactivation (Default: 60)

Supported Languages
  • English (me)
  • Persian (The.Mahdi.Hero)
  • Spanish (Jujitosis)

Changelog
  • Version 3.4:
    • + Multi-Language Support
    • + dmb_version Public CVar
    • * Fixed a bug when a client disconnects, server still tries to disable his timer, but it couldn't.
    • * Replaced MAX_PLAYERS with hard-coded values constants.
    • Fixed GodMode bug
  • Version 3.3:
    • * Optimized a lot
    • * Removed Persian lines

Installation
  • Attention: "Get Plugin" doesn't work, You MUST compile the plugin locally using LATEST DEVELOPMENT VERSION of AMX Mod X

Found a bug?
Please feel free to post the bugs here, I'll see it and fix it ;)
I welcome useful snippets and anything makes the coding or performance better.
Attached Files
File Type: sma Get Plugin or Get Source (knife_dm_shop.sma - 1069 views - 22.7 KB)
File Type: txt knife_dm_shop.txt (4.3 KB, 331 views)
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...

Last edited by xEhsaan; 05-13-2015 at 08:12. Reason: Updated to Version 3.4
xEhsaan is offline
Send a message via Skype™ to xEhsaan
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-07-2015 , 03:46   Re: Knife Deathmatch Shop
Reply With Quote #2

Hola.
  • Do not use CurWeapon Event to re-set the speed, use Ham_Player_ResetMaxSpeed.
  • When you format the items in Shop_Menu do the iFrags >= iPrice once and save that in a bool instead of doing three times.
  • You may want to save the CVars in an array so you can loop them instead of doing the same thing for each item again and again.
  • Same applies for the Menu_Callback, you could put that in an array too.
  • Line 278 is not translated to english.
  • Glow Menu could also be handled with an array.
  • So for most of your handlers.
__________________
Kia is offline
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 05-07-2015 , 03:50   Re: Knife Deathmatch Shop
Reply With Quote #3

Thanks for your great advises, Kia. I'll apply them as soon as possible.
But, would you explain your second advise? I couldn't understand it.

I'll thank you if you say what do you think about the idea and its effect on gameplay.

(P.S.: I think you know Persian or you or your parents are Iranian, is it true? 'cause your name is like the names in Iran. ;))
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...
xEhsaan is offline
Send a message via Skype™ to xEhsaan
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Location: Siiiiiiiiuu
Old 05-07-2015 , 04:08   Re: Knife Deathmatch Shop
Reply With Quote #4

"After purchasing, it'll take 1 - 2 seconds to activate the item
Plugin will crash if you enter a negative value for HP Value"
First, why not instantly?
Second, check the value and if is negative return. Makes no sense to use a plugin that can crash the server lol
__________________
Jhob94 is offline
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 05-07-2015 , 04:22   Re: Knife Deathmatch Shop
Reply With Quote #5

I need some help...

1. Should I hook a function to Ham_Player_ResetMaxSpeed or just call it?
2. Fixed
3. You mean sth like this? :
PHP Code:
public Init_Vars() {
    
get_pcvar_stringg_pTagg_Tag63 );
    
    
// Glow
    
g_Items[0][0] = get_pcvar_numg_pGlowPrice );
    
g_Items[0][1] = get_pcvar_numg_pGlowTime );
    
    
// HP
    
g_Items[1][0] = get_pcvar_numg_pHPPrice );
    
g_Items[1][1] = get_pcvar_numg_pHPValue );
    
    
// Speed
    
g_Items[2][0] = get_pcvar_numg_pSpeedPrice );
    
g_Items[2][1] = get_pcvar_numg_pSpeedTime );
    
    
// Hook
    
g_Items[3][0] = get_pcvar_numg_pHookPrice );
    
g_Items[3][1] = get_pcvar_numg_pHookTime );
    
    
// GodMode
    
g_Items[4][0] = get_pcvar_numg_pGodModePrice );
    
g_Items[4][1] = get_pcvar_numg_pGodModeTime );

4 & 6 & 7: You mean I handle them with g_Items I created?

Thank you.
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...
xEhsaan is offline
Send a message via Skype™ to xEhsaan
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 05-07-2015 , 04:27   Re: Knife Deathmatch Shop
Reply With Quote #6

Quote:
Originally Posted by Jhob94 View Post
"After purchasing, it'll take 1 - 2 seconds to activate the item
Plugin will crash if you enter a negative value for HP Value"
First, why not instantly?
Second, check the value and if is negative return. Makes no sense to use a plugin that can crash the server lol
1. Fixed that already, I didn't remember that, what a forgetful I am
2. LOL, I knew that, but Mmm. I will reupload it when I apply major changes. Anyway it doesn't crash the server itself, it will be crashed if plugin misconfigured.

Thanks anyway.
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...

Last edited by xEhsaan; 05-07-2015 at 04:28.
xEhsaan is offline
Send a message via Skype™ to xEhsaan
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-07-2015 , 10:07   Re: Knife Deathmatch Shop
Reply With Quote #7

Quote:
Speed is different on AMX Mod X versions. You must change it yourself
Never heard of something like this. I know a bug with speed caused by sv_maxspeed cvar(on furien server, maybe it's the case here too). To fix it, just set this cvar to a higher value like 9999 inside your plugin.

PHP Code:
public Init_Vars() { 
Not everything need public in front of it. It is needed for stuffs that can be called from other plugins/modules(forwards, the handler of a menu, a task, etc). You should avoid public if you call stuffs directly in your plugin(it will become a private function - is accessible only inside current plugin). Another thing is that you initialize only one variable, making a function only for that is silly. Just put it inside plugin_init, and please don't hardcode strings size, use charsmax()(can be done with sizeof -1 too, but it is the same thing, peoples prefer the first one for readability) to get it.

PHP Code:
set_task60.0"Advertise_DM" ); 
This is not going to work correctly. Maybe after one minute no one is connected to server yet and they won't see your message, IMO you should display it at spawn.

Reseting variables in both client_disconnect and client_connect is not needed. It is enough to do it only one time during client_disconnect.
Kia was talking about iFrags >= iPrice. You can save expression value(true/false) inside a boolean and check it inside formatex. From my point of view this is not very important, it may help on readability, but nothing more.
Initializing iTime variable is not needed, cause you use it only one time, you can write the native directly.

Also, for menu items an array would be better :crab
Info param from menu_additem is not used, so you can remove menu_item_getinfo and work directly with item.
Also, instead of checking item name, why you don't do a [tt]switch(item)[/t] ?
Returning PLUGIN_HANDLED inside menu callback and inside the public where creating the menu is not needed.

PHP Code:
new g_Menu;
    
g_Menu menu_create"\yRang Ra Entekhab Konid:""Glow_Menu_Handler" );
    
    
menu_additemg_Menu"Red""1" );
    
menu_additemg_Menu"Green""2" );
    
menu_additemg_Menu"Blue""3" );
    
menu_additemg_Menu"Purple""4" );
    
menu_additemg_Menu"Cyan""5" );
    
menu_additemg_Menu"Yellow""6" );
    
menu_additemg_Menu"Black""7" );
    
menu_additemg_Menu"White""8" );
    
menu_additemg_Menu"Random""9" ); 
This menu is not dynamic, so you can create it only one time in plugin_init and make g_Menu global, so you can acces your menu later.
Cache the return value of get_user_msgid.

This are just some stuffs, didn't read all your code.
__________________
HamletEagle is offline
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 05-07-2015 , 12:42   Re: Knife Deathmatch Shop
Reply With Quote #8

Thank you really much Hamlet. This gave me a lot of code optimization guides. I never thought that someone ever would help me in this amount. (You don't know, my country, Iran is just ... never mind)

But, I didn't understand the last part of your post:
Quote:
Originally Posted by HamletEagle View Post
This menu is not dynamic, so you can create it only one time in plugin_init and make g_Menu global, so you can acces your menu later.
Cache the return value of get_user_msgid.
get_user_msgid? I don't know what do you mean. Would you please give me an example or explain how this function works?

Thank you again so much
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...
xEhsaan is offline
Send a message via Skype™ to xEhsaan
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-07-2015 , 13:32   Re: Knife Deathmatch Shop
Reply With Quote #9

PHP Code:
message_begin(MSG_ONEget_user_msgid("ScreenFade"), {0,0,0}, id);
    
write_short(1<<12);
    
write_short(1<<10);
    
write_short(1<<12);
    
write_byte(iRed);
    
write_byte(iGreen);
    
write_byte(iBlue);
    
write_byte(50);
    
message_end(); 
You use it several times inside your plugin. Instead of copy-pasting code without understanding, you should search for every native that you get from other plugins and see what it does.
__________________
HamletEagle is offline
xEhsaan
Member
Join Date: Mar 2015
Location: Isfahan, Iran
Old 05-07-2015 , 16:14   Re: Knife Deathmatch Shop
Reply With Quote #10

Updated to version 3.3
I tried to do everything you guys said and plugin optimized 1.5x (Thank you for your great advises)

Please test newer version and tell me what do you think about The Idea and Plugin performance.

Thanks.
__________________
* Wait for something awesome...
* AMX Mod X Plugin Translation Repository [Paused Temporarily]
* Knife Deathmatch Shop
* Knife CFG Detector
* Looking for an idea...
xEhsaan is offline
Send a message via Skype™ to xEhsaan
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 17:55.


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