AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ Request ] nvault & add / remove a plr (https://forums.alliedmods.net/showthread.php?t=188321)

Aooka 06-25-2012 04:27

[ Request ] nvault & add / remove a plr
 
Hello :) ,
My code :
Code:
#include < amxmodx > #include < amxmisc > #include < nvault > #define CMDTARGET_NO_BOTS  (1<<3) new g_iSaving; new bool: g_bIsVip[ 33 ]; public plugin_init( ) {     register_plugin( "Vip test" , "1.0" , "Aooka" );     register_concmd( "amx_addvip" , "CmdAddVip" , ADMIN_IMMUNITY , "<#userid>" );     register_concmd( "amx_removevip" , "CmdRemoveVip" , ADMIN_IMMUNITY , "<#userid>" );     register_clcmd( "say /vip" , "VipMenu" );     g_iSaving = nvault_open( "vip_file" );     new iMenu = menu_create( "Awesome Vip Menu" , "Handler_Menu" );     menu_additem( iMenu , "Test 1" , "1" , 0 );     menu_additem( iMenu , "Test 2" , "2" , 0 );     menu_setprop( iMenu , MPROP_EXITNAME , "Sortir" ); } public client_putinserver( id ) {     g_bIsVip[ id ] = false; } public plugin_end( ) {     nvault_close( g_iSaving ); } public VipMenu( id , iMenu ) {     if( is_user_alive( id ) && g_bIsVip[ id ] == true )     {         menu_display( id , iMenu , 0 );     }     else     {         client_print( id , print_center , "If you whant to go to the VipMenu you msut be a Vip" );     } } public Handler_Menu( id , iMenu , item ) {     if( item != MENU_EXIT )     {         switch( item )         {             case 1:                 client_print( id , print_center , "Test 1 :: OK" );             case 2:                 client_print( id , print_center , "Test 2 :: OK" );         }     }     else     {         client_print( id , print_center , "Menu is closed" );         menu_destroy( iMenu );     } } public CmdAddVip( id , level , cid ) {     if( !cmd_access( id , level , cid , 2 ) )     {         return 1;     }     else     {         new szArg[ 36 ];         read_argv( 1 , szArg , charsmax( szArg ) );         new target = cmd_target( id , szArg , CMDTARGET_NO_BOTS );         if( !target )         {             console_print( id , "Player not found" );             return 1;         }                 else if( g_bIsVip[ target ] == true )         {             console_print( id , "Player is alrady a Vip" );             return 1;         }                 static szName[ 2 ][ 36 ];         get_user_name( id , szName[ 0 ] , charsmax( szName[ ] ) );         get_user_name( target , szName[ 1 ] , charsmax( szName[ ] ) );         static szAuthID[ 2 ][ 35 ];         get_user_authid( id , szAuthID[ 0 ] , charsmax( szAuthID[ ] ) );         get_user_authid( target , szAuthID[ 1 ] , charsmax( szAuthID[ ] ) );             client_print( 0 , print_chat , "%s (%s) gave a Vip place for the player %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] );             log_amx( "%s (%s) gave a place of Vip to %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] ); } public CmdRemoveVip( id , level , cid ) {     if( !cmd_access( id , level , cid , 2 ) )     {         return 1;     }         new szArg[ 36 ];     read_argv( 1 , szArg , charsmax( szArg ) );         new target = cmd_target( id , szArg , CMDTARGET_NO_BOTS );         if( !target )     {         console_print( id , "Player not found" );         return 1;     }         else if( g_bIsVip[ target ] == false )     {         g_bIsVip[ target ] = true;     }         static szName[ 2 ][ 36 ];     get_user_name( id , szName[ 0 ] , charsmax( szName[ ] ) );     get_user_name( target , szName[ 1 ] , charsmax( szName[ ] ) );     static szAuthID[ 2 ][ 35 ];     get_user_authid( id , szAuthID[ 0 ] , charsmax( szAuthID[ ] ) );     get_user_authid( target , szAuthID[ 1 ] , charsmax( szAuthID[ ] ) );         client_print( 0 , print_chat , "%s (%s) remove a Vip place for the player %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] );         log_amx( "%s (%s) remove a place of Vip to %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] ); }

