SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 20/10/2018, 09:45 AM   #21
Danielknow
Big Clucker
 
Join Date: May 2018
Location: United States
Posts: 70
Reputation: 1
Default Re: MySQL Clan System

@Gammix awesome system! keep made amazing systems
Danielknow is offline   Reply With Quote
Old 20/10/2018, 04:45 PM   #22
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,761
Reputation: 840
Default Re: MySQL Clan System

Quote:
Originally Posted by KinderClans View Post
Another question. How i can restrict a command for just one clan? I mean, i wanna do /clanmute, and player must be in clan "Test" to use it, how to? Do i need to check clan database ID or name? How i can do it?

I see there is playerClanID, but i don't know how to use it, i mean really don't know how it works.

And, playerClanID is saved somewhere in database or is just a temporary variable?
playerClanID holds the clan ID player is in, it's saved and loaded everytime a player connects/disconnects.

You can use this variable to access clan data in your command, if have done a similar job in other clan commands.

Have a look:
Code:
clanData[clanid][property]
So if i want to get player's clan name: i'll do two checks:
pawn Code:
if (playerClanID[playerid] == -1) { // so we don't get any runtime error
    if (!strcmp("Test", clanData[playerClanID[playerid]][CLAN_NAME])) { // clan name matches to "Test"
        // do your code here
    }
}

For a list of properties you can get from a clanid:
pawn Code:
enum E_CLAN_DATA {
    CLAN_SQLID,
    CLAN_TAG[MAX_CLAN_TAG_NAME],
    CLAN_NAME[MAX_CLAN_NAME],
    CLAN_SKIN,
    CLAN_TEAM,
    CLAN_OWNER[MAX_PLAYER_NAME],
    Float:CLAN_SPAWN_POS[4],
    CLAN_SPAWN_INTERIORID,
    CLAN_SPAWN_WORLDID,
    CLAN_VAULT_MONEY,
    CLAN_VAULT_WEAPONS[MAX_CLAN_WEAPONS],
    CLAN_VAULT_WEAPONS_TIMESTAMP[MAX_CLAN_WEAPONS],
    CLAN_TOTAL_EXP,
    CLAN_WAR_WINS,
    CLAN_WAR_TOTAL,
    Text3D:CLAN_3D_TEXT_LABEL,
    CLAN_PICKUPID
};

^ Its like database but for runtime only!

Quote:
Originally Posted by KinderClans View Post
Also i want to remove TEAMS datas, everything related to it. Will it work too without teams?
Yes you can remove the array and code related to TEAMS, you have to remove the command related to setting clan team and also remove some code from OnPlayerSpawn.
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 22/10/2018, 08:16 AM   #23
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 720
Reputation: 43
Default Re: MySQL Clan System

I have a problem with the command to create faction. I removed team skins and added the possibility to set faction skins directly with the /fcreatecommand. But faction doesn't create, i get the ownership message and everything but in database faction doesn't create. Here is whole command:

