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

Unset array key


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WillCz
Junior Member
Join Date: Mar 2010
Old 09-07-2010 , 12:52   Unset array key
Reply With Quote #1

Hello,
I'm trying to write a plugin that mutes every player on player_death event, I managed to mute players and write this state into an array. However I would like to clean (empty) the array on round_start... Is there a solution?

Muting is performed this way:
PHP Code:
PerformMute(target)
{
  new 
userId GetClientUserId(target);
    
muted[mutedCount++] = userId;
    
SetClientListeningFlags(targetVOICE_MUTED);

I need simply clean the array so it would contain no keys and then reset the counter.
WillCz is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 09-07-2010 , 13:01   Re: Unset array key
Reply With Quote #2

Code:
for (new i = 0; i < sizeof muted; ++i) muted[i] = -1;

?
Seta00 is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 09-07-2010 , 13:20   Re: Unset array key
Reply With Quote #3

Quote:
Originally Posted by Seta00 View Post
Code:
for (new i = 0; i < sizeof muted; ++i) muted[i] = -1;


?
*
PHP Code:
for(new 0sizeof(muted); i++)
muted 0
If he wants to set it as new. Because new = nulled.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
WillCz
Junior Member
Join Date: Mar 2010
Old 09-07-2010 , 14:49   Re: Unset array key
Reply With Quote #4

Okay, I've got following and still won't work: (I'm getting only one message of player unmute instead of multiple which should be in the array)
PHP Code:
PerformMute(target)
{
  new 
userId GetClientUserId(target);
    
muted[mutedCount++] = userId;
    
PrintToChatAll("DEBUG: muting player %d"userId);
}

PerformUnMute(target)
{
    new 
userId GetClientUserId(target);
    
PrintToChatAll("DEBUG: unmuting player %d"userId);
}

public 
Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
  new 
client GetClientOfUserId(GetEventInt(event"userid"));
  if(!(
GetUserFlagBits(client) & ADMFLAG_KICK))
  {
    
PerformMute(client);
  }
  else
  {
    
PrintToChatAll("DEBUG: %d is admin"GetEventInt(event"userid"));
  }
  return 
Plugin_Continue;
}

public 
Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
  
PrintToChatAll("Muted count: %d"mutedCount);
  for(new 
0mutedCounti++)
  {
    
PerformUnMute(GetClientOfUserId(muted[i]));
  }
  
mutedCount 0;
  
  
PrintToChatAll("All players can now speak.");
  
PrintToChatAll("Muted count: %d"mutedCount);
  return 
Plugin_Continue;

My problem is that all code in roundstart won't be executed (i.e. i'm getting muted count: 8, unmuting player: xxx and nothing more - 1 unmute instead of 8 and additional display of 2 another messages)
WillCz is offline
WillCz
Junior Member
Join Date: Mar 2010
Old 09-09-2010 , 15:25   Re: Unset array key
Reply With Quote #5

I'm getting these messages in error log, what I'm doing wrong?
Code:
L 09/09/2010 - 21:23:49: [SM] Native "GetClientUserId" reported: Client index 0 is invalid
L 09/09/2010 - 21:24:14: [SM] Plugin encountered error 15: Array index is out of bounds
WillCz is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 09-09-2010 , 15:41   Re: Unset array key
Reply With Quote #6

How is your muted array declared?
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
WillCz
Junior Member
Join Date: Mar 2010
Old 09-09-2010 , 16:14   Re: Unset array key
Reply With Quote #7

Code:
new muted[MAXPLAYERS+1];
new mutedCount = 0;
What I've seen on the server, the counter even does not reset, on one map the muted count goes to hundreds, (i.e. muted count: 918, no-one unmuted)
WillCz is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 09-09-2010 , 16:54   Re: Unset array key
Reply With Quote #8

You should remove the mute on disconnected players as well, otherwise if various muted players disconnect you'll keep getting array index out of bounds errors.
Seta00 is offline
WillCz
Junior Member
Join Date: Mar 2010
Old 09-10-2010 , 10:42   Re: Unset array key
Reply With Quote #9

Is there any way how to imitate the foreach cycle in SourcePawn? In PHP, I would write something like this:
PHP Code:
$muted = array();

foreach(
$muted as $key => $player)
{
  
PerformUnMute($key);
}

$muted = array(); // Resetting array

// ------ client disconnect -------
function onClientDisconnect($client)
{
  global 
$muted;
  
$key getUserIdOfClient($client)
  unset(
$muted[$key]);
}

// ------ death -------
function Event_PlayerDeath($client)
{
  global 
$muted;
  
$userid GetClientUserId($client);
  
$muted[$userid] = TRUE;
  
PerformMute($client);

Also, it is possible to use sizeof function on arrays?

Last edited by WillCz; 09-10-2010 at 11:00.
WillCz is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 09-10-2010 , 16:36   Re: Unset array key
Reply With Quote #10

Quote:
Originally Posted by WillCz View Post
Is there any way how to imitate the foreach cycle in SourcePawn? In PHP, I would write something like this:
PHP Code:
$muted = array();

foreach(
$muted as $key => $player)
{
  
PerformUnMute($key);
}

$muted = array(); // Resetting array 
No, use a normal for and index the array properly:
PHP Code:
for (new 0sizeof array; ++i) {
    
PerformMute(array[i]);

Quote:
Also, it is possible to use sizeof function on arrays?
Yes, see code above.
Seta00 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 13:08.


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