AlliedModders

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

ironskillz1 03-13-2013 11:20

buy meny
 
How can i change i menu if someone buy something?

Exemple if my menu look like this
Knife Skin [NOT BOUGHT]

And when someone buy it. I want it to look like this
Knife Skin [BOUGHT]


How can i do that?


and im using nvault... so i want to save.
so if someone buy a knife and it changes map i want it to stay as [BOUGHT]

Torge 03-13-2013 11:59

Re: buy meny
 
With a boolean or booleans but depends how many items you add for each boolean. ;D

Example:
PHP Code:

// Bought?
if (g_bBoughtAK47[id])
   
menu_additem(hMenu"AK47 [BOUGHT]""1");
// Not bought?
else
   
menu_additem(hMenu"AK47 [NOT BOUGHT]""1"); 


ironskillz1 03-13-2013 13:49

Re: buy meny
 
Quote:

Originally Posted by Torge (Post 1911975)
With a boolean or booleans but depends how many items you add for each boolean. ;D

Example:
PHP Code:

// Bought?
if (g_bBoughtAK47[id])
   
menu_additem(hMenu"AK47 [BOUGHT]""1");
// Not bought?
else
   
menu_additem(hMenu"AK47 [NOT BOUGHT]""1"); 




yeah i got like 5 items but im going to add more
but how can i save booleans on nvault?
if not how should i do then?
Code:

stock save_item( index )
{
 gVault = nvault_open( "Nvault" )
 
 if( gVault == INVALID_HANDLE )
 {
  set_fail_state( "[Nvault] nValut ERROR: =-> Invalid-Handle" )
 }
 
 get_user_name( index, gSteamID, charsmax( gSteamID ) )
 
 formatex( vKey, charsmax( vKey ), "%sItems", gSteamID )
 formatex( vData, charsmax( vData ), "%d", gItems[ index ])
 nvault_set( gVault, vKey, vData )
 nvault_close( gVault )
}
stock load_item( index )
{
 gVault = nvault_open( "Nvault" )
 
 if( gVault == INVALID_HANDLE )
 {
  set_fail_state( "[Nvault] nValut ERROR: =-> Invalid-Handle" )
 }
 
 get_user_name(  index, gSteamID, charsmax( gSteamID ) )
 
 formatex( vKey, charsmax( vKey ), "%sItems", gSteamID )
 gItems[ index ] = nvault_get( gVault, vKey )
 nvault_close( gVault )
}


Torge 03-13-2013 13:59

Re: buy meny
 
Perhaps like this?

http://forums.alliedmods.net/showthread.php?t=191406

ironskillz1 03-13-2013 14:46

Re: buy meny
 
oh sorry i mean like this

Becuse i save my Knife models like this
Code:

SaveKnife(id)
{
new authid[32]
get_user_authid(id, authid, 31)
new vaultkey[64]
new vaultdata[64]
format(vaultkey, 64, "KNIFE2_%s", authid)
format(vaultdata, 64, "%d", knife_model[id])
set_vaultdata(vaultkey, vaultdata)
}
LoadKnife(id)
{
new authid[32]
get_user_authid(id,authid,31)
new vaultkey[64], vaultdata[64]
format(vaultkey, 64, "KNIFE2_%s", authid)
get_vaultdata(vaultkey, vaultdata, 64)
knife_model[id] = str_to_num(vaultdata)
}


and they Saves in vault.ini
like this (this is knife model 1)
Code:

; Don't modify!
server_language en
KNIFE2_STEAM_0:0:38415370 1

but when i buy another knife model it looks like this
Code:

; Don't modify!
server_language en
KNIFE2_STEAM_0:0:38415370 2

i want it to show that i own 2 knife models like this
Code:

; Don't modify!
server_language en
KNIFE2_STEAM_0:0:38415370 1
KNIFE2_STEAM_0:0:38415370 2

Can i some how do that?

hornet 03-14-2013 07:25

Re: buy meny
 
It's because your saving over the same key. You should save all of your skin indexes under the one vault key, it would be more efficient. Also, your going from vault to nvault over different posts ... pick one.

Blizzard_87 03-15-2013 06:03

Re: buy meny
 
Quote:

Originally Posted by Torge (Post 1911975)
With a boolean or booleans but depends how many items you add for each boolean. ;D

Example:
PHP Code:

// Bought?
if (g_bBoughtAK47[id])
   
menu_additem(hMenu"AK47 [BOUGHT]""1");
// Not bought?
else
   
menu_additem(hMenu"AK47 [NOT BOUGHT]""1"); 


better method for menu..

example:
PHP Code:


new Temp[101];

formatex(Temp100"AK47 [%s]"g_bBoughtAK47[id] ? "BOUGHT" "NOT BOUGHT")
menu_additem(hMenuTemp"1"); 


Torge 03-15-2013 08:45

Re: buy meny
 
Quote:

Originally Posted by Blizzard_87 (Post 1912990)
better method for menu..

example:
PHP Code:


new Temp[101];

formatex(Temp100"AK47 [%s]"g_bBoughtAK47[id] ? "BOUGHT" "NOT BOUGHT")
menu_additem(hMenuTemp"1"); 


That's right, but it really makes no much difference.

ironskillz1 03-15-2013 10:40

Re: buy meny
 
Quote:

Originally Posted by hornet (Post 1912439)
You should save all of your skin indexes under the one vault key.

How can i do that :)?

hornet 03-16-2013 05:16

Re: buy meny
 
Quote:

Originally Posted by ironskillz1 (Post 1913124)
How can i do that :)?

Well you need to start by scrapping your AK47 array, and make one that can be used for all skins:
Code:
#define MAX_SKINS        5 new bool:g_bBoughtSkin[ 33 ][ MAX_SKINS ];

Your new data functions look like this:

Code:
public SaveData( id ) {     new szData[ 64 ], szKey[ 32 ];     get_user_authid( id, szKey, charsmax( szKey ) );     format( szKey, charsmax( szKey ), "%s-SKINS", szKey );         for( new i ; i < MAX_SKINS ; i ++ )         if( g_bBoughtSkin[ id ][ i ] )             format( szData, charsmax( szData ), "%s%i-", szData, i );         set_vaultdata( szKey, szData ); } public LoadData( id ) {     new szData[ 64 ], szKey[ 32 ], szPiece[ 32 ];         get_user_authid( id, szKey, charsmax( szKey ) );     format( szKey, charsmax( szKey ), "%s-SKINS", szKey );         get_vaultdata( szKey, szData, charsmax( szData ) );         while( contain( szData, "-" ) >= 0 )     {               strtok( szData, szPiece, charsmax( szPiece ), szData, charsmax( szData ), '-' );                       g_bBoughtSkin[ id ][ str_to_num( szPiece ) ] = true;     } }

And now you need to go and rebuild your menu create code accordingly to the new skins array.


All times are GMT -4. The time now is 21:46.

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