AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Error with money, shop. (https://forums.alliedmods.net/showthread.php?t=187713)

klysman07 06-16-2012 22:12

Error with money, shop.
 
I have a problem with this shop .

I can not buy items from the store, saying did not have money, even though with 16,000 $$

Can someone help me please

Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>

new i
new bool:g_iSet[33]
new g_szDefault_Model[33][50]

enum _:items_data {
        item_Name[100],
        item_Cost,
        item_Team
}

new Array:g_aItems
new gmsgSetFOV
new bool:has_drug[33]

public plugin_init()
{
        register_plugin("JailBreak SHOP.", "2.0", "Andre Neves")
       
        register_clcmd("say /shop", "cmdShop")
       
        register_event("CurWeapon", "set_speed", "be", "1=1");
       
        g_aItems = ArrayCreate(items_data)
       
        Add_Item("500 Hp", 15000, CS_TEAM_CT)
        Add_Item("255 Hp", 7500, CS_TEAM_CT)
        Add_Item("No Clip\d[15s]", 10000, CS_TEAM_CT)
        Add_Item("Invensibilidade\d[15s]", 10000, CS_TEAM_CT)
        Add_Item("Gravidade\d[20s]", 5000, CS_TEAM_CT)
        Add_Item("Kit Guarda", 10000, CS_TEAM_CT)
       
       
        Add_Item("1 Bomba HE" , 7000, CS_TEAM_T)
        Add_Item("2 Bombas Flash", 7000, CS_TEAM_T)
        Add_Item("Park Bombas", 9000, CS_TEAM_T)
        Add_Item("Hp 255", 8000, CS_TEAM_T)
        Add_Item("Colete 255",6000, CS_TEAM_T)
        Add_Item("Gravidade\d[15s]",7000, CS_TEAM_T)
        Add_Item("2 Bombas Congelante", 6000, CS_TEAM_T)
        Add_Item("Usp\d[12tiros]", 15000, CS_TEAM_T)
        Add_Item("Glock\d[20tiros]", 15500, CS_TEAM_T)
        Add_Item("Scolt\d[2tiros]", 16000, CS_TEAM_T)
        Add_Item("Invencibilidade\d[6s]", 14500, CS_TEAM_T)
        Add_Item("Invisivel\d[15s]", 14000, CS_TEAM_T)
        Add_Item("Maconha\d[2m]", 8500, CS_TEAM_T) 
        Add_Item("Kit Prisioneiro", 12000, CS_TEAM_T)
        Add_Item("[Ak47]+[Awp]+[Deagle]", 8000, CS_TEAM_CT)
       
        gmsgSetFOV = get_user_msgid("SetFOV")
}

public cmdShop(id)
{
        if(!is_user_alive(id))
        {
                client_print(id, print_chat, "[ + SHOP + ] Voce precisa estar vivo para abrir o Shop !!")
        }
       
        static iMoney, szBuffer[50], iTotalItems, item_Data[items_data], team
        team    = _:cs_get_user_team(id)
        iMoney  = cs_get_user_money(id)
       
        formatex(szBuffer, charsmax(szBuffer), "\r[ + SHOP + ]^n- Seu dinheiro:\w%i^n\wBy:Jailbreak", iMoney)
        new iMenu = menu_create(szBuffer, "MenuHandler")
       
        new szMenuId[10]
       
        iTotalItems = ArraySize(g_aItems)
       
        for( i = 0; i < iTotalItems; i++)
        {
                ArrayGetArray(g_aItems, i, item_Data)
               
                if(item_Data[item_Team] != _:team)
                        continue
               
                if(item_Data[item_Cost] > iMoney)
                {
                        remove_colorMenu(item_Data[item_Name], charsmax(item_Data[item_Name]))
                        formatex(szBuffer, charsmax(szBuffer), "%s \r=[%i]", item_Data[item_Name], item_Data[item_Cost])
                }
               
                else
                        formatex(szBuffer, charsmax(szBuffer), "%s \r=[%i]", item_Data[item_Name], item_Data[item_Cost])
               
                num_to_str(i, szMenuId, 9)
                menu_additem(iMenu, szBuffer, szMenuId)
        }
       
        menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL)
        menu_display(id, iMenu)
       
        return 1
}

