[GameMode] Collaborative RP - A SA-MP Community Production
#2

VERSION 0.1

Changes:
  • First version, everything
Notes:
  • Not compiled or tested.
Credits in this revision:
  • Lenny
    • Everything
pawn Код:
/*
    This is a base for a roleplay script using:
   
        * MySQL plugin
            By: G-sTyLeZzZ
            Link: https://sampforum.blast.hk/showthread.php?tid=56564
           
        * sscanf plugin
            By: ******
            Link: https://sampforum.blast.hk/showthread.php?tid=120356
           
        * foreach include
            By: ******
            Link: https://sampforum.blast.hk/showthread.php?tid=92679
           
        * zcmd include
            By: Zeex
            Link: https://sampforum.blast.hk/showthread.php?tid=91354
       
        * SHA512 plugin
            By: RyDeR`
            Link: https://sampforum.blast.hk/showthread.php?tid=188734
       
    Started by Lenny (lenny.carlson@hotmail.com) AKA Lenny the Cup @ forum.sa-mp.com
   
    This is a collaborative script, made by the SA-MP forum community of forum.sa-mp.com
   
    Features:
   
        * Dialog login system
   
*/


#include <a_samp>
#include <a_mysql>
#include <sscanf>
#include <foreach>
#include <zcmd>

//------------------------------------- Server configuration -------------------------------------
// DEFINITION                           VALUE                       COMMENT
#undef MAX_PLAYERS
#define MAX_PLAYERS                     10                          // The maximum amount of players on your server
#define DEBUG_MYSQL                     0                           // 1 = Use MySQL debugging
#define SHOW_MARKERS                    0                           // 0 = Off, 1 = Global, 2 = Streamed (Nearby) player markers on the map


#define MIN_PLAYER_PASSWORD             5
#define MAX_PLAYER_PASSWORD             15                          // The maximum string size for a players password

#define DEFAULT_SPAWN_X                 0.0
#define DEFAULT_SPAWN_Y                 0.0
#define DEFAULT_SPAWN_Z                 0.0
#define DEFAULT_SPAWN_ANGLE             0.0
#define DEFAULT_SPAWN_INTERIOR          0

//------------------------------------- Dialog IDs -------------------------------------
#define DIALOG_NOTHING                  1                           // An empty dialog ID, nothing happens when this is used
#define DIALOG_LOGIN                    2                           // Welcome, provide password
#define DIALOG_REGISTER                 3                           // Welcome, please register

//------------------------------------- MySQL Configuration -------------------------------------
#define SQL_HOST                        "localhost"
#define SQL_DB                          "database"
#define SQL_USER                        "user"
#define SQL_PASS                        "pass"

main() {}

//------------------------------------- Variables -------------------------------------
enum e_PlayerInfo
{
    pID,
    pName[MAX_PLAYER_NAME],
    bool: pLoggedIn,
    pCash,
    pAdmin,
    Float: pSpawn[4],                   // X, Y, Z, Angle
    pSpawnInt,
    pSkin
}
new PlayerInfo[MAX_PLAYERS][e_PlayerInfo];

//------------------------------------- Native Functions -------------------------------------
public OnGameModeInit()
{
    #if DEBUG_MYSQL == 1
        mysql_debug(1);
    #endif
    mysql_connect(SQL_HOST, SQL_USER,SQL_DB, SQL_PASS);
    ShowPlayerMarkers(SHOW_MARKERS);
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    Dialog_Welcome(playerid, dialogid, response, listitem, inputtext);
}

public OnPlayerConnect(playerid)
{
    GreetPlayer();
}

