Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: MacTavish on Jul 24, 2015, 08:33 AM

Title: [Advanced] AFK system
Post by: MacTavish on Jul 24, 2015, 08:33 AM
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

Title: Re: [Advanced] AFK system
Post by: DizzasTeR on Jul 24, 2015, 08:47 AM
You could use Table/Array to store the nicks, why SQLite?
Title: Re: [Advanced] AFK system
Post by: MacTavish on Jul 24, 2015, 08:55 AM
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
Title: Re: [Advanced] AFK system
Post by: Thijn on Jul 24, 2015, 09:22 AM
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.
Title: Re: [Advanced] AFK system
Post by: MacTavish 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
Title: Re: [Advanced] AFK system
Post by: Ksna on Jul 24, 2015, 11:46 AM
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
Title: Re: [Advanced] AFK system
Post by: MacTavish on Jul 24, 2015, 11:58 AM
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
Title: Re: [Advanced] AFK system
Post by: DizzasTeR on Jul 24, 2015, 12:19 PM
You can still do that with array/table Beztone.
Title: Re: [Advanced] AFK system
Post by: MacTavish on Jul 24, 2015, 12:44 PM
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
Title: Re: [Advanced] AFK system
Post by: EK.IceFlake on Jul 24, 2015, 07:30 PM
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.
Title: Re: [Advanced] AFK system
Post by: MacTavish on Jul 25, 2015, 07:04 AM
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
Title: Re: [Advanced] AFK system
Post by: [VSS]Shawn on Jul 26, 2015, 01:51 PM
u didn't added oldname in playerclass
Title: Re: [Advanced] AFK system
Post by: MacTavish on Jul 26, 2015, 01:55 PM
Quote from: [VSS]Shawn on Jul 26, 2015, 01:51 PMu didn't added oldname in playerclass

Updated
Title: Re: [Advanced] AFK system
Post by: MacTavish on Oct 22, 2015, 02:49 PM
BUMP! System Updated To Table no more SQLite
@Thijn would you please clean the topic :) if you dont mind
Title: Re: [Advanced] AFK system
Post by: rulk on Oct 22, 2015, 05:32 PM
Its good to see you putting in the effort to learn from the advice given to you @Kusanagi

thumbs up from me :-)
Title: Re: [Advanced] AFK system
Post by: KAKAN on Oct 23, 2015, 04:28 PM
Nice update.
This would help the newbies very much.
Nice work. :)
Title: Re: [Advanced] AFK system
Post by: KAKAN on Oct 24, 2015, 06:29 AM
Just 1 suggestion( not a bug )
Add the same thing to onScriptUnload()
Because if someone uses this, and he shut-downs the server when someone had been AFK after killing 100 of players.
Will that guy be able to save his/her stats? Nope.
Title: Re: [Advanced] AFK system
Post by: MacTavish on Oct 24, 2015, 06:53 PM
Quote from: KAKAN on Oct 24, 2015, 06:29 AMJust 1 suggestion( not a bug )
Add the same thing to onScriptUnload()
Because if someone uses this, and he shut-downs the server when someone had been AFK after killing 100 of players.
Will that guy be able to save his/her stats? Nope.
I'll see about that but there are much things that you guys have to implement yourself such as checking nick before saving stats ( i believe that there are many servers those have timers that saves stats each 3 minutes) btw for onScriptUnload() you can create a loop that could change nick and save data of each player if it is possible
Title: Re: [Advanced] AFK system
Post by: KAKAN on Oct 25, 2015, 07:33 AM
Simple, add this in the onScriptUnload()
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.

}
Title: Re: [Advanced] AFK system
Post by: MacTavish on Oct 25, 2015, 09:57 AM
I already made this code last night but i lost internet :D

Updated
Title: Re: [Advanced] AFK system
Post by: KAKAN on Oct 25, 2015, 01:48 PM
Nice work.
After getting back from my trip.
I'll test it and have a full bug test.