pawn Code:
CMD:fcreate(playerid, params[]) {
    if (!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, COLOR_TOMATO, "Error: Only admin level 5 and above can access to this command.");

    new factionName[MAX_FACTION_NAME], factionTag[MAX_FACTION_TAG_NAME], ownerid, skin;
    if (sscanf(params, "s["#MAX_FACTION_NAME"]s["#MAX_FACTION_TAG_NAME"]rd", factionName, factionTag, ownerid, skin)) {
        SendClientMessage(playerid, COLOR_LIGHT_AQUA, "Usage: /fcreate [name] [tag] [owner] [faction skin]");
        SendClientMessage(playerid, COLOR_LIGHT_AQUA, "Usage: To add spaces in [name], you can use '_' and it will be auto detected as a white space!");
        return 1;
    }
   
    if(skin < 0 || skin > 311) return SendClientMessage(playerid, -1, "* Invalid skin ID (1-311)");

    foreach_factions(i) {
        if (!strcmp(factionData[i][FACTION_NAME], factionName, true)) {
            return SendClientMessage(playerid, COLOR_TOMATO, "Error: The faction name already exist, try another one.");
        }
       
        if (!strcmp(factionData[i][FACTION_TAG], factionTag, true)) {
            return SendClientMessage(playerid, COLOR_TOMATO, "Error: The faction tag already exist, try another one.");
        }
    }
   
    if (!IsPlayerConnected(ownerid))
        return SendClientMessage(playerid, COLOR_TOMATO, "Error: The owner player isn't connected.");

    if (playerFactionID[ownerid] != -1)
        return SendClientMessage(playerid, COLOR_TOMATO, "Error: The owner player is in a faction.");

    new index = -1;
    for (new i = 0; i < MAX_FACTIONS; i++) {
        if (factionData[i][FACTION_NAME][0] == EOS) {
            index = i;
            break;
        }
    }
   
    if (index == -1)
        return SendClientMessage(playerid, COLOR_TOMATO, "Error: Looks like the server factions creation limit has been reached, please contact server developer about this.");

    for (new i = 0; factionName[i] != EOS; i++) {
        if (factionName[i] == '_') {
            factionName[i] = ' ';
        }
    }

    new pos = strfind(factionTag, "[");
    if (pos != -1)
        strdel(factionTag, pos, pos + 1);

    pos = strfind(factionTag, "]");
    if (pos != -1)
        strdel(factionTag, pos, pos + 1);

    format(factionData[index][FACTION_TAG], MAX_FACTION_TAG_NAME, factionTag);
    format(factionData[index][FACTION_NAME], MAX_FACTION_NAME, factionName);
    factionData[index][FACTION_SKIN] = skin;
    GetPlayerName(ownerid, factionData[index][FACTION_OWNER], MAX_PLAYER_NAME);
    factionData[index][FACTION_WAR_WINS] = 0;
    factionData[index][FACTION_WAR_TOTAL] = 0;
    factionData[index][FACTION_SPAWN_POS][0] = 0.0;
    factionData[index][FACTION_SPAWN_POS][1] = 0.0;
    factionData[index][FACTION_SPAWN_POS][2] = 0.0;
    factionData[index][FACTION_SPAWN_POS][3] = 0.0;
    factionData[index][FACTION_SPAWN_INTERIORID] = 0;
    factionData[index][FACTION_SPAWN_WORLDID] = 0;
    factionData[index][FACTION_VAULT_MONEY] = 0;
    for (new i = 0; i < MAX_FACTION_WEAPONS; i++) {
        factionData[index][FACTION_VAULT_WEAPONS][i] = -1;
        factionData[index][FACTION_VAULT_WEPS_TIMESTAMP][i] = -1;
    }
    factionData[index][FACTION_TOTAL_EXP] = 0;
    factionData[index][FACTION_3D_TEXT_LABEL] = Text3D:INVALID_STREAMER_ID;
    factionData[index][FACTION_PICKUPID] = INVALID_STREAMER_ID;

    playerFactionID[ownerid] = index;
    playerFactionRank[ownerid] = FACTION_RANK_OWNER;

    new vault_weapons[32];
    for (new i = 0; i < MAX_FACTION_WEAPONS; i++) {
        format(vault_weapons, sizeof(vault_weapons), "%s-1", vault_weapons);

        if (i != (MAX_FACTION_WEAPONS - 1)) {
            strcat(vault_weapons, " ");
        }
    }
   
    new query[512];
    mysql_format(database, query, sizeof(query),
        "INSERT INTO factions (\
            tag, name, skin, exp, team, factionwar_wins, factionwar_total, \
            spawn_x, spawn_y, spawn_z, spawn_angle, spawn_interiorid, spawn_worldid, \
            vault_money, vault_weapons, vault_weapons_timestamp\
        ) VALUES (\
            '%e', '%e', %d, 0, %i, 0, 0, \
            0.0, 0.0, 0.0, 0.0, 0, 0, \
            0, '%s'\
        )"
,
        factionTag, factionName, skin,
        vault_weapons, vault_weapons
    );

    mysql_format(database, query, sizeof(query),
        "INSERT INTO faction_members (\
            faction_name, name, rank\
        ) VALUES (\
            '%e', '%e', %i\
        )"
,
        factionName, factionData[index][FACTION_OWNER], FACTION_RANK_OWNER
    );
    mysql_tquery(database, query);

    for (new i = 0; i < MAX_FACTION_RANKS; i++) {
        format(factionRankNames[index][i], MAX_FACTION_RANK_NAME, DEFAULT_FACTION_RANKS[i]);

        mysql_format(database, query, sizeof(query),
            "INSERT INTO faction_ranks (\
                faction_name, name, level\
            ) VALUES (\
                '%e', '%e', %i\
            )"
,
            factionName, DEFAULT_FACTION_RANKS[i], i
        );
        mysql_tquery(database, query);
    }
   
    mysql_format(database, query, sizeof(query),
        "SELECT id FROM factions WHERE faction_name = '%e'",
        factionName
    );
    new Cache:cache = mysql_query(database, query);
    cache_get_value_int(0, "id", factionData[index][FACTION_SQLID]);
    cache_delete(cache);
   
    UpdateFactionsRank();

    new string[164];
    format(string, sizeof(string), "[%s] %s", factionData[index][FACTION_TAG], factionRankNames[index][MAX_FACTION_RANKS - 1]);
    playerFaction3DTextLabel[ownerid] = CreateDynamic3DTextLabel(string, -1, 0.0, 0.0, 0.0, 25.0, ownerid, .testlos = 1);

    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));

    SendClientMessage(ownerid, COLOR_GREEN, "_________________________________________");
    SendClientMessage(ownerid, COLOR_GREEN, "");
    SendClientMessage(ownerid, COLOR_GREEN, "                           FACTION OWNERSHIP");
    format(string, sizeof(string), "Admin "COL_DEFAULT"%s"COL_GREEN", have assgined you as owner of new faction: "COL_DEFAULT"%s", name, factionData[index][FACTION_NAME]);
    SendClientMessage(ownerid, COLOR_GREEN, string);
    SendClientMessage(ownerid, COLOR_GREEN, "Here are some tips to get a head start with your faction:");
    SendClientMessage(ownerid, COLOR_GREEN, "To start recruiting players to your faction, use "COL_DEFAULT"/finvite");
    SendClientMessage(ownerid, COLOR_GREEN, "For list of faction commands that you have access to all of them, type "COL_DEFAULT"/fhelp");
    SendClientMessage(ownerid, COLOR_GREEN, "_________________________________________");

    format(string, sizeof(string), "Admin: You have suceessfully assigned a new faction, "COL_DEFAULT"%s "COL_BLUE"to player "COL_DEFAULT"%s", factionData[index][FACTION_NAME], factionData[index][FACTION_OWNER]);
    SendClientMessage(playerid, COLOR_BLUE, string);
   
    PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
    PlayerPlaySound(ownerid, 1057, 0.0, 0.0, 0.0);

    format(string, sizeof(string), "(%s)", factionData[index][FACTION_TAG]);
    TextDrawSetString(factionAnnouncementTD[1], string);
    format(string, sizeof(string), "~w~Faction ~r~~h~%s ~w~is now recruiting new memebers. To request an invite, contact ~r~~h~%s ~w~(id: ~r~%i~w~)", factionData[index][FACTION_NAME], factionData[index][FACTION_OWNER], ownerid);
    TextDrawSetString(factionAnnouncementTD[2], string);

    foreach (new i : Player) {
        if (GetPlayerState(i) != PLAYER_STATE_WASTED || GetPlayerState(i) != PLAYER_STATE_SPECTATING) {
            for (new x = 0; x < sizeof(factionAnnouncementTD); x++) {
                TextDrawShowForPlayer(i, factionAnnouncementTD[x]);
            }
        }
    }

    factionAnnouncementTimer = SetTimer("OnAnnouncementExpire", (30 * 1000), false);
   
    format(string, sizeof(string), "[%s] %s", factionData[index][FACTION_TAG], factionRankNames[index][FACTION_RANK_OWNER]);
    playerFaction3DTextLabel[playerid] = CreateDynamic3DTextLabel(string, -1, 0.0, 0.0, 0.0, 25.0, playerid, .testlos = 1);

    format(string, sizeof(string), "~g~~h~~h~(%s) ~g~~h~%s ~w~(Rank: (%i)%s)", factionData[index][FACTION_TAG], factionData[index][FACTION_NAME], FACTION_RANK_OWNER + 1, factionRankNames[index][FACTION_RANK_OWNER]);
    PlayerTextDrawSetString(playerid, factionNamePTD[playerid], string);
    PlayerTextDrawShow(playerid, factionNamePTD[playerid]);

    return 1;
}