//------------------------------------- Other Functions -------------------------------------
// Dialog_Welcome
// By: Lenny
// Date: 11/11 2010
stock Dialog_Welcome(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_LOGIN:
        {
            if(!response)
                KickPlayer(playerid, "Cancelled login.");
            if(isnull(inputtext))
                return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome back!", "Please provide your password.\n\nError: No password provided. Please try again.", "Submit", "Cancel");
            new
                String[128];   
            SHA512(inputtext, String, 128);
            if(strcmp(String, GetPVarString(playerid, "Password"), false, 128)) // Wrong password!
            {
                SetPVarInt(playerid, "WrongLoginTries", GetPVarInt(playerid, "WrongLoginTries")+1);
                if(GetPVarInt(playerid, "WrongLoginTries") == 3)
                    KickPlayer(playerid, "Too many login tries.");
                format(String, 128, "Please provide your password.\n\nError: Invalid password.\n\nWrong tries: %d/3", GetPVarInt(playerid, "WrongLoginTries"));
                return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome back!", String, "Submit", "Cancel");
            }
            LoadPlayerStats(playerid);
            SpawnPlayer(playerid);
            return 1;
        }
        case DIALOG_REGISTER:
        {
            if(!response)
                KickPlayer(playerid, "Cancelled register.");
            if(isnull(inputtext))
                return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome!", "To play on this server, you need to register with a password.\n\n Please provide your password of choice below.\n\nError: No password provided. Please try again.", "Submit", "Cancel");
            if(strlen(inputtext) < MIN_PLAYER_PASSWORD || strlen(inputtext) > MAX_PLAYER_PASSWORD)
                return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome!", "To play on this server, you need to register with a password.\n\n Please provide your password of choice below.\n\nError: Password is too long or too short. Please try again.", "Submit", "Cancel");
            RegisterPlayer(playerid, inputtext);
            LoadPlayerStats(playerid);
            SpawnPlayer(playerid);
            return 1;
        }
    }
}

// KickPlayer
// By: Lenny
// Date: 11/11 2010
// Usage: KickPlayer(1, 2, 3, 4, 5);
// 1 = Integer - ID of the player to kick
// 2 = String - Reason for the kick
// 3 = Integer - ID of the kicking player, INVALID_PLAYER_ID if nobody (Default)
// 4 = Bool - Silent or broadcast to everyone, true (Default) or false
// 5 = Bool - Log the kick, true or false (Default)
stock KickPlayer(playerid, const reason[], kicker = INVALID_PLAYER_ID, bool: silent = true, bool: log = false)
{
    new
        String[168],
        KickerName[MAX_PLAYER_NAME];
    if(kicker == INVALID_PLAYER_ID)
    {
        format(KickerName, MAX_PLAYER_NAME, "SYSTEM");
    else
    {
        format(String, 168, "You kicked %s, reason: %s", PlayerInfo[playerid][pName], reason);
        SendClientMessage(kicker, COLOR_CONFIRM, String);
        format(KickerName, MAX_PLAYER_NAME, PlayerInfo[kicker][pName]);
    }
    format(String, 168, "You were kicked by %s, reason: %s", KickerName, reason);
    SendClientMessage(playerid, COLOR_WARNING, String);
    Kick(playerid);
    if(silent == false)
    {
        format(String, 168, "%s kicked %s, reason: %s", KickerName, PlayerInfo[playerid][pName], reason);
        SendClientMessageToAll(COLOR_WARNING, String);
    }
    return 1;
}

// BanPlayer
// By: Lenny
// Date: 11/11 2010
// Usage: BanPlayer(1, 2, 3, 4, 5);
// 1 = Integer - ID of the player to ban
// 2 = String - Reason for the ban
// 3 = Integer - ID of the banning player, INVALID_PLAYER_ID if nobody (Default)
// 4 = Bool - Silent or broadcast to everyone, true (Default) or false
// 5 = Bool - Log the ban, true or false (Default)
stock BanPlayer(playerid, const reason[], banner = INVALID_PLAYER_ID, bool: silent = true, bool: log = false)
{
    new
        String[168],
        BannerName[MAX_PLAYER_NAME];
    if(banner == INVALID_PLAYER_ID)
    {
        format(BannerName, MAX_PLAYER_NAME, "SYSTEM");
    else
    {
        format(String, 168, "You kicked %s, reason: %s", PlayerInfo[playerid][pName], reason);
        SendClientMessage(banner, COLOR_CONFIRM, String);
        format(BannerName, MAX_PLAYER_NAME, PlayerInfo[banner][pName]);
    }
    format(String, 168, "You were kicked by %s, reason: %s", BannerName, reason);
    SendClientMessage(playerid, COLOR_WARNING, String);
    BanEx(playerid, reason);
    if(silent == false)
    {
        format(String, 168, "%s kicked %s, reason: %s", BannerName, PlayerInfo[playerid][pName], reason);
        SendClientMessageToAll(COLOR_WARNING, String);
    }
    return 1;
}

// GreetPlayer
// By: Lenny
// Date: 11/11 2010
stock GreetPlayer(playerid)
{
    GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
    new
        Query[128];
    format(Query, 75, "SELECT `password` FROM `players` WHERE `name` = '%s'", PlayerInfo[playerid][pName]);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows())
    {
        mysql_fetch_field_row(Query, "password");
        SetPVarString(playerid, "Password", Query);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Welcome back!", "Please provide your password.", "Submit", "Cancel");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Welcome!", "To play on this server, you need to register with a password.\n\n Please provide your password of choice below.", "Submit", "Cancel");
    }
    mysql_free_result();
}

