Crew/Gang sys-

Started by Gito Baloch, Nov 15, 2022, 12:09 PM

Previous topic - Next topic

Gito Baloch

Crew System


Crew Class

[noae][noae][noae][noae]InCrew = false;
Crew = null;
CrewTag = null;
Inviter = null;
InvReq=false;
[/noae][/noae][/noae][/noae]

on Script Load
[noae][noae][noae][noae]cdb <- 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) ) ");
[/noae][/noae][/noae][/noae]


function(s)
[noae][noae][noae][noae]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);

}
}
[/noae][/noae][/noae][/noae]

on Player Join
[noae][noae][noae][noae]cInfo(player);[/noae][/noae][/noae][/noae]


on Player Death
[noae][noae][noae][noae]        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 + "'" );
}
[/noae][/noae][/noae][/noae]
on Player Kill
[noae][noae][noae][noae]        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 + "'" );
}
[/noae][/noae][/noae][/noae]

on Player Command
[noae][noae][noae][noae]if( 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);
}
[/noae][/noae][/noae][/noae]

Total commands (6): /addcrew | /invite | /joincrew | /leavecrew | /crew | /crewchat(cc).


Programming is the language I speak, the world I shape, and the future I code

UncleRus

Gito Baloch,create script server XD
I LoperkinDead.My brothers scripters TimyrSem,VladSem

H.a.S.a.N

Good job that best from clan system

gamingpro


gamingpro

Nice Pro Good job <3

H.a.S.a.N

but this have errors in cosole onscriptload
try this
```
cdb <- ConnectSQL( "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) ) ");
 Stats <- array( GetMaxPlayers(), null );
```

gamingpro


Gito Baloch

Quote from: H.a.S.a.N on Mar 20, 2023, 07:37 PMbut this have errors in cosole onscriptload
try this
```
cdb <- ConnectSQL( "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) ) ");
 Stats <- array( GetMaxPlayers(), null );
```

What is the bug here? Can you share a picture of the console?
Programming is the language I speak, the world I shape, and the future I code

H.a.S.a.N

AN ERROR HAS OCCURED [parameter 1 has an invalid type 'null' ; expected: 'userdata']
CALLSTACK
*FUNCTION [onScriptLoad()] scripts/main.nut line [128]
*FUNCTION [unknown()]  line [1]
LOCALS
[this] TABLE
[gamemode_event] CLOSURE
[filterscript_event] NATIVECLOSURE
[this] TABLE
This error


Ridwan Rz

Quote from: H.a.S.a.N on Apr 29, 2023, 08:16 AMAN ERROR HAS OCCURED [parameter 1 has an invalid type 'null' ; expected: 'userdata']
CALLSTACK
*FUNCTION [onScriptLoad()] scripts/main.nut line [128]
*FUNCTION [unknown()]  line [1]
LOCALS
[this] TABLE
[gamemode_event] CLOSURE
[filterscript_event] NATIVECLOSURE
[this] TABLE
This error



Hasan, I think you better show the line code. I don't know what is the part of code is causing it.

habi

I think the error is related to SQL. You show full onScriptLoad from beginning to end.