public MenuHandler(id, menu, item)
{
        if(item == MENU_EXIT)
                return
       
        new data[6], iName[64]
        new iAccess, callback
        menu_item_getinfo(menu, item, iAccess, data, 5, iName, 63, callback)
        new itemId = str_to_num(data)
       
        static iMoney, item_Data[items_data]
       
        ArrayGetArray(g_aItems, itemId, item_Data)
       
        if(iMoney < item_Data[item_Cost])
        {
                client_print(id, print_chat, "[ + SHOP + ] Voce ainda precisa de mais dinheiro para comprar este item !!")
                return
        }
       
        iMoney = cs_get_user_money(id) - item_Data[item_Cost]
       
        cs_set_user_money(id, iMoney)
       
        switch(++itemId)
        {
                case 1:                       
                {
                        set_user_health(id, 500)
                       
                        client_print( id, print_chat, "Voce comprou 500 de Vida!!")
                        client_print( id, print_chat, "By: !!")                               
                }
                case 2: 
                {
                        set_user_health(id, 255)
                       
                        client_print( id, print_chat, "Voce comprou 255 de Vida !!")
                        client_print( id, print_chat, "By:  !!")                       
                }
                case 3:
                {
                        set_user_noclip(id, 1)
                        set_task(15.0, "remove_noclip", id)
                       
                        client_print( id, print_chat, "Voce comprou 15 segundos de No-Clip !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 4:
                {
                        set_user_godmode(id, 1)
                        set_task(15.0, "remove_godmode", id)
                       
                        client_print( id, print_chat, "Voce comprou 15 segundos de Invensibilidade !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 5:
                {
                        set_user_gravity(id, 0.5)
                        set_task(20.0, "remove_gravity", id)
                       
                        client_print( id, print_chat, "Voce comprou 20 segundos de Gravidade reduzida !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 6:
                {
                        cs_set_weapon_ammo(give_item(id, "weapon_m4a1"), 30)
                        cs_set_user_bpammo(id, CSW_M4A1, 90)
                        set_user_health(id, 200)
                        cs_set_user_armor(id, 200, CS_ARMOR_VESTHELM)
                        cs_set_weapon_ammo(give_item(id, "weapon_usp"), 12)
                        cs_set_user_bpammo(id, CSW_USP, 35)                   
                        give_item(id, "weapon_hegrenade")
                        give_item(id, "weapon_smokegrenade")
                        give_item(id, "weapon_flashbang")
                       
                        client_print( id, print_chat, "Voce comprou Kit Guarda para Ajuda-lo neste Round !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 7:
                {
                        give_item(id, "weapon_hegrenade")
                       
                        client_print( id, print_chat, "Voce comprou 1 Granada !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 8:
                {
                        give_item( id, "weapon_flashbang" );
                        give_item( id, "weapon_flashbang" );
                       
                        client_print( id, print_chat, "Voce comprou 2 Flash !!")
                        client_print( id, print_chat, "By: !!")                               
                }
                case 9:
                {
                        give_item(id, "weapon_hegrenade")
                        give_item(id, "weapon_flashbang")
                        give_item(id, "weapon_smokegrenade")                       
                       
                        client_print( id, print_chat, "Voce comprou Park Granadas com Flash , He e Smolk !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 10:
                {
                        set_user_health(id, 255)
                       
                        client_print( id, print_chat, "Voce comprou 255 de Vida !!")
                        client_print( id, print_chat, "By: !!")                               
                }
                case 11:
                {
                        cs_set_user_armor(id, 255, CS_ARMOR_VESTHELM)
                       
                        client_print( id, print_chat, "Voce comprou 255 de Colete !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 12:
                {
                        set_user_gravity(id, 0.5)
                        set_task(15.0, "remove_gravity", id)
                       
                        client_print( id, print_chat, "Voce comprou 15 Segundos de Gravidade reduzida !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 13:{
                       
                       
                        give_item(id, "weapon_smokegrenade")
                       
                       
                        client_print( id, print_chat, "Voce comprou Granada Congelante !!")
                        client_print( id, print_chat, "By:  !!")                       
                }                     
                case 14:
                {
                        cs_set_weapon_ammo(give_item(id, "weapon_usp"), 12)
                        cs_set_user_bpammo(id, CSW_USP, 0)
                       
                        client_print( id, print_chat, "Voce comprou uma USP com 12 tiros !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 15:               
                {
                        cs_set_weapon_ammo(give_item(id, "weapon_glock18"), 20)
                        cs_set_user_bpammo(id, CSW_GLOCK18, 0)
                       
                        client_print( id, print_chat, "Voce comprou GLOCK com 20 tiros !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 18:
                {
                        set_user_godmode(id, 1)
                        set_task(6.0, "remove_godmode", id)
                       
                        client_print( id, print_chat, "Voce comprou 6 segundos de Invensibilidade !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 17:
                {
                        set_user_rendering( id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 255)     
                        set_task(20.0, "Reset_Stealth", id )
                       
                        client_print( id, print_chat, "Voce comprou 20 segundos de Invisibilidade !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 19:
                {
                        set_user_health( id, 150)
                        set_user_gravity(id, 0.8)
                       
                        message_begin(MSG_ONE, gmsgSetFOV, {0,0,0}, id)
                        write_byte(170)
                        message_end()
                        has_drug[id] = true
                        set_task(120.0 , "remove_drug", id);
                        client_print( id, print_chat, "Voce comprou 2 Minutos do Efeito da Maconha e agora esta Drogado !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 16:
                {
                        cs_set_weapon_ammo(give_item(id, "weapon_scout"), 2)
                        cs_set_user_bpammo(id, CSW_SCOUT, 0)
                       
                        client_print( id, print_chat, "Voce comprou uma Scolt com 2 tiro !!")
                        client_print( id, print_chat, "By:  !!")                               
                }             
                case 20:
                {
                        give_item(id, "weapon_flashbang")
                        give_item(id, "weapon_smokegrenade")                   
                        set_user_health(id, 200)
                        cs_set_user_armor(id, 200, CS_ARMOR_VESTHELM)
                       
                        client_print( id, print_chat, "Voce comprou Kit Prisioneiro com Vida, Colete ,Flash , Smolk !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
                case 21:
                {
                        cs_set_weapon_ammo(give_item(id, "weapon_ak47"), 30)
                        cs_set_user_bpammo(id, CSW_AK47, 150)
                       
                        cs_set_weapon_ammo(give_item(id, "weapon_awp"), 10)
                        cs_set_user_bpammo(id, CSW_AWP, 50)
                       
                        cs_set_weapon_ammo(give_item(id, "weapon_deagle"), 7)
                        cs_set_user_bpammo(id, CSW_DEAGLE, 50)                 
                       
                        client_print( id, print_chat, "Voce comprou [ AK47+AWP+DEAGLE ] Totalmente Carregadas !!")
                        client_print( id, print_chat, "By:  !!")                               
                }
        }
        return;
}

Add_Item(name[], cost, CsTeams:team) {
        static item_Data[items_data]
       
        copy(item_Data[item_Name], charsmax(item_Data[item_Name]), name)
        item_Data[item_Cost] = cost
        item_Data[item_Team] = _:team
       
        ArrayPushArray(g_aItems, item_Data)   
}

public remove_gravity(id)
{
        if(is_user_connected(id))
                set_user_gravity(id, 1.0)
}

public remove_noclip(id)
{
        if(is_user_connected(id))
                set_user_noclip(id, 0)
}

public remove_godmode(id)
        set_user_godmode(id, 0)

public remove_CTmodel(id)
        cs_set_user_model(id, g_szDefault_Model[id])

public remove_drug(id)
{
        if(!has_drug[id])
                return;
       
        message_begin(MSG_ONE, gmsgSetFOV, {0,0,0}, id)
        write_byte(90)
        message_end()
        has_drug[id] = false
        client_print( id, print_chat, "O Efeito da Maconha Acabou !!")
        client_print( id, print_chat, "By:  !!")               
}

remove_colorMenu(menu[], len)
{
replace_all(menu, len, "\r", "")
replace_all(menu, len, "\d", "")
replace_all(menu, len, "\y", "")
replace_all(menu, len, "\w", "")

copyc(menu, len, menu, 0)
}

public Reset_Stealth(id)
{
set_user_rendering( id, kRenderFxNone, 0, 0, 0, kRenderNormal, 0 )
client_print(id, print_chat, " Sua Invisibilidade Acabou !!")
client_print( id, print_chat, "By:  !!")               
}

public set_speed(id)
{
if(g_iSet[id])
{
        set_user_maxspeed(id, 600.0)
}
}

public set_timer(id)
{
set_user_maxspeed(id, 250.0)
client_print(id, print_chat, " Sua Velocidade Acabou !!")
client_print( id, print_chat, "By:  !!")               
}



Brasil.

Neeeeeeeeeel.- 06-16-2012 22:30

Re: Error with money, shop.
 
"iMoney" allways will be 0 at the conditional that ckeck's if you have the money to buy an item.

hornet 06-16-2012 22:32

Re: Error with money, shop.
 
Code:

static iMoney, item_Data[items_data]
Your creating your variable iMoney everytime and not setting to your real amount of money. So:
Code:
if(iMoney < item_Data[item_Cost]) // = true

klysman07 06-16-2012 22:51

Re: Error with money, shop.
 
Quote:

Originally Posted by hornet (Post 1730199)
Code:

static iMoney, item_Data[items_data]
Your creating your variable iMoney everytime and not setting to your real amount of money. So:
Code:
if(iMoney < item_Data[item_Cost]) // = true

I did not understand, can you explain please?

where should I change, how should I put.

Neeeeeeeeeel.- 06-17-2012 00:08

Re: Error with money, shop.
 
Just put:
PHP Code:

iMoney cs_get_user_moneyid ); 

After:
PHP Code:

static iMoneyitem_Data[items_data


klysman07 06-17-2012 08:13

Re: Error with money, shop.
 
I do not know. where should I change.

one can change me, and put the code in full.

please

hornet 06-17-2012 08:35

Re: Error with money, shop.
 
1 Attachment(s)
When you post in the Scripting Help section, users expect that your willing to learn and try to solve the problem with the help your given. Next time you need a plugin fixed, please post in the request section unless you want to learn.

klysman07 06-17-2012 08:37

Re: Error with money, shop.
 
Thanks, I'll have tests and put the result.

and next time I do right =]

Tkss

klysman07 06-17-2012 09:10

Re: Error with money, shop.
 
friend. now no longer to able to open shop.
I type / shop, most will not open

can you help me?

hornet 06-17-2012 10:00

Re: Error with money, shop.
 
I just tested and it works fine.


All times are GMT -4. The time now is 06:14.

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