[Advanced] AFK system

Started by MacTavish, Jul 24, 2015, 08:33 AM

Previous topic - Next topic

MacTavish

Away From Keyboard System

onScriptLoad()
{
pAway <- {};
oldname <- array( GetMaxPlayers(), null );
}

function onScriptUnload(){
local I, player, mp = GetMaxPlayers();
for(I = 0; I < mp; ++I ){ // place it in first line
player = FindPlayer( I )
if (pAway.rawin(oldname[player.ID]))
{
player.Name = ""+oldname[player.ID]+"";
pAway.rawdelete( player.Name );
oldname[player.ID] = null;
}
}
//Your shitty codes here.

}

function onPlayerJoin( player )
{
if(pAway.rawin(player.Name))
{
Message("Kicked "+player.Name+", Reason: A player with same nick already exist");
 player.Kick();
}
}

function onPlayerPart( player, reason )
{
if (pAway.rawin(oldname[player.ID])) // place it in first line
{
player.Name = ""+oldname[player.ID]+"";
pAway.rawdelete( player.Name );
oldname[player.ID] = null;
}
}
function onPlayerChat(player, text)
{
if ( text == "afk" || text == "AFK" )
{
if (pAway.rawin(oldname[player.ID])) MessagePlayer("Failure - You Have Already Used AFK, try BACK Instead",player);
else{
Message(player+" Is Now AFK!");
EchoMessage(player+" Is Now AFK!");
oldname[player.ID]= player.Name;
pAway.rawset(player.Name, "afk");
player.Name = ""+player.Name+"(AFK)";
}
}
else if ( text == "back" || text == "BACK" )
{
if (!pAway.rawin(oldname[player.ID])) MessagePlayer("Failure - You Haven't Used AFK",player);
else{
Message(""+oldname[player.ID]+" Is Now Back!");
EchoMessage(""+oldname[player.ID]+" Is Now Back!");
player.Name = ""+oldname[player.ID]+"";
pAway.rawdelete( player.Name );
oldname[player.ID] = null;
}
}
return 1;
}


Updated: On Table now Thanks To @rulk and @NE.CrystalBlue For Examples


Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

DizzasTeR

You could use Table/Array to store the nicks, why SQLite?

MacTavish

Quote from: Doom_Killer on Jul 24, 2015, 08:47 AMYou could use Table/Array to store the nicks, why SQLite?
Bro i created this months ago, i was working on GHP script and stopped working, SQlite felt me easy to create it faster.

Btw could you tell me about the saving nick and status in array

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

Indeed, why make it so laggy when you already set someone's status back when they leave. SQLite is better for saving persistent data, that needs to survive server restarts.

MacTavish

#4
Quote from: Thijn on Jul 24, 2015, 09:22 AMIndeed, why make it so laggy when you already set someone's status back when they leave. SQLite is better for saving persistent data, that needs to survive server restarts.

You mean this is better with sqlite,

@Thijn

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Ksna

#5
Quote from: Beztone on Jul 24, 2015, 09:27 AM
Quote from: Thijn on Jul 24, 2015, 09:22 AMIndeed, why make it so laggy when you already set someone's status back when they leave. SQLite is better for saving persistent data, that needs to survive server restarts.
You mean this is better with sqlite,
@Thijn
No, he says not to use sqlite and your making this afk off after he leaves server and if you want to use database use only if you want to save  even after server restarts but your turned it off . so what is the use of database which just creates lag better make a array/table

MacTavish

#6
I used that in onPlayerPart because if the player nick remains as afk then the server wont save the stats data.

Beztone(afk) left server

Error nick not found in accounts table ( stats lost )

But if use PartWhenAway then

Beztone left server nick founded (stats saved)

I'd tested everything before releasing it

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

DizzasTeR

You can still do that with array/table Beztone.

MacTavish

Quote from: Doom_Killer on Jul 24, 2015, 12:19 PMYou can still do that with array/table Beztone.

Ok i will update the topic when i'll done that

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

EK.IceFlake

#9
You do not return 1 in onPlayerChat. This will cause chat messages by players to not appear.
At the top, you use "\\" for commenting. This will return a compiletime syntax error.

MacTavish

Quote from: NE.CrystalBlue on Jul 24, 2015, 07:30 PMYou do not return 1 in onPlayerChat. This will cause chat messages by players to not appear.

That was not necessary because everyone already had that in their scripts, btw added

Quote from: NE.CrystalBlue on Jul 24, 2015, 07:30 PMAt the top, you use "\" for commenting. This will return a compiletime syntax error.

I was confused about text ignoring slashes thanks

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

[VSS]Shawn

u didn't added oldname in playerclass

MacTavish


Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

MacTavish

#13
BUMP! System Updated To Table no more SQLite
@Thijn would you please clean the topic :) if you dont mind

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

rulk

Its good to see you putting in the effort to learn from the advice given to you @Kusanagi

thumbs up from me :-)
We are all god's children.