Raised This Month: $51 Target: $400
 12% 

ArrayDeleteItem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 03-30-2021 , 20:41   ArrayDeleteItem
Reply With Quote #1

just wanted to make a menu to show connected vips, but something is wrong with ArrayDeleteItem, it seems deleting the string doesn't work, i think i need to get id from array but don't know how.
Can someone help me?

Code:
#include < amxmodx >
#include < amxmisc >

new Array: g_aNames;
new g_playerName [ 33 ] [ 32 ];

public plugin_init ( )
{
	register_plugin ( "[ZP] Online VIPS", "1.0", "LondoN eXtream" );

	g_aNames = ArrayCreate ( 32 );

	register_clcmd ( "say /vips", "clcmd_show" );
}

public clcmd_show ( iEntity )
{
	if ( !ArraySize ( g_aNames ) )
	{
		client_print ( iEntity, print_chat, "No online vips." );
		return;
	}

	new sTempString [ 32 ];
	new MenuID = menu_create ( "\wOnline Gold Members", "func_ignore" );
	
	for ( new i; i < ArraySize ( g_aNames ); i++ )
	{
		ArrayGetString ( g_aNames, i, sTempString, charsmax ( sTempString ) );

		menu_additem ( MenuID, "\w%s", sTempString );
	}

	menu_setprop ( MenuID, MPROP_EXIT, MEXIT_ALL );
	menu_display ( iEntity, MenuID, 0 );
}

public func_ignore ( a, b, c )
{
	menu_destroy ( b );
	return;
}

public client_putinserver ( iEntity )
{
	if ( is_user_bot ( iEntity ) || is_user_hltv ( iEntity ) )
		return;

	get_user_name ( iEntity, g_playerName [ iEntity ], charsmax ( g_playerName ) );

	if ( get_user_flags ( iEntity ) & ADMIN_LEVEL_H )
		ArrayPushString ( g_aNames, g_playerName [ iEntity ] );
}

public client_disconnect ( iEntity )
{
	if ( is_user_bot ( iEntity ) || is_user_hltv ( iEntity ) )
		return;

	if ( get_user_flags ( iEntity ) & ADMIN_LEVEL_H )
	{
		if ( ArrayFindString ( g_aNames, g_playerName [ iEntity ] ) )
			ArrayDeleteItem ( g_aNames, g_playerName [ iEntity ] );
	}
}

public plugin_end ( )
	ArrayDestroy ( g_aNames );
__________________
LondoN is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-30-2021 , 20:44   Re: ArrayDeleteItem
Reply With Quote #2

Try:
PHP Code:
new iItemIndex ArrayFindString g_aNamesg_playerName iEntity ] );
    
if ( 
iItemIndex != -)
    
ArrayDeleteItem g_aNamesiItemIndex ); 
__________________
Bugsy is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 03-30-2021 , 20:48   Re: ArrayDeleteItem
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Try:
PHP Code:
new iItemIndex ArrayFindString g_aNamesg_playerName iEntity ] );
    
if ( 
iItemIndex != -)
    
ArrayDeleteItem g_aNamesiItemIndex ); 
/tmp/text4AoT4q.sma(64) : error 035: argument type mismatch (argument 2)
/tmp/text4AoT4q.sma(67) : error 035: argument type mismatch (argument 2)

online compiler.
it seems the amxmodx.org/webcompiler.cgi doesn't support ArrayFindString, i need to manually add in header native ArrayFindString(Array:what, item); so, other way exists?

Code:
public client_disconnect ( iEntity )
{
	if ( is_user_bot ( iEntity ) || is_user_hltv ( iEntity ) )
		return;

	if ( get_user_flags ( iEntity ) & ADMIN_LEVEL_H )
	{
		new id = ArrayFindString ( g_aNames, g_playerName [ iEntity ] );
		
		if ( id != 0 )
			ArrayDeleteItem ( g_aNames, g_playerName [ iEntity ] );
	}
}
not working, not compiling
__________________

Last edited by LondoN; 03-30-2021 at 20:48.
LondoN is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-30-2021 , 21:14   Re: ArrayDeleteItem
Reply With Quote #4

Should be correct based on this

How is g_playerName [ iEntity ] defined? I am assuming this is a 2d array, holding strings.
__________________

Last edited by Bugsy; 03-30-2021 at 21:14.
Bugsy is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 03-30-2021 , 21:19   Re: ArrayDeleteItem
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Should be correct based on this

How is g_playerName [ iEntity ] defined? I am assuming this is a 2d array, holding strings.
Code:
new g_playerName [ 33 ] [ 32 ];
Code:
public client_putinserver ( iEntity )
{
	if ( is_user_bot ( iEntity ) || is_user_hltv ( iEntity ) )
		return;

	get_user_name ( iEntity, g_playerName [ iEntity ], charsmax ( g_playerName ) );

	if ( get_user_flags ( iEntity ) & ADMIN_LEVEL_H )
		ArrayPushString ( g_aNames, g_playerName [ iEntity ] );
}
Online compiler gives me errors, but idk why since i'm using some default natives, nothing new.
__________________
LondoN is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-30-2021 , 21:31   Re: ArrayDeleteItem
Reply With Quote #6

It's working fine for me on a very old 1.9 build

PHP Code:
new Array:aTest ArrayCreate32 );
    
ArrayPushStringaTest "bugsy1" ); 
ArrayPushStringaTest "bugsy2" ); 
ArrayPushStringaTest "bugsy3" ); 
ArrayPushStringaTest "bugsy4" ); 
ArrayPushStringaTest "bugsy5" ); 
    
new 
iItemIndex ArrayFindString aTest"bugsy3" );
    
if ( 
iItemIndex != -)
{
    
server_print"bugsy3 found at %d" iItemIndex );
    
ArrayDeleteItem aTestiItemIndex );

Output:
Code:
bugsy3 found at 2
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:12.


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