AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   buy an m4 (https://forums.alliedmods.net/showthread.php?t=74854)

{PHILMAGROIN} 07-26-2008 04:36

buy an m4
 
This is my first plugin ever made without any help other than looking at other code. Im posting it for people to tell me what i did wrong, what i can do better,to critisize me:up:, or use? probably another plugin out there like this but whatever. So here it is
Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> #define PLUGIN "Buy_m4" #define VERSION "1.0" #define AUTHOR "{PHILMAGROIN}" new m4_cost public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_concmd("say /m4", "buym4")     m4_cost = register_cvar("m4_price", "800") } public buym4(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED                 new money = cs_get_user_money(id);         new cost;                 cost = get_pcvar_num(m4_cost)                 if(money < cost)         {             client_print(id, print_chat,"[AMXX] You dont't have enough money for an m4.")         }         else {             cs_set_user_money(id, cs_get_user_money(id) - cost);             {                 client_print(id, print_chat,"[AMXX] Kill Em with your new m4.")                 give_item(id, "weapon_m4a1");             }         return 1;     } }

Exolent[jNr] 07-26-2008 05:21

Re: buy an m4
 
Code:
        new cost;                 cost = get_pcvar_num(m4_cost)

No need for more than 1 line

Code:
new cost = get_pcvar_num(m4_cost)
---------------------------------
Code:
cs_set_user_money(id, cs_get_user_money(id) - cost);
You already have the player's money stored in "money"
Code:
cs_set_user_money(id, money - cost);
---------------------------------
Code:
        else {             cs_set_user_money(id, money - cost);             {                 client_print(id, print_chat,"[AMXX] Kill Em with your new m4.")                 give_item(id, "weapon_m4a1");             }         return 1;
You messed up your brackets
Code:
        else {             cs_set_user_money(id, money - cost);             client_print(id, print_chat,"[AMXX] Kill Em with your new m4.")             give_item(id, "weapon_m4a1");         }     return 1;
----------------------------------
Final:
Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> #define PLUGIN "Buy_m4" #define VERSION "1.0" #define AUTHOR "{PHILMAGROIN}" new m4_cost public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_concmd("say /m4", "buym4")     m4_cost = register_cvar("m4_price", "800") } public buym4(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED         new money = cs_get_user_money(id);     new cost cost = get_pcvar_num(m4_cost)         if(money < cost)     {         client_print(id, print_chat,"[AMXX] You dont't have enough money for an m4.")     }     else {         cs_set_user_money(id, money - cost);         client_print(id, print_chat,"[AMXX] Kill Em with your new m4.")         give_item(id, "weapon_m4a1");     }     return PLUGIN_HANDLED; }

{PHILMAGROIN} 07-26-2008 06:10

Re: buy an m4
 
Thanks. i added ability to buy ammo with it.

Code:
// Description: This plugin is mainly for terrorists to be able to buy an m4. Cts can buy one as // well but its the same price as an m4 on the buy menu. // Commands: say /m4 or /m4ammo // Cvars: "m4_price" "m4_aprice" #include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> #define PLUGIN "Buy_m4" #define VERSION "1.1" #define AUTHOR "{PHILMAGROIN}" new m4_cost, m4_ammo; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_clcmd("say /m4", "buym4")     register_clcmd("say /m4ammo", "buym4ammo")     m4_cost = register_cvar("m4_price", "2500")     m4_ammo = register_cvar("m4_aprice", "3000") } public buym4(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED             new money = cs_get_user_money(id);     new cost = get_pcvar_num(m4_cost)             if(money < cost)     {         client_print(id, print_chat,"[AMXX] You don't have enough money for an m4.")     }     else {         cs_set_user_money(id, money - cost);         client_print(id, print_chat,"[AMXX] You just purchased an m4.")              give_item(id,"weapon_m4a1");     }     return PLUGIN_HANDLED } public buym4ammo(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED             new money = cs_get_user_money(id);     new cost = get_pcvar_num(m4_ammo)             if(money < cost)     {         client_print(id, print_chat,"[AMXX] You don't have enough money for an m4 with extra ammo.")     }     else {         cs_set_user_money(id, money - cost);         client_print(id, print_chat,"[AMXX] You just purchased an m4 with extra ammo.")         give_item(id, "weapon_m4a1");         give_item(id, "ammo_556nato");         give_item(id, "ammo_556nato");         give_item(id, "ammo_556nato");     }     return PLUGIN_HANDLED }

Exolent[jNr] 07-26-2008 06:14

Re: buy an m4
 
http://wiki.amxmodx.org/CS_Weapons_Information

To give ammo, you should give the actual ammo.
Quote:

22 weapon_m4a1 230 30 90 4 ammo_556nato 3100 60 m4a1
Code:
give_item(id, "ammo_556nato")

{PHILMAGROIN} 07-26-2008 06:19

Re: buy an m4
 
Thanks.

PvtSmithFSSF 07-26-2008 08:01

Re: buy an m4
 
you should use register_clcmd not register_concmd.
clcmd = you can type it in chat.
concmd = you gotta type it in console..

minimiller 07-26-2008 08:50

Re: buy an m4
 
concmd works aswell, its just that you can execute the cmd from a console
which is a bad idea

PvtSmithFSSF 07-26-2008 09:38

Re: buy an m4
 
So you're saying concmd will also let you type it in chat and it still works?? Sorry if that sounded rude I meant it as a question because you're smarter :D hehe

{PHILMAGROIN} 07-26-2008 11:53

Re: buy an m4
 
ya i actually meant to fix this.

minimiller 07-26-2008 12:04

Re: buy an m4
 
Lol no problem
Yea if you use concmd("say /m4") or clcmd("say /m4") they do the same thing
However the concmd can be executed from a console and the clcmd cannot


All times are GMT -4. The time now is 05:38.

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