« on: November 15, 2022, 12:39:19 pm »
Crew System
Crew ClassInCrew = false;
Crew = null;
CrewTag = null;
Inviter = null;
InvReq=false;
on Script Loadcdb <- ConnectSQL("dataBase/crew.db");
QuerySQL(cdb,"CREATE TABLE IF NOT EXISTS Crews( cName VARCHAR(25), cTag VARCHAR(5), cOWNER VARCHAR(25), cKills INTEGER, cDeaths INTEGER, cMoney INTEGER ) ");
QuerySQL(cdb, "CREATE TABLE IF NOT EXISTS Members( cName VARCHAR(25), cTag VARCHAR(5), Player VARCHAR(30) ) ");
function(s)function cInfo(player)
{
local q = QuerySQL(cdb, "SELECT * FROM Members WHERE Player = '" + escapeSQLString(player.Name) + "'");
if(q) {
stats[player.ID].Crew = GetSQLColumnData(q, 0);
stats[player.ID].CrewTag = GetSQLColumnData(q, 1);
stats[player.ID].InCrew = true;
}
else {
stats[player.ID].Crew = null;
stats[player.ID].CrewTag = null;
stats[player.ID].InCrew = false;
}
}
function InvReq(playerID,plrID)
{
local player = FindPlayer(playerID), plr = FindPlayer(plrID);
if(stats[plr.ID].InvReq){
stats[plr.ID].InvReq=false;
MessagePlayer("[#ffff4d]The crew invitation sent by [#ffffff]"+player.Name+" [#ffff4d]has been timed out.",plr);
MessagePlayer("[#ffff4d]The crew invitation you sent to [#ffffff]"+plr.Name+"[#ffff4d] has been timed out.",player);
}
}
on Player JoincInfo(player);
on Player Death if (stats[player.ID].InCrew)
{
local q = QuerySQL(cdb, "SELECT * FROM Crews WHERE cName ='"+stats[player.ID].Crew+"'");
local deaths = GetSQLColumnData(q,4);
deaths++;
QuerySQL( cdb, "UPDATE Crews SET cDeaths='"+deaths+"' WHERE cName LIKE '" + stats[player.ID].Crew + "'" );
}
on Player Kill if (stats[killer.ID].InCrew)
{
local q = QuerySQL(cdb, "SELECT * FROM Crews WHERE cName ='"+stats[player.ID].Crew+"'");
local kills = GetSQLColumnData(q,3);
local money = GetSQLColumnData(q,5);
kills++;
money++;
QuerySQL( cdb, "UPDATE Crews SET cKills='"+Kills+"' WHERE cName LIKE '" + stats[player.ID].Crew + "'" );
QuerySQL( cdb, "UPDATE Crews SET cMoney='"+money+"' WHERE cName LIKE '" + stats[player.ID].Crew + "'" );
}
on Player Commandif( cmd == "addcrew" )
{
if(!text) MessagePlayer("[#ff4d4d]/addc <crew name> <crew tag>",player);
local texta = GetTok( text, " ", 1);
local textb = GetTok( text, " ", 2);
if(textb == null) MessagePlayer("[#ff4d4d]/addc <crew name> <crew tag>",player);
else if (stats[player.ID].InCrew) return MessagePlayer("[#ff4d4d]You are already in a crew.",player);
else {
local q = QuerySQL(cdb, "SELECT * FROM Crews WHERE cName ='"+texta+"' ");
if(q && texta == GetSQLColumnData(q,0)) return MessagePlayer("[#ff4d4d]There's already a crew with this name, please try another.",player);
else {
MessagePlayer("[#ffff4d]Crew Added: Name: [#ff9966]"+texta+" [#ffffff]| [#ffff4d]Tag: [#ff9966]"+textb+" [#ffffff]| [#ffff4d]Owner: [#ff9966]"+player.Name+"",player);
QuerySQL(cdb,"INSERT INTO Crews(cName, cTag, cOWNER, cKills, cDeaths, cMoney) VALUES('"+texta+"', '"+textb+"', '"+escapeSQLString(player.Name)+"', '"+0+"', '"+0+"', '"+0+"')");
QuerySQL(cdb,"INSERT INTO Members(cName, cTag, Player) VALUES('"+texta+"', '"+textb+"', '"+escapeSQLString(player.Name)+"') ");
stats[player.ID].Crew = texta;
stats[player.ID].CrewTag = textb;
stats[player.ID].InCrew = true;
}
}
}
else if (cmd == "joincrew")
{
if (!stats[player.ID].InvReq) return MessagePlayer("[#ff4d4d]You haven't recieved any invitation.",player);
else if (stats[player.ID].InCrew) return MessagePlayer("[#ff4d4d]You are already in a crew.",player);
else {
local plr = FindPlayer( stats[ player.ID ].Inviter );
QuerySQL(cdb,"INSERT INTO Members(cName, cTag, Player) VALUES('"+stats[plr.ID].Crew+"', '"+stats[plr.ID].CrewTag+"', '"+escapeSQLString(player.Name)+"') ");
cInfo(player);
MessagePlayer("[#ffff4d]You have joined [#ff9966]"+stats[player.ID].Crew+"",player);
MessagePlayer("[#ffffff]"+player.Name+"[#ffff4d] has joined your crew",plr);
stats[player.ID].InvReq=false;
}
}
else if (cmd == "cc" || cmd == "crewchat")
{
if (!text) MessagePlayer("/"+cmd+" text",player);
else if (!stats[player.ID].InCrew) return MessagePlayer("[#ff4d4d]You are not in any crew.",player);
else {
for (local i=0;i<GetMaxPlayers();i++) {
local plr = FindPlayer(i);
if(stats[player.ID].Crew == stats[i].Crew) {
MessagePlayer("[#ffff4d]"+player.Name+": [#ff9966]"+text+"",plr);
}
}
}
}
else if (cmd == "crew"){
if(stats[player.ID].InCrew==false)return MessagePlayer("[#ff4d4d]You are not in any crew.",player);
else {
local q = QuerySQL(cdb, "SELECT * FROM Crews WHERE cName = '"+stats[player.ID].Crew+"' ");
if(q){
local a = GetSQLColumnData(q,0);
local b = GetSQLColumnData(q,1);
local c = GetSQLColumnData(q,5);
local d = GetSQLColumnData(q,3);
local e = GetSQLColumnData(q,4);
local f = GetSQLColumnData(q,2);
MessagePlayer("[#ffff4d]Crew: [#ff9966]"+a+" ["+b+"] [#ffff4d]Money: [#ff9966]$"+c+" [#ffffff]| [#ffff4d]Kills: [#ff9966]"+d+" [#ffff4d]Deaths: [#ff9966]"+e+"",player);
MessagePlayer("[#ffff4d]Crew Owned by [#ff9966]"+f+"",player);
}
}
}
else if (cmd == "invite")
{
if (!text) MessagePlayer("[#ff4d4d]/invite player",player);
else if (!stats[player.ID].InCrew) return MessagePlayer("[#ff4d4d]You aren't in any crew.",player);
else {
local plr = FindPlayer(text);
if (!plr) MessagePlayer("Unknown player",player);
else if (stats[plr.ID].InCrew) return MessagePlayer("[#ff4d4d]Requested player is already in a crew.",player);
else {
MessagePlayer("[#ffff4d]You have sent crew invitation to [#ffffff]"+plr.Name+"",player);
MessagePlayer("[#ffffff]"+player.Name+" [#ffff4d]has asked you to join his crew: [#ff9966]"+stats[player.ID].Crew+"",plr);
stats[plr.ID].Inviter = player.Name;
stats[plr.ID].InvReq = true;
NewTimer( "InvReq", 5000, 1, player.ID,plr.ID);
}
}
}
else if (cmd == "leavecrew")
{
if (!stats[player.ID].InCrew) return MessagePlayer("[#ff4d4d]You are not in any crew.",player);
else {
local q = QuerySQL(cdb,"SELECT * FROM Crews WHERE cOWNER = '"+escapeSQLString(player.Name)+"' ");
if (q && player.Name == GetSQLColumnData(q,2)) {
MessagePlayer("[#ff4d4d]You cannot leave the crew because you are the owner.",player);
}
else {
stats[player.ID].InCrew = false;
stats[player.ID].CrewTag = "null";
QuerySQL( cdb, "DELETE FROM Members WHERE Player='"+player.Name+"'" );
MessagePlayer("[#ffff4d]You have left the crew: [#ff9966]"+stats[player.ID].Crew+"",player);
stats[player.ID].Crew = "null";
}
}
}
else if (cmd == "crewcmds")
{
MessagePlayer("[#ff9966]/addcrew | /invite | /joincrew | /leavecrew | /crew | /crewchat(cc)",player);
}
Total commands (6): /addcrew | /invite | /joincrew | /leavecrew | /crew | /crewchat(cc).
« Last Edit: November 15, 2022, 12:45:01 pm by GiTo »
Logged
Winner x 1 (list)
What happens when the poison expires?