[Basic] Ignore/Unignore snippet

Started by DizzasTeR, Aug 10, 2017, 05:19 PM

Previous topic - Next topic

DizzasTeR

Some people and friends were having troubles coding one so I decided to take 3 mins challenge and test this out. Some conditions and logical stuff might be missing from commands but ofcourse its just a basic template to give an idea. It still works and it is tested ;)

g_Ignores <- {};

function onPlayerJoin( player ) {
g_Ignores.rawset( player.ID, {} );
}

function onPlayerPart( player, reason ) {
if( g_Ignores.rawin( player.ID ) ) {
g_Ignores.rawdelete( player.ID );
}
}

function onPlayerCommand( player, cmd, text ) {
if( cmd == "ignore" ) {
if( !text ) return MessagePlayer( "/ignore [ID/Name]", player );
local plr = ( !IsNum( text ) ? FindPlayer( text ) : FindPlayer( text.tointeger() ) );
if( !plr ) return MessagePlayer( "Invalid player", player );
else if( g_Ignores.rawget( player.ID ).rawin( plr.ID ) ) return MessagePlayer( format( "You are already ignoring %s", plr.Name ), player );
g_Ignores.rawget( player.ID ).rawset( plr.ID, true );
MessagePlayer( format( "You are not ignoring %s", plr.Name ), player );
}

else if( cmd == "unignore" ) {
if( !text ) return MessagePlayer( "/unignore [ID/Name]", player );
local plr = ( !IsNum( text ) ? FindPlayer( text ) : FindPlayer( text.tointeger() ) );
if( !plr ) return MessagePlayer( "Invalid player", player );
else if( !g_Ignores.rawget( player.ID ).rawin( plr.ID ) ) return MessagePlayer( format( "You are not ignoring %s", plr.Name ), player );
g_Ignores.rawget( player.ID ).rawdelete( plr.ID );
MessagePlayer( format( "You are no longer ignoring %s", plr.Name ), player );
}
}

function onPlayerChat( player, text ) {
local playerIgnores = g_Ignores.rawget( player.ID );
local MaxPlayers = GetMaxPlayers();
for( local i = 0; i <= MaxPlayers; i++ ) {
local plr = FindPlayer( i );
if( !plr ) continue;
local plrIgnores = g_Ignores.rawget( plr.ID );

if( playerIgnores.rawin( plr.ID ) ) continue;
else if( plrIgnores.rawin( player.ID ) ) continue;
MessagePlayer( format( "%s: %s", player.Name, text ), plr );
}
return 0; //You must halt the event itself to avoid double chats
}

KAKAN

You should paste it in pastebin or somewhere else. This forum f* up formatting and its spacing and Squirrel don't go well.
oh no

DizzasTeR