|
Member
|

03-18-2017
, 21:48
Request Costume Shop
|
#1
|
Hello, I have this plugin, Its works fine but lacks some things that i need, if someone can help me with this, I would be grateful
#include <adv_vault> alternative to sql, sqlite, nvault.
#include <expmod> where i have my custom natives, alternatives to cs_set_user... and cs_get_user...
What i need, 2 separate menu where you can buy customes and a Menu like a Inventory where you can choose your already bought costumes, You can use up to 3 costumes at the same time but not the same costumes, because you have <HEAD> <PELVIS> and <BACK>, at the moment you can just use 1, either Head, Pelvis and Back, so its seems a bit useless.
If you bought a costume, it will NOT appear again on the menu but on Inventory
When you choose a Costume (max. 3) it will appear on Inventory: Costume Name #1 - On Use
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <amx_settings_api>
#include <adv_vault>
#include <expmod> // cs_get_user_money and cs_set_user_money natives -> exp_get_user_monets and exp_set_user_monets
#include <colorchat>
new gVault, gF1, gF2;
new const __VAULTNAME[] = "data_costumes";
/* ======================================================================================================================= */
new const __Plugin[][] = { "Costume Shop" , "1.0" , "kikizon" };
new const __Commands[][] = { "say /shopcostumes", "say /hats" };
new const __COSTUMES_FILE[] = "costumes.ini";
const MAX_COSTUMES = 56 ;
new cached_costume_name[MAX_COSTUMES][32], cached_costume_model[MAX_COSTUMES][64], cached_costume_submodel[MAX_COSTUMES],
cached_costume_price[MAX_COSTUMES], costume_counter, gMaxPlayers;
new gSelectedCostume[ 33 ][ 2 ], gUnlockedCostumes[ 33 ][ MAX_COSTUMES ], gPlayerName[ 33 ][ 32 ];
/* ======================================================================================================================= */
public plugin_precache()
{
new i, szBuffer[128];
for( i = 1 ; i < MAX_COSTUMES ; ++i )
{
if( costume_counter >= MAX_COSTUMES )
break;
formatex( szBuffer, 127, "COSTUME_%d", i );
if( !amx_load_setting_string( __COSTUMES_FILE, szBuffer, "NOMBRE", cached_costume_name[i], 31 )) continue;
amx_load_setting_string( __COSTUMES_FILE, szBuffer, "MODEL", cached_costume_model[i], 31);
amx_load_setting_int( __COSTUMES_FILE, szBuffer, "SUB MODEL", cached_costume_submodel[i] );
amx_load_setting_int( __COSTUMES_FILE, szBuffer, "PRICE", cached_costume_price[i]);
precache_model(cached_costume_model[i]);
++costume_counter;
}
}
public plugin_init()
{
register_plugin( __Plugin[ 0x0000 ] , __Plugin[ 0x0001 ] , __Plugin[ 0x0002 ] );
register_cvar( "costumes", __Plugin[ 0x0002 ], FCVAR_SERVER|FCVAR_SPONLY );
set_cvar_string( "costumes", __Plugin[ 0x0002 ] );
register_event( "HLTV" , "ev_RoundStart" , "a" , "1=0" , "2=0" );
new i;
for( i = 0 ; i < sizeof __Commands ; ++i )
register_clcmd( __Commands[i] , "clcmdCostumes" );
RegisterHam( Ham_Spawn, "player", "hamSpawnPost", true );
RegisterHam( Ham_Killed, "player", "hamKilledPost", true );
gMaxPlayers = get_maxplayers();
gVault = adv_vault_open( __VAULTNAME );
gF1 = adv_vault_register_field( gVault, "Selected" );
gF2 = adv_vault_register_field( gVault, "Unlocked", DATATYPE_ARRAY, MAX_COSTUMES );
adv_vault_init( gVault );
}
/* ======================================================================================================================= */
public client_putinserver( index )
{
get_user_name( index , gPlayerName[ index ] , 31 );
gSelectedCostume[ index ][ 0 ] = gSelectedCostume[ index ][ 1 ] = 0;
new i;
for( i = 0 ; i < costume_counter ; ++i )
gUnlockedCostumes[ index ][ i ] = 0;
LoadData( index );
}
public client_disconnect( index )
{
if( gSelectedCostume[index][0] )
{
remove_entity( gSelectedCostume[index][1] );
gSelectedCostume[index][1] = 0;
}
SaveData( index );
}
public hamSpawnPost( index )
{
if( gSelectedCostume[index][0])
{
DeleteCostume(index, false);
SetCostume(index);
}
}
public hamKilledPost( victim , attacker , sg )
if( gSelectedCostume[victim][0])
DeleteCostume( victim , false );
public ev_RoundStart()
{
new i;
for( i = 1 ; i <= gMaxPlayers ; ++i )
{
if( !is_user_connected(i)) continue;
DeleteCostume(i, false);
SaveData(i);
}
}
/* ======================================================================================================================= */
public clcmdCostumes( index )
{
new szBuffer[64], menu = menu_create( "\yCostume Shop" , "menu_clcmd");
menu_additem( menu , gSelectedCostume[index][0] ? "\yRemover Current Costume" : "\dCostume not found" );
if(gSelectedCostume[index][0]) formatex( szBuffer , 63 , "Select Costume: [\y%s\w]", cached_costume_name[ gSelectedCostume[index][0] ] )
else formatex( szBuffer , 63, "Select Costume" );
menu_additem( menu , szBuffer );
menu_display( index , menu );
return PLUGIN_HANDLED;
}
public menu_clcmd( index , menu, item )
{
if( item != MENU_EXIT )
{
if(!item) DeleteCostume( index, true );
else ShowCostumeMenu( index );
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
ShowCostumeMenu( index )
{
new i, szBuffer[64], money, menu, szNum[4];
menu = menu_create( "\wCostume Shop" , "menu_costume" );
money = exp_get_user_monets(index);
for( i = 1 ; i <= costume_counter ; ++i )
{
if ( !cached_costume_name[i][0] ) continue;
if( gUnlockedCostumes[index][i] == 1)
formatex( szBuffer, 63, cached_costume_name[i] );
else if( gSelectedCostume[index][0] == i )
formatex( szBuffer , 63 , "\d%s \y[On Use]", cached_costume_name[i] );
else if( money < cached_costume_price[i] )
formatex( szBuffer , 63 , "\d%s \y[Cost: $%d]", cached_costume_name[i], cached_costume_price[i] );
else
formatex( szBuffer , 63 , "\w%s \y[Cost: $%d]", cached_costume_name[i], cached_costume_price[i] );
num_to_str( i , szNum , 3 );
menu_additem( menu , szBuffer , szNum );
}
menu_display( index , menu );
}
public menu_costume( index , menu , item )
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[3], Name[64], access, callback, i;
menu_item_getinfo(menu, item, access, data, 2, Name, 63, callback);
i = str_to_num(data);
if( gUnlockedCostumes[index][i] == 1 )
{
DeleteCostume( index , true );
ColorChat(index, GREEN, "^x04[JailBreaK PaiN]^x01 Choosed:^x03 %s", cached_costume_name[i] );
gSelectedCostume[index][0] = i;
SetCostume( index );
}
else if( gSelectedCostume[index][0] == i )
ColorChat(index, GREEN, "^x04[JailBreaK PaiN]^x01 Costume already choosed" );
else if( exp_get_user_monets(index) < cached_costume_price[i] )
ColorChat(index, GREEN, "^x04[JailBreaK PaiN]^x01 You dont have enough money" );
else
{
gUnlockedCostumes[index][i] = 1;
DeleteCostume(index, true);
exp_set_user_monets(index, exp_get_user_monets(index) - cached_costume_price[i])
ColorChat(index, GREEN, "^x04[JailBreaK PaiN]^x01 Bought:^x03 %s", cached_costume_name[i] );
gSelectedCostume[index][0] = i;
SetCostume(index);
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
/* ======================================================================================================================= */
LoadData( index )
{
if( !adv_vault_get_prepare( gVault , _ , gPlayerName[ index ] ))
return;
gSelectedCostume[ index ][0] = adv_vault_get_field( gVault , gF1 );
adv_vault_get_field( gVault , gF2 , gUnlockedCostumes[index], MAX_COSTUMES-1 );
}
SaveData( index )
{
if( !is_user_connected(index) ) return;
adv_vault_set_start( gVault );
adv_vault_set_field( gVault , gF1 , gSelectedCostume[ index ][0] );
adv_vault_set_field( gVault , gF2 , gUnlockedCostumes[ index ] );
adv_vault_set_end( gVault , 0 , gPlayerName[index] );
}
stock SetCostume(index)
{
if( !is_user_alive(index)) return ;
gSelectedCostume[index][1] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
set_pev(gSelectedCostume[index][1], pev_movetype, MOVETYPE_FOLLOW );
set_pev(gSelectedCostume[index][1], pev_aiment, index );
set_pev(gSelectedCostume[index][1], pev_rendermode, kRenderNormal );
engfunc(EngFunc_SetModel, gSelectedCostume[index][1], cached_costume_model[ gSelectedCostume[index][0] ]);
set_pev(gSelectedCostume[index][1], pev_body, cached_costume_submodel[ gSelectedCostume[index][0] ]);
set_pev(gSelectedCostume[index][1], pev_sequence, cached_costume_submodel[ gSelectedCostume[index][0] ]);
set_pev(gSelectedCostume[index][1], pev_animtime, get_gametime());
set_pev(gSelectedCostume[index][1], pev_framerate, 1.0);
}
stock DeleteCostume( index , type )
{
if( type )
{
remove_entity(gSelectedCostume[index][1] );
gSelectedCostume[index][1] = 0;
gSelectedCostume[index][0] = 0;
}
else
{
remove_entity(gSelectedCostume[index][1] );
gSelectedCostume[index][1] = 0;
}
}
|
|