It do not work and i test a lots of things this last weeks but ...

So thank you in advance all :D

Sherazaa 06-25-2012 08:07

Re: [ Request ] nvault & add / remove a plr
 
What is this !!
szName[ 2 ][ 36 ];

Why they are 2 arrays O_O

hornet 06-25-2012 08:16

Re: [ Request ] nvault & add / remove a plr
 
Quote:

Originally Posted by Sherazaa (Post 1735715)
What is this !!
szName[ 2 ][ 36 ];

Why they are 2 arrays O_O

For 2 different players.


Aooka, you never set the VIP bool to true in the CmdAddVip() function. You included nVault which you have open and closed a vault file, but never done anything with it? Also, there is no need to define CMDTARGET_NO_BOTS because it is an already defined constant in amxmisc. And for the understanding of how your defining your variables, it is unnecessary for you to use static in these cases, use new instead. You only need to use static when creating large arrays ( for example an MOTD ) or when your calling the function with an array / string very often.

Exolent[jNr] 06-25-2012 12:10

Re: [ Request ] nvault & add / remove a plr
 
Quote:

Originally Posted by Sherazaa (Post 1735715)
What is this !!
szName[ 2 ][ 36 ];

Why they are 2 arrays O_O

It's a 2-dimensional array.

Sherazaa 06-25-2012 12:37

Re: [ Request ] nvault & add / remove a plr
 
Okay thanks :) I go look a tutoriel about it !

Aooka 06-25-2012 12:58

Re: [ Request ] nvault & add / remove a plr
 
@Sherazaa: Take just a look here : http://wiki.amxmodx.org/Pawn_Tutoria...nsional_Arrays :D

