AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to add DMG to weapon (https://forums.alliedmods.net/showthread.php?t=241659)

DataCore 06-07-2014 08:46

How to add DMG to weapon
 
Hello!

I made a shop for my server and i put there GOLDEN Ak47, if you buy it from shop i want that it has more dmg than other weapons. Who can help, comment and ill pm you the code.

hornet 06-07-2014 09:14

Re: How to add DMG to weapon
 
If you wish to receive any help, then post your code here.

DataCore 06-08-2014 08:20

Re: How to add DMG to weapon
 
Help me please:)


Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <colorchat>
#include <fun>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "Shop"
#define VERSION "1.0"
#define AUTHOR "DataCore"

new const g_szPrefix[] = "^04[SkyNet]^01"

new const g_szYes[] = "Yes/Yes.wav"
new const g_szNo[] = "No/No.wav"

new const View_goldak47[] = "models/shop/v_goldak47.mdl"
new const Player_goldak47[] = "models/shop/p_goldak47.mdl"

new bool:Golden[33]


public plugin_precache()
{
        precache_model(View_goldak47)
        precache_model(Player_goldak47)
}

public plugin_init()
{
                register_plugin(PLUGIN, VERSION, AUTHOR)
               
                register_cvar("server_shop", "1")
               
                RegisterHam(Ham_Spawn, "player", "Spawning", 1)
       
                register_event( "CurWeapon", "WeaponEvent", "be", "1=1")
               
                register_clcmd("say /shop", "Shop");
                register_clcmd("say /pood", "Shop");
                register_clcmd("say /zps", "Shop");
}

public Shop(id)
{
        if(is_user_alive(id))
        {
                ColorChat(id, NORMAL, "%s You are ^4dead^1.", g_szPrefix)
                client_cmd(id, "spk %s", g_szNo)
        }

                if(get_cvar_num("server_shop") == 1)
                {
                        new Shopmenu = menu_create("\rShop", "Shop_handler")
                       
                        menu_additem(Shopmenu, "\wKnives", "1", 0)
                        menu_additem(Shopmenu, "\wSpecial Weapons", "2", 0)
                        menu_additem(Shopmenu, "\wSkins", "3", 0)
                       
                        menu_setprop(Shopmenu, MPROP_EXITNAME, "Exit")
                        menu_display(id, Shopmenu, 0)
                }
}

public Shop_handler(id, menu, item)
{
               
        new data[6], iName[64]
        new access, callback
               
        menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
        new key = str_to_num(data)
        switch(key)
        {
                case 1:
                {
                        ColorChat(id, NORMAL, "%s Sorry! This shop is not ready.", g_szPrefix)
                        client_cmd(id, "spk %s", g_szNo)
                }
                       
                case 2:
                {
                        Weapons(id)
                }
               
                case 3:
                {
                        ColorChat(id, NORMAL, "%s Sorry! This shop is not ready.", g_szPrefix)
                        client_cmd(id, "spk %s", g_szNo)
                }
                       
                case 0:
                {
                        menu_destroy(menu)
                }
               
        }
        return PLUGIN_HANDLED
}

public Weapons(id)
{
        new WEPMenu = menu_create("\rSpecial Weapons", "Weapons_Handler")
       
        menu_additem(WEPMenu, "\wGolden Ak47 \y[More DMG] \r16000$ ", "1", 0)
        menu_addblank(WEPMenu, 0)
        menu_additem(WEPMenu, "\wBack", "0", 0)
               
        menu_setprop(WEPMenu, MPROP_PERPAGE, 0)

        menu_display(id, WEPMenu, 0)
}

public Weapons_Handler(id, menu, item)
{
               
        new data[6], iName[64]
        new access, callback
               
        menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)
        new key = str_to_num(data)
        switch(key)
        {
                case 1:
                {
                        if(cs_get_user_money(id) < 16000)
                        {       
                                ColorChat(id, NORMAL, "%s You dont have enough money!", g_szPrefix)
                                client_cmd(id, "spk %s", g_szNo)
                                return PLUGIN_HANDLED
                        }
                       
                        ColorChat(id, NORMAL, "%s You just bought ^4Golden AK47^1.", g_szPrefix)
                        client_cmd(id, "spk %s", g_szYes)
                        cs_set_user_money(id, (cs_get_user_money(id) - 16000))
                        Golden[id] = true
                               
                        if(get_user_weapon(id) == CSW_AK47)
                        {
                                set_pev(id, pev_viewmodel2, View_goldak47)
                                set_pev(id, pev_weaponmodel2, Player_goldak47)
                        }
                        /* ---- How to add more DMG? ---- */
                }
                       
                case 0:
                {
                        menu_destroy(menu)
                        Shop(id)
                }
               
        }
        return PLUGIN_HANDLED
}

public WeaponEvent(id)
{
        if(get_user_weapon(id) == CSW_AK47)
        {
                if(Golden[id])
                {
                        set_pev(id, pev_viewmodel2, View_goldak47)
                        set_pev(id, pev_weaponmodel2, Player_goldak47)
                }
               
        }
        return PLUGIN_HANDLED
}

public Spawning(id)
{
        if(is_user_alive(id))
        {
                Golden[id] = false
        }
}


Flick3rR 06-09-2014 06:34

Re: How to add DMG to weapon
 
1 Attachment(s)
Code:

if(is_user_alive(id))
{
        ColorChat(id, NORMAL, "%s You are ^4dead^1.", g_szPrefix)
        client_cmd(id, "spk %s", g_szNo)
}

What?! I think you forgot the ! sign before is_user_alive
Also, if you want to stop the function, use else after the check, or return something inside it, so the function will stop.
It's better to use the item variable, instead of getting menu info. Just make a
PHP Code:

new key item 

and then you may use the same switch between key.
Now, on the thread. You should register Ham_TakeDamage like this:
PHP Code:

RegisterHam(Ham_TakeDamage"player""Event_TakeDamage"

I see you have already made a bool for the user having golden ak47, so we can use it in the ham function to check if the user holds golden ak and then multiple his damage.
Like this:
PHP Code:

public Event_TakeDamage(victiminflictorattackerFloat:damagedmgbits)
{
    if(
is_user_alive(attacker) && get_user_weapon(attacker) == CSW_AK47 && Golden[attacker])//Checking if the user holds AK47 and it's golden
        
SetHamParamFloat(4damage 2//Here we multiple his damage! The second param is the value of the damage. 
        //Now it's multiplied by 2, but you can increase this number to higher or lower one.


P.S.: I see you reset the bool only on spawn. But if player drops his golden ak47, he will still have that damage increase with another ak47, which is not golden. So you may set the bool to false on ak47 dropping, if it's true when the user drops the ak47.

Also, you may register cvars in variables, so it'll be more easy to use them. And it's better to use get_pcvar_num instead of get_cvar_num, because it's faster.

And you may use read_data(2) in CurWeapon event insted of get_user_weapon, because I think it's more proper.

In the function of the menu, where you give the golden ak47, you don't actually give it to him, but only check if he already has one. So you will have to give_item(id, "weapon_ak47") and then there is no need to check if he already has one, because you gave him. Otherwise, what if he hasn't got ak47? No sense. I'm not really sure if giving the item will automaticaly switch to it, but I think so.

In the menu, you don't have to addblank 0 and then switch it and destroy the menu there. Just use that check in the handlers and it's all okay.
PHP Code:

    if(item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    


The code with all changes precached.

DataCore 06-09-2014 13:10

Re: How to add DMG to weapon
 
Thanks! Im Smarter now:D


All times are GMT -4. The time now is 09:39.

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