Veteran Member
Join Date: Feb 2007
Location: Trollhättan
|
01-20-2012
, 16:28
Re: Help.
|
#4
|
Fixed it, you are now able to buy the shotgun. I also corrected my previous post.
You have to get the messageid when you want to set the money, saving it from init will only make it invalid.
I may have changed more but i do not remember those changes.
Edit2: You can now buy Drugs without errors, removed the or condition that i missed >= is enough to check.
Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>
#include <fakemeta>
#include <colorchat>
#include <cstrike>
#define fm_get_user_money(%1) get_pdata_int( %1, 115 )
#define is_valid_player(%1) (1 <= %1 <= 32)
new g_RegenCost
new g_HpCost
new g_NadesCost
new g_GravCost
new g_InvisCost
new g_DrugsCost
new g_ShotgunazmCost
new AzmGun[33];
new Regen[33];
new const szPrefix[] = "[Mp3-SurfShop] ~ "
new const VERSION[] = "0.0.7"
public plugin_init()
{
register_plugin("Surf-Shop", VERSION, "Ex1ne")
g_RegenCost = register_cvar("amx_sshop_regen_cost", "16000")
g_HpCost = register_cvar("amx_sshop_hp_cost", "4000")
g_NadesCost = register_cvar("amx_sshop_nades_cost", "6000")
g_GravCost = register_cvar("amx_sshop_gravity_cost", "14000")
g_InvisCost = register_cvar("amx_sshop_invis_cost", "12000")
g_DrugsCost = register_cvar("amx_sshop_drugs_cost", "4000")
g_ShotgunazmCost = register_cvar("amx_sshop_azmgun", "16000")
register_clcmd("say /sshop", "Cmd_Shop")
register_clcmd("say /shop", "Cmd_Shop")
register_clcmd("say_team /sshop", "Cmd_Shop")
register_clcmd("say_team /shop", "Cmd_Shop")
register_clcmd("say /test", "testee", ADMIN_BAN)
RegisterHam(Ham_Spawn, "player", "Spawn_Player", 1)
RegisterHam(Ham_Killed, "player", "Killed_Player", 1)
RegisterHam(Ham_TakeDamage, "player", "TakeDamage")
}
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if ( is_valid_player( attacker ) && AzmGun[attacker] == 1 )
{
SetHamParamFloat(4, damage * 3)
}
}
public Cmd_Shop(id)
{
if(!is_user_alive(id))
{
return PLUGIN_HANDLED
}
new money = fm_get_user_money(id)
new cost1 = get_pcvar_num(g_RegenCost)
new cost2 = get_pcvar_num(g_HpCost)
new cost3 = get_pcvar_num(g_NadesCost)
new cost4 = get_pcvar_num(g_GravCost)
new cost5 = get_pcvar_num(g_InvisCost)
new cost6 = get_pcvar_num(g_DrugsCost)
new cost7 = get_pcvar_num(g_ShotgunazmCost)
new szText[555 char]
formatex(szText, charsmax(szText), "\y[.Mp3] Surf Shop^n\yVersion: \d%s", VERSION)
new menu = menu_create(szText, "Cmd_Shop_Handler")
if(money < cost1) formatex(szText, charsmax(szText), "\dRegeneration [Cost: %d$]", cost1)
else formatex(szText, charsmax(szText), "\yRegeneration \w[Cost: \y%d$\w]", cost1)
menu_additem(menu, szText, "1", 0)
if(money < cost2) formatex(szText, charsmax(szText), "\d150 HP [Cost: %d$]", cost2)
else formatex(szText, charsmax(szText), "\y150 HP \w[Cost: \y%d$\w]", cost2)
menu_additem(menu, szText, "2", 0)
if(money < cost3) formatex(szText, charsmax(szText), "\dAll grenades [Cost: %d$]", cost3)
else formatex(szText, charsmax(szText), "\yAll grenades \w[Cost: \y%d$\w]", cost3)
menu_additem(menu, szText, "3", 0)
if(money < cost4) formatex(szText, charsmax(szText), "\dLower gravity [Cost: %d$]", cost4)
else formatex(szText, charsmax(szText), "\yLower Grevity \w[Cost: \y%d$\w]", cost4)
menu_additem(menu, szText, "4", 0)
if(money < cost5) formatex(szText, charsmax(szText), "\dInvisibility [Cost: %d$]", cost5)
else formatex(szText, charsmax(szText), "\yInvisibility \w[Cost: \y%d$\w]", cost5)
menu_additem(menu, szText, "5", 0)
if(money < cost6) formatex(szText, charsmax(szText), "\dDrugs [Cost: %d$]", cost6)
else formatex(szText, charsmax(szText), "\yDrugs \w[Cost: \y%d$\w]", cost6)
menu_additem(menu, szText, "6", 0)
if(money < cost7) formatex(szText, charsmax(szText), "\dAwesome Shotgun [Cost %d$]", cost7)
else formatex(szText, charsmax(szText), "\yAwesome Shotgun \w[Cost: \y%d$\w]", cost7)
menu_additem(menu, szText, "7", 0)
menu_display(id, menu, 0)
return PLUGIN_HANDLED
}
public Cmd_Shop_Handler(id, menu, item)
{
new data[6], iName[64], access, callback
menu_item_getinfo(menu, item, access, data, charsmax(data), iName, charsmax(iName), callback )
new key = str_to_num(data)
switch(key)
{
case 1:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_RegenCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost)
{
ColorChat(id, GREY, "^4%s^3 Bought ^4Regeneration^3!", szPrefix)
fm_set_user_money(id, money - cost)
Regen[id] = 1
}
return PLUGIN_HANDLED
}
case 2:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_HpCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost )
{
ColorChat(id, GREY, "^4%s^3 Bought ^4150 HP^3!", szPrefix)
fm_set_user_money(id, money - cost)
set_user_health(id, 150)
}
}
case 3:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_NadesCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost )
{
ColorChat(id, GREY, "^4%s^3 Bought ^4All grenades^3!", szPrefix)
fm_set_user_money(id, money - cost)
give_item(id, "weapon_hegrenade")
give_item(id, "weapon_smokegrenade")
give_item(id, "weapon_flashbang")
give_item(id, "weapon_flashbang")
}
}
case 4:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_GravCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost )
{
ColorChat(id, GREY, "^4%s^3 Bought ^4Regeneration^3!", szPrefix)
fm_set_user_money(id, money - cost)
set_user_gravity(id, 0.75)
}
}
case 5:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_InvisCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost)
{
ColorChat(id, GREY, "^4%s^3 Bought ^4Invisibility^3!", szPrefix)
fm_set_user_money(id, money - cost)
new iPercent = 50
new iAlpha = iPercent * 255 / 100;
set_user_rendering( id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, iAlpha );
}
}
case 6:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_DrugsCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost )
{
ColorChat(id, GREY, "^4%s^3 Bought ^4Drugs^3!", szPrefix)
fm_set_user_money(id, money - cost)
message_begin( MSG_ONE, get_user_msgid("SetFOV") , { 0, 0, 0 }, id )
write_byte( 180 )
message_end( )
return PLUGIN_HANDLED
}
}
case 7:
{
new money = fm_get_user_money(id)
new cost = get_pcvar_num(g_ShotgunazmCost)
if(money < cost)
{
ColorChat(id, GREY, "^4%s^3 Cant afford.", szPrefix)
return PLUGIN_HANDLED
}
if(money >= cost)
{
fm_set_user_money(id, money - cost)
give_item(id, "weapon_m3")
cs_set_user_bpammo(id, CSW_M3, 300)
AzmGun[id] = 1;
ColorChat(id, GREY, "^4%s^3 Bought ^4Awesome Shotgun^3!", szPrefix)
}
}
}
return PLUGIN_HANDLED
}
public Spawn_Player(id)
{
if(Regen[id] == 1)
{
new HP
HP = get_user_health(id)
if(HP < 100)
{
if(HP + 2 >= 100)
{
return PLUGIN_HANDLED
}
set_user_health(id, HP + 5)
}
}
set_task(1.0, "Spawn_Player", id)
return PLUGIN_HANDLED
}
public Killed_Player(id)
{
Regen[id] = 0;
AzmGun[id] = 0;
set_user_gravity(id, 1.0)
set_user_rendering(id)
}
public fm_set_user_money ( index, i_Money )
{
set_pdata_int ( index, 115, i_Money );
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("Money"), _, index);
write_long(i_Money);
write_byte ( 1 );
message_end ();
}
__________________
Last edited by fxfighter; 01-20-2012 at 16:50.
Reason: Typos and fixed so that you can buy drugs
|
|