Basic Stats System
Update:Changed the stats using class
Installation:Player ClassAdd this on the top of your scriptclass PlayerStats
{
kills = 0;
headshots = 0;
deaths = 0;
rank = 0;
}
OnScriptLoadfunction onScriptLoad()
{
stats <- ConnectSQL("stats.db");
QuerySQL(stats, "create table if not exists pstats ( Name TEXT, Rank TEXT, Kills INTEGER, Headshots INTEGER, Deaths INTEGER )");
}
onPlayerJoinfunction onPlayerJoin(player)
{
StatsInfo(player);
}
Command
function onPlayerCommand(player, command, arguments)
{
local cmd, text;
cmd = command.tolower();
text = arguments;
if(cmd == "stats")
{
if(!arguments)
{
MessagePlayer("[#FF0000]Information:[#FFFFFF] Your stats : ", player);
MessagePlayer("[#FFFFFF]Kills : " + stats[player.ID].kills + " Headshots : " + stats[player.ID].headshots + " Deaths : " + stats[player.ID].deaths + " Rank : " + stats[player.ID].rank + ".", player);
}
else
{
local plr = FindPlayer(arguments);
if(!plr) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Unknown Player", player);
else
{
local q = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + plr.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] "+plr.Name+ " stats : ", player);
MessagePlayer("[#FFFFFF]Kills : " + stats[player.ID].kills + " Headshots : " + stats[player.ID].headshots + " Deaths : " + stats[player.ID].deaths + " Rank : " + stats[player.ID].rank + ".", player);
}
}
}
else if(cmd == "resetstats")
{
if(!arguments) MessagePlayer("[#FF0000]Command Error:[#FFFFFF] Use /" + cmd + " [player] ", player);
else
{
local plr = FindPlayer(arguments);
if(!plr) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Invalid player", player);
else
{
Message("[#514FFF]Administrator Command:[#FFFFFF] Admin[" + player.Name + "] reseted stats of player : " + plr.Name+ ".");
MessagePlayer("[#FF0000]Information:[#FFFFFF] Your stats have been reseted by Admin " + player.Name + ".", plr);
QuerySQL(stats, "UPDATE pstats SET Rank = '1', Kills = '0', Deaths = '0', Headshots = '0' WHERE Name = '" + plr.Name + "'");
stats[plr.ID].kills = 0;
stats[plr.ID].deaths = 0;
stats[plr.ID].headshots = 0;
stats[plr.ID].rank = 1;
}
}
}
else if(cmd == "setstats")
{
if(!arguments)
{
MessagePlayer("[#FF0000]Command Error:[#FFFFFF] Use /" + cmd + " [player] [stats(0 - 3)] [value]", player);
MessagePlayer("0 = Rank, 1 = Kills, 2 = Headshots, 3 = Deaths", player);
}
else if(NumTok(arguments, " ") < 3 )
{
MessagePlayer("[#FF0000]Command Error:[#FFFFFF] Use /" + cmd + " [player] [stats(0 - 3)] [value]", player);
MessagePlayer("0 = Rank, 1 = Kills, 2 = Headshots, 3 = Deaths", player);
}
else if(!IsNum(GetTok(arguments, " ", 2))) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Stats should be between 0 - 4", player);
else if(!IsNum(GetTok(arguments, " ", 3))) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] value should be in numbers", player);
else if(GetTok(arguments, " ", 2).tointeger() < 0 ) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Stats should be between 0 - 4", player);
else if(GetTok(arguments, " ", 2).tointeger() > 4 ) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Stats should be between 0 - 4", player);
else if(GetTok(arguments, " ", 3).tointeger() < 0 ) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Minimum value is 0", player);
else
{
local plr = FindPlayer(GetTok(arguments, " ", 1));
local stat = GetTok(arguments, " ", 2).tointeger();
local val = GetTok(arguments, " ", 3).tointeger();
if(!plr) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Invalid player", player);
else
{
if(stat == 0)
{
if(val < 1) MessagePlayer("[#FF0000]Usage Error:[#FFFFFF] Rank cannot be less than 1", player);
else QuerySQL(stats, "UPDATE pstats SET Rank = '" + val + "' WHERE Name = '" + plr.Name + "'");
stats[plr.ID].rank = val;
Message("[#514FFF]Developer Command:[#FFFFFF] Developer[" + player.Name + "] set Player : " + plr.Name +"'s Rank to " + val + ".");
}
else if(stat == 1)
{
QuerySQL(stats, "UPDATE pstats SET Kills = '" + val + "' WHERE Name = '" + plr.Name + "'");
Message("[#514FFF]Developer Command:[#FFFFFF] Developer[" + player.Name + "]set Player : " + plr.Name + "'s Kills to " + val + ".");
stats[plr.ID].kills = val;
}
else if(stat == 2)
{
QuerySQL(stats, "UPDATE pstats SET HeadShots = '" + val + "' WHERE Name = '" + plr.Name + "'");
Message("[#514FFF]Developer Command:[#FFFFFF] Developer[" + player.Name + "] set Player : " + plr.Name+ "'s HeadShots to " + val + ".");
stats[plr.ID].headshots = val;
}
else if(stat == 3)
{
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + val + "' WHERE Name = '" + plr.Name + "'");
Message("[#514FFF]Developer Command:[#FFFFFF] Developer[" + player.Name + "] set Player : " + plr.Name+ "'s Deaths to " + val + ".");
stats[plr.ID].deaths = val;
}
}
}
}
}
Functionsfunction onPlayerKill(killer, player, reason, bodypart)
{
rankcheck(killer);
rankcheck(player);
if(bodypart == 6)
{
MessagePlayer("[#FFFFFF]You received $1000 bonus for killing through headshot", killer);
local pkill = stats[player.ID].kills + 1;
local phead = stats[player.ID].headshots + 1;
QuerySQL(stats, "UPDATE pstats SET Kills = '" + pkill + "' WHERE Name = '" + killer.Name + "'");
QuerySQL(stats, "UPDATE pstats SET Headshots = '" + phead + "' WHERE Name = '" + killer.Name + "'");
local pdeath = stats[player.ID].deaths + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '"+pdeath+"' WHERE Name = '"+player.Name+"'");
}
else
{
local q2 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + killer.Name + "'");
local pkill = GetSQLColumnData(q2, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Kills = '" + pkill + "' WHERE Name = '" + killer.Name + "'");
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '"+pdeath+"' WHERE Name = '"+player.Name+"'");
}
}
function onPlayerDeath( player, reason)
{
local pdeath = stats[player.ID].deaths + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
function rankcheck(player)
{
local q2 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name+ "'");
local ran = GetSQLColumnData(q2, 1).tointeger();
local kills = GetSQLColumnData(q2, 2).tointeger();
if(kills >= 5000 && ran < 8)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '8' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 5000 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
else if(kills >= 4000 && ran < 7 && kills < 5000)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '7' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 4000 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
else if(kills >= 3000 && ran < 6 && kills < 4000)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '6' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 3000 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
else if(kills >= 2000 && ran < 5 && kills < 3000)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '5' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 2000 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
else if(kills >= 1000 && ran < 4 && kills < 2000)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '4' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 1000 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
else if(kills >= 500 && ran < 3 && kills < 1000)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '3' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 500 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
else if(kills >= 100 && ran < 2 && kills < 500)
{
QuerySQL(stats, "UPDATE pstats SET Rank = '2' WHERE Name = '" + player.Name + "'");
MessagePlayer("[#FF0000]Information:[#FFFFFF] You have completed 100 kills. Now your rank is 8", player);
MessagePlayer("[#FF0000]Information:[#FFFFFF] You received 000 cash", player);
}
}
function StatsInfo(player)
{
local q = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '"+player.Name+"'");
if(!q) QuerySQL(stats, "INSERT INTO pstats ( Name, Rank, Kills, Headshots, Deaths ) VALUES ( '" + escapeSQLString(player.Name) + "', '1', '0', '0', '0' )");
else
{
stats[player.ID].kills = GetSQLColumnData(q, 2).tointeger();
stats[player.ID].headshots = GetSQLColumnData(q, 3).tointeger();
stats[player.ID].deaths = GetSQLColumnData(q, 4).tointeger();
stats[player.ID].rank = GetSQLColumnData(q, 1).tointeger();
}
}
function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
tokenized = split(string, separator),
text = "";
if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}
function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}
function GetPlayer( plr )
{
if ( plr )
{
if ( IsNum( plr ) )
{
plr = FindPlayer( plr.tointeger() );
if ( plr ) return plr;
else return false;
}
else
{
plr = FindPlayer( plr );
if ( plr ) return plr;
else return false;
}
}
else return false;
}
If any bug found, please inform me
@umar4911 Just one ERRoR i Have Death Function But IF The Player Killed Not Delet Cash And Not UPDATED.
// Function onplayerKill Its Work But Function onplayerDeath Not Working // Its Work Just not Delet Cash And NOT UPDATE Death For Stats
function onPlayerDeath( player, reason ,weapon )
{
DecCash( player, 100 );
Announce("Wasted",player,5);
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
function onPlayerDeath( player, weapon )
{
DecCash( player, 100 );
Announce("Wasted",player,5);
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
function onPlayerDeath( player, reason )
{
DecCash( player, 100 );
Announce("Wasted",player,5);
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
HELPPPPPPPPP
Delete all 3 onPlayerDeath functions and keep this one:
function onPlayerDeath( player, weapon )
{
DecCash( player, 100 );
Announce("Wasted",player,5);
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
@Xmair Niice Work But When i Do /kill Not UPDATED // Lets Me tell You
That Function Its UPDATE If Kill With Weaponfunction onPlayerDeath( player, weapon )
{
DecCash( player, 100 );
Announce("Wasted",player,5);
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
That Its UPDATED Just If Player Do /killfunction onPlayerDeath( player, reason )
{
DecCash( player, 100 );
Announce("Wasted",player,5);
local q3 = QuerySQL(stats, "SELECT * FROM pstats WHERE Name = '" + player.Name + "'");
local pdeath = GetSQLColumnData(q3, 2).tointeger() + 1;
QuerySQL(stats, "UPDATE pstats SET Deaths = '" + pdeath + "' WHERE Name = '" + player.Name + "'");
rankcheck(player);
}
Hmm Can Make Two Function ?
I'm out.
Quote from: Xmair on Dec 02, 2017, 02:17 PMI'm out.
:( Do You Have Any Solution Of it :/
Quote from: Mohamed on Dec 02, 2017, 02:23 PMQuote from: Xmair on Dec 02, 2017, 02:17 PMI'm out.
:( Do You Have Any Solution Of it :/
You cant make 2 functions and death cant be with weapon. It is always playerkill as their is always killer
@umar4911 I Fixed All, Now I Have just one Problem, OnPlayerDeath Not UPDATE :(
Quote from: Mohamed on Dec 02, 2017, 03:12 PM@umar4911 I Fixed All, Now I Have just one Problem, OnPlayerDeath Not UPDATE :(
give info
@umar4911 Problem Solved By Me.
Thanks Very much For it i Really Happy :D
@umar4911 That iTs Work But If Me Death i Will Not UPDATED After 5min then i do /kill // then UPDATED
i Want UPDATE AUTO :( Same OnplayerKill :'(
Quote from: Mohamed on Dec 02, 2017, 08:53 PM@umar4911 That iTs Work But If Me Death i Will Not UPDATED After 5min then i do /kill // then UPDATED
i Want UPDATE AUTO :( Same OnplayerKill :'(
I cant understand what are you saying
Nice idea, however I prefer to add up the kills/deaths on the class & save the class in the database once the player leaves. FYI, "Installion" is spelled wrong in which it's spelled "Installation". :3 Your welcome.
Btw My Problem of PlayerDeath Fixed :D
Garbage
Quote from: kennedyarz on Dec 03, 2017, 08:19 PMGarbage
At least he has done something not like being a n*** and asking everyone to make something for him don't forget we all were newbie in past. >:(
Just look at your post while newbie
Quote from: kennedyarz on Mar 19, 2016, 01:11 AMnot hear but every time I ask for help always get a negative response departe scripters I would like to at least give me the registration function for my server because it makes me much needed, this time I would like that was not as usual
;D
Quote from: KuRiMi on Dec 03, 2017, 05:06 PMNice idea, however I prefer to add up the kills/deaths on the class & save the class in the database once the player leaves. FYI, "Installion" is spelled wrong in which it's spelled "Installation". :3 Your welcome.
I thought of adding class. Now I will modify as I reach my pc and thank you for telling me :P
Edit: Fixed
Quote from: ! on Dec 03, 2017, 09:14 PMQuote from: kennedyarz on Dec 03, 2017, 08:19 PMGarbage
At least he has done something not like being a n*** and asking everyone to make something for him don't forget we all were newbie in past. >:(
Just look at your post while newbie
Quote from: kennedyarz on Mar 19, 2016, 01:11 AMnot hear but every time I ask for help always get a negative response departe scripters I would like to at least give me the registration function for my server because it makes me much needed, this time I would like that was not as usual
;D
You're right, but I say it because it does not work for me since I do not work with those scripts
@umar4911 Its Working Keep Up Bro. :D
Quote from: kennedyarz on Dec 04, 2017, 01:11 PMYou're right, but I say it because it does not work for me since I do not work with those scripts
Yep just checked the snippet and found a bug in resetstats :)
stats[player.ID].kills = 0;
stats[player.ID].deaths = 0;
stats[player.ID].headshots = 0;
stats[player.ID].rank = 1;
@umar4911 change it to
stats[plr.ID].kills = 0;
stats[plr.ID].deaths = 0;
stats[plr.ID].headshots = 0;
stats[plr.ID].rank = 1;
Quote from: ! on Dec 06, 2017, 10:58 AMQuote from: kennedyarz on Dec 04, 2017, 01:11 PMYou're right, but I say it because it does not work for me since I do not work with those scripts
Yep just checked the snippet and found a bug in resetstats :)
stats[player.ID].kills = 0;
stats[player.ID].deaths = 0;
stats[player.ID].headshots = 0;
stats[player.ID].rank = 1;
@umar4911 change it to
stats[plr.ID].kills = 0;
stats[plr.ID].deaths = 0;
stats[plr.ID].headshots = 0;
stats[plr.ID].rank = 1;
I forgot to change to plr. Thank you.
Updated
P.S: kennedyarz replied before changing it to class
PLZ HOW TO DOWNLOAD ???
Quote from: Bninin.. on Dec 09, 2017, 02:46 PMPLZ HOW TO DOWNLOAD ???
Copy and paste code to text file? Jesus, too many idiots have recently registered in this forum...
why commmands not work for me i am doing this in anik register systeam
i am using this plugins : ini04rel32 squirrel04rel32 xmlconf04rel32 announce04rel32 sockets04rel32 hashing04rel32 sqlite04rel32 mysql04rel32
Quote from: =RK=MarineForce on Dec 18, 2017, 09:18 PMwhy commmands not work for me i am doing this in anik register systeam
i am using this plugins : ini04rel32 squirrel04rel32 xmlconf04rel32 announce04rel32 sockets04rel32 hashing04rel32 sqlite04rel32 mysql04rel32
Must be problem in copy pasting. See the playerclass as it already exists in anik registration system. See the function
all function nice works
i will send you script on pm you save him cmds okay
have problem
if i am do /stats
its show only [#FF0000] Your Stats:
Quote from: =RK=MarineForce on Dec 19, 2017, 05:39 PMhave problem
if i am do /stats
its show only [#FF0000] Your Stats:
What is the error and what is the code of stats cmd which you are using
Not Working For Me.
I Just Create one Line, And is all UPDATED and Sample Not a DataBase.
But Thanks For Your help :P