@Hornet: So i do that :
Code:
#include < amxmodx > #include < amxmisc > #include < nvault > new g_iSaving; new bool: g_bIsVip[ 33 ]; public plugin_init( ) {     register_plugin( "Vip test" , "1.0" , "Aooka" );     register_concmd( "amx_addvip" , "CmdAddVip" , ADMIN_IMMUNITY , "<#userid>" );     register_concmd( "amx_removevip" , "CmdRemoveVip" , ADMIN_IMMUNITY , "<#userid>" );         register_clcmd( "say /vip" , "VipMenu" );         g_iSaving = nvault_open( "vip_file" );         new const iMenu = menu_create( "Awesome Vip Menu" , "Handler_Menu" );     menu_additem( iMenu , "Test 1" , "1" , 0 );     menu_additem( iMenu , "Test 2" , "2" , 0 );         menu_setprop( iMenu , MPROP_EXITNAME , "Sortir" ); } public client_putinserver( id ) {     g_bIsVip[ id ] = false; } public plugin_end( ) {     nvault_close( g_iSaving ); } public VipMenu( id , iMenu ) {     if( is_user_alive( id ) && g_bIsVip[ id ] == true )     {         menu_display( id , iMenu , 0 );     }     else     {         client_print( id , print_center , "If you whant to go to the VipMenu you msut be a Vip" );     }   } public Handler_Menu( id , iMenu , item ) {     if( item != MENU_EXIT )     {         switch( item )         {             case 1:                 client_print( id , print_center , "Test 1 :: OK" );             case 2:                 client_print( id , print_center , "Test 2 :: OK" );         }     }     else     {         client_print( id , print_center , "Menu is closed" );         menu_destroy( iMenu );     } } public CmdAddVip( id , level , cid ) {     if( !cmd_access( id , level , cid , 2 ) )     {         return 1;     }     else     {         new szArg[ 36 ];         read_argv( 1 , szArg , charsmax( szArg ) );         new target = cmd_target( id , szArg , CMDTARGET_NO_BOTS );         if( !target )         {             console_print( id , "Player not found" );             return 1;         }                 else if( g_bIsVip[ target ] == true )         {             console_print( id , "Player is alrady a Vip" );             return 1;         }         else         {             g_bIsVip[ target ] = true;                         new szName[ 2 ][ 36 ];             get_user_name( id , szName[ 0 ] , charsmax( szName[ ] ) );             get_user_name( target , szName[ 1 ] , charsmax( szName[ ] ) );                         new szAuthID[ 2 ][ 35 ];             get_user_authid( id , szAuthID[ 0 ] , charsmax( szAuthID[ ] ) );             get_user_authid( target , szAuthID[ 1 ] , charsmax( szAuthID[ ] ) );                         client_print( 0 , print_chat , "%s (%s) gave a Vip place for the player %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] );                         log_amx( "%s (%s) gave a place of Vip to %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] );         }     }     return 0; } public CmdRemoveVip( id , level , cid ) {     if( !cmd_access( id , level , cid , 2 ) )     {         return 1;     }             new szArg[ 36 ];     read_argv( 1 , szArg , charsmax( szArg ) );             new target = cmd_target( id , szArg , CMDTARGET_NO_BOTS );             if( !target )     {         console_print( id , "Player not found" );         return 1;     }             else if( g_bIsVip[ target ] == false )     {         console_print( id , "Player is not a Vip" );         return 1;     }     else     {         new szName[ 2 ][ 36 ];         get_user_name( id , szName[ 0 ] , charsmax( szName[ ] ) );         get_user_name( target , szName[ 1 ] , charsmax( szName[ ] ) );                 new szAuthID[ 2 ][ 35 ];         get_user_authid( id , szAuthID[ 0 ] , charsmax( szAuthID[ ] ) );         get_user_authid( target , szAuthID[ 1 ] , charsmax( szAuthID[ ] ) );                 client_print( 0 , print_chat , "%s (%s) remove a Vip place for the player %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] );                     log_amx( "%s (%s) remove a place of Vip to %s (%s)" , szName[ 0 ] , szAuthID[ 0 ] , szName[ 1 ] , szAuthID[ 1 ] );     }     return 0; }

It do not work.
I've a problem and i know what is it but i don't know how to do.
It's for the nVault system.
Yes I open & close it and ... nothing :/

I don't know what can i use in this list : http://www.amxmodx.org/funcwiki.php?go=inc&id=41
If it is in this list...

Thank you in advance :D

Sherazaa 06-25-2012 13:00

Re: [ Request ] nvault & add / remove a plr
 
Quote:

Originally Posted by Aooka (Post 1735870)
@Sherazaa: Take just a look here : http://wiki.amxmodx.org/Pawn_Tutoria...nsional_Arrays :D

Ok, thanks :mrgreen:

Exolent[jNr] 06-25-2012 13:46

Re: [ Request ] nvault & add / remove a plr
 
1. You added a variable "iMenu" to your command callback. That does not exist. You cannot just add variables to a public function callback and expect it to work.
By that logic, I could do:
Code:
public VipMenu( id, Float:health, weapons[], attacker, all_players[] )
But no, you cannot do that.

2. Make the menu global so it can be accessed. Otherwise the handle is unused.

3. Don't destroy the menu, ever. It is created once and never again, so if you close it once, it is destroyed, and then you cannot access it anymore.

Aooka 06-25-2012 14:44

Re: [ Request ] nvault & add / remove a plr
 
Quote:

Originally Posted by Exolent[jNr] (Post 1735918)
But no, you cannot do that.

So what can i do for that ?
I test tomorrow thanks :D

Exolent[jNr] 06-25-2012 15:41

Re: [ Request ] nvault & add / remove a plr
 
Quote:

Originally Posted by Aooka (Post 1735953)
So what can i do for that ?
I test tomorrow thanks :D

Quote:

Originally Posted by Exolent[jNr] (Post 1735918)
2. Make the menu global



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

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