// LoadPlayerStats
// By: Lenny
// Date: 11/11 2010
stock LoadPlayerStats(playerid)
{
    new
        Query[210]];
    format(Query, 210, "SELECT `id`,`cash`,`admin`,`spawnx`,`spawny`,`spawnz`,`spawna`,`spawnint`,`skin` FROM `players` WHERE `name` = %s", GetPlayerName(playerid));
    mysql_query(Query);
    mysql_store_result();
    mysql_fetch_row_format(Query, " ")
    if(!mysql_num_rows())
    {
        mysql_free_result();
        return 0;
    }
    PlayerInfo[playerid][pID] = mysql_fetch_int();
    PlayerInfo[playerid][pCash] = mysql_fetch_int();
    PlayerInfo[playerid][pAdmin] = mysql_fetch_int();
    PlayerInfo[playerid][pSpawn][0] = mysql_fetch_float();
    PlayerInfo[playerid][pSpawn][1] = mysql_fetch_float();
    PlayerInfo[playerid][pSpawn][2] = mysql_fetch_float();
    PlayerInfo[playerid][pSpawn][3] = mysql_fetch_float();
    PlayerInfo[playerid][pSpawnInt] = mysql_fetch_int();
    PlayerInfo[playerid][pSkin] = mysql_fetch_int();
    mysql_free_result();
    SetSpawnInfo(playerid, 0, skin, PlayerInfo[playerid][pSpawn][0], PlayerInfo[playerid][pSpawn][1], PlayerInfo[playerid][pSpawn][2], PlayerInfo[playerid][pSpawn][3], 0, 0, 0, 0, 0, 0)
    return 1;
}

// RegisterPlayer
// By: Lenny
// Date: 11/11 2010
stock RegisterPlayer(playerid, password[])
{
    new
        EncryptedPass[168],
        String[400];
    SHA512(password, EncryptedPass, 400);
    format(String, x, "INSERT INTO `players` (`name`,`password`,`spawnx`,`spawny`,`spawnz`,`spawna`,`spawnint`,`spawnskin`,`admin`,`cash`) VALUES ('%s','%s','%f','%f','%f','%f','%d','%d','0','0')", PlayerInfo[playerid][pName], EncryptedPass, DEFAULT_SPAWN_X, DEFAULT_SPAWN_Y, DEFAULT_SPAWN_Z, DEFAULT_SPAWN_ANGLE, DEFAULT_SPAWN_INTERIOR);
    mysql_query(String);
    if(!mysql_affected_rows())
        return 0;
    return 1;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)