In mysql log i get "invalid passing parameter" referred to "INSERT INTO factions" query, maybe added one useless parameter?
KinderClans is offline   Reply With Quote
Old 16/12/2018, 03:07 PM   #24
Droxx
Big Clucker
 
Droxx's Avatar
 
Join Date: Dec 2015
Posts: 116
Reputation: 32
Default Re: MySQL Clan System

Facing to problems which do not allow the FS to run..

Code:
[18:02:45]   Loading filterscript 'clans.amx'...
[debug] Run time error 19: "File or function is not found"
[debug]  MEM_new
[debug]  MEM_delete
EDIT: Updated pawn-memory plugin, works!
Droxx is offline   Reply With Quote
Old 12/07/2019, 01:22 PM   #25
v1k1nG
Huge Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Posts: 437
Reputation: 31
Default Re: MySQL Clan System

Hello Gammix. That is really some handsome job you've been doing. Only thing I don't understand is why when using /cbuyskin the list doesnt show all the 312 skins but stops at 104?
__________________
v1k1nG is offline   Reply With Quote
Old 19/07/2019, 03:56 AM   #26
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,761
Reputation: 840
Default Re: MySQL Clan System

Quote:
Originally Posted by v1k1nG View Post
Hello Gammix. That is really some handsome job you've been doing. Only thing I don't understand is why when using /cbuyskin the list doesnt show all the 312 skins but stops at 104?
You'll have to modify it with "strcat". Something like this:

pawn Code:
const MAX_SKINS = 312;
new subString[32];
static string[MAX_SKINS * sizeof(subString)];

if (string[0] == EOS) {
    for (new i = 0; i < MAX_SKINS; i++) {
        format(subString, sizeof(subString), "%i\tID: %i~n~~r~~h~~h~Price: $%s\n", i, i, FormatNumber(15000000));
        strcat(string, subString);
    }
}
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with clan system. Exhibit Scripting Help 1 22/05/2018 05:57 AM
[Include] clan.inc -> Easy-to-use, plug-n-play clan system fiki574 Includes 123 25/12/2015 08:11 PM
Clan system [ MySql ] Cameltoe Help Archive 6 24/08/2010 03:23 PM


All times are GMT. The time now is 05:27 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.