[FilterScript] Dynamic Entrance System![MYSQL]
#1

This its simple system witch allow you to create entrances In Game.

All info stored in mysql db.

COMMANDS

Quote:

create - [ Entrance Name ] [ Interior ]

ENTER and EXIT you can with key [ ENTER ]


Small Video


[ame]http://www.youtube.com/watch?v=iXr8o4LKY4U[/ame]

Download

Script
http://pastebin.com/hXLMTAFm

SQL: http://solidfiles.com/d/4650d/

pawn Код:
/*
                        Dynamic Entrance System
                            By Raimis_[R]
*/


#define FILTERSCRIPT

#include <a_samp>
#include "../include/a_mysql.inc"
#include "../include/sscanf2.inc"
#include "../include/zcmd.inc"

#define MySQL_HOST "localhost"
#define MySQL_USER "root"
#define MySQL_DB   "rpg"
#define MySQL_PASS ""

#define MAX_ENTRANCES (100)
#define MAX_ENTRANCE_NAME (25)

#define void%0(%1)\
            forward%0(%1); public%0(%1)
#define function%0(%1)\
                stock%0(%1)
#define forEx(%0,%1)\
            for(new %0; %0 != %1; %0++)
#define PRESSED(%0)\
            (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

enum items
{
    ID,
    Name[MAX_ENTRANCE_NAME],
    Float:Enter[3],
    Float:Exit[3],
    Interior,
    VirtualW
}
new eSystem[MAX_ENTRANCES][items];

new Text3D:EnterLabel[MAX_ENTRANCES];

public OnFilterScriptInit()
{
    CreateMySQLConnection(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS);

    mysql_query("SELECT * FROM `entrances`");
    mysql_store_result();

    new query[200], string[66], Count = 1;

    while(mysql_fetch_row(query))
    {
        sscanf(query,"e<p<|>is[25]ffffffii>",eSystem[Count]);

        format(string,sizeof(string),"Entrance: %s\nPress [ENTER] to enter!", eSystem[Count][Name]);
        EnterLabel[Count] = Create3DTextLabel(string, -1, eSystem[Count][Enter][0], eSystem[Count][Enter][1], eSystem[Count][Enter][2], 100.0, 0, 0);
        Count++;
    }
    mysql_free_result();
    return 1;
}

public OnFilterScriptExit()
{
    print("INFO: DES System UnLoaded!");
    mysql_close();
    print("INFO: MySQL Connection closed!");
    return 1;
}

command(create, playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) return 0;

    new pName[MAX_ENTRANCE_NAME], pInterior, query[200];

    if (sscanf(params,"s[25]i", pName, pInterior))
    {
        return SendClientMessage(playerid, -1, "* USAGE: /create [Entrance Name] [Interior ID]");
    }
    if (strlen(pName) > MAX_ENTRANCE_NAME)
    {
        return SendClientMessage(playerid, -1, "* Entrance Name Cannot By Longer Than 25 Simbols!");
    }
    new Float:Player[3];
    GetPlayerPos(playerid, Player[0], Player[1], Player[2]);

    mysql_query("SELECT MAX(ID) FROM `entrances`");
    mysql_store_result();

    new sqlid[10];
    mysql_fetch_row_format(sqlid,"|");
    printf("INFO: Last ID: %s", sqlid);

    new SQLID = strval(sqlid);
    SQLID++;
    eSystem[SQLID][ID] = SQLID;
    eSystem[SQLID][Name] = pName;
    eSystem[SQLID][Enter][0] = Player[0];
    eSystem[SQLID][Enter][1] = Player[1];
    eSystem[SQLID][Enter][2] = Player[2];
    eSystem[SQLID][VirtualW] = SQLID;

    format(query,sizeof(query),"INSERT INTO `entrances` (`ID`,`Name`,`X`,`Y`,`Z`,`VirtualW`) VALUES ('%i','%s','%f','%f','%f','%i')",
    eSystem[SQLID][ID], eSystem[SQLID][Name], eSystem[SQLID][Enter][0], eSystem[SQLID][Enter][1], eSystem[SQLID][Enter][2], eSystem[SQLID][VirtualW]);
    mysql_query(query);

    new string[66];
    format(string,sizeof(string),"Entrance: %s!\nPress [ENTER] to enter!", eSystem[SQLID][Name]);
    EnterLabel[SQLID] = Create3DTextLabel(string, -1, eSystem[SQLID][Enter][0], eSystem[SQLID][Enter][1], eSystem[SQLID][Enter][2], 50.0, 0, 1);

    UpdateExitCordinates(SQLID,pInterior);
    mysql_free_result();
    return 1;
}



function UpdateExitCordinates(eID, eInterior)
{
    switch(eInterior)
    {
        case 1: // LV Gym
        {
            eSystem[eID][Interior] = 7;
            eSystem[eID][Exit][0] = 773.579956;
            eSystem[eID][Exit][1] = -77.096694;
            eSystem[eID][Exit][2] = 1000.655029;
        }
        case 2: // Car school
        {
            eSystem[eID][Interior] = 3;
            eSystem[eID][Exit][0] = -2029.798339;
            eSystem[eID][Exit][1] = -106.675910;
            eSystem[eID][Exit][2] = 1035.171875;
        }
        case 3: // Bike school
        {
            eSystem[eID][Interior] = 3;
            eSystem[eID][Exit][0] = 1494.325195;
            eSystem[eID][Exit][1] = 1304.942871;
            eSystem[eID][Exit][2] = 1093.289062;
        }
        case 4: // LS Police HQ
        {
            eSystem[eID][Interior] = 6;
            eSystem[eID][Exit][0] = 246.783996;
            eSystem[eID][Exit][1] = 63.900199;
            eSystem[eID][Exit][2] = 1003.640625;
        }
        case 5: // Zero's RC Shop
        {
            eSystem[eID][Interior] = 6;
            eSystem[eID][Exit][0] = -2240.468505;
            eSystem[eID][Exit][1] = 137.060440;
            eSystem[eID][Exit][2] = 1035.414062;
        }
        case 6: // Ammunation 1
        {
            eSystem[eID][Interior] = 1;
            eSystem[eID][Exit][0] = 286.148986;
            eSystem[eID][Exit][1] = -40.644397;
            eSystem[eID][Exit][2] = 1001.515625;
        }
        case 7: // 24/7 1
        {
            eSystem[eID][Interior] = 17;
            eSystem[eID][Exit][0] = -25.884498;
            eSystem[eID][Exit][1] = -185.868988;
            eSystem[eID][Exit][2] = 1003.546875;
        }
        case 8: //  Jefferson motel
        {
            eSystem[eID][Interior] = 15;
            eSystem[eID][Exit][0] = 2215.454833;
            eSystem[eID][Exit][1] = -1147.475585;
            eSystem[eID][Exit][2] = 1025.796875;
        }
        case 9: // Binco
        {
            eSystem[eID][Interior] = 15;
            eSystem[eID][Exit][0] = 207.737991;
            eSystem[eID][Exit][1] = -109.019996;
            eSystem[eID][Exit][2] = 1005.132812;
        }
        case 10: // Club
        {
            eSystem[eID][Interior] = 17;
            eSystem[eID][Exit][0] = 493.390991;
            eSystem[eID][Exit][1] = -22.722799;
            eSystem[eID][Exit][2] = 1000.679687;
        }
        default: // Bar
        {
            eSystem[eID][Interior] = 11;
            eSystem[eID][Exit][0] = 501.980987;
            eSystem[eID][Exit][1] = -69.150199;
            eSystem[eID][Exit][2] = 998.757812;
        }
    }
    new query[200];
    format(query,sizeof(query),"UPDATE `entrances` SET `exitX` = '%f', `exitY` = '%f', `exitZ` = '%f', `Interior` = '%i' WHERE `ID` = '%i'",
    eSystem[eID][Exit][0], eSystem[eID][Exit][1], eSystem[eID][Exit][2], eSystem[eID][Interior], eID);
    mysql_query(query);
}


function CreateMySQLConnection(host[], user[], db[], pass[])
{
    mysql_connect(host, user, db, pass);

    if (mysql_ping() >= 1)
    {
        print("INFO: Connected To MySQL!");
    }
    else
    {
        print("INFO: Can't Connect To MySQL!");
    }
    // By Wups
    mysql_query("CREATE TABLE IF NOT EXISTS `entrances` ( \
      `ID` int(3) NOT NULL, \
      `Name` varchar(25) NOT NULL, \
      `X` float NOT NULL, \
      `Y` float NOT NULL, \
      `Z` float NOT NULL, \
      `exitX` float NOT NULL, \
      `exitY` float NOT NULL, \
      `exitZ` float NOT NULL, \
      `Interior` int(5) NOT NULL, \
      `VirtualW` int(3) NOT NULL \
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
);
}


void OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_SECONDARY_ATTACK))
    {
        forEx(i, MAX_ENTRANCES)
        {
            if (IsPlayerInRangeOfPoint(playerid, 2, eSystem[i][Enter][0], eSystem[i][Enter][1], eSystem[i][Enter][2]))
            {
                SetPlayerVirtualWorld(playerid, eSystem[i][VirtualW]);
                SetPlayerInterior(playerid, eSystem[i][Interior]);
                SetPlayerPos(playerid, eSystem[i][Exit][0], eSystem[i][Exit][1], eSystem[i][Exit][2]);
                SetPVarInt(playerid, "entranceID", i); // Need for exit
                break; // Stoping loop
            }
        }
        if (IsPlayerInRangeOfPoint(playerid, 2, eSystem[GetPVarInt(playerid,"entranceID")][Exit][0], eSystem[GetPVarInt(playerid,"entranceID")][Exit][1], eSystem[GetPVarInt(playerid,"entranceID")][Exit][2]))
        {
            SetPlayerVirtualWorld(playerid, 0);
            SetPlayerInterior(playerid, 0);
            SetPlayerPos(playerid, eSystem[GetPVarInt(playerid,"entranceID")][Enter][0], eSystem[GetPVarInt(playerid,"entranceID")][Enter][1], eSystem[GetPVarInt(playerid,"entranceID")][Enter][2]);
        }
    }
    return 1;
}
Reply
#2

____COOL____
:::10/10:::

Good work
Reply
#3

Well , i won't say more than.......That's Awesome...Good Job..Really..
Reply
#4

Gonna USE IT!
but when the server restart they SAVE?! and Where?
Reply
#5

Quote:
Originally Posted by Issam
Посмотреть сообщение
Gonna USE IT!
but when the server restart they SAVE?! and Where?
Yes. In MySQL DB.
Reply
#6

nice job, but my server crashed after I put it in my gamemode
Reply
#7

Good script.
Reply
#8

Quote:
Originally Posted by Scottas
Посмотреть сообщение
nice job, but my server crashed after I put it in my gamemode
Reply
#9

awesome xN
Reply
#10

9.99999../10
Reply
#11

Thanks for feedback
Reply
#12

Looks alright.
My suggestion:
pawn Код:
function CreateMySQLConnection(host[], user[], db[], pass[])
{
    mysql_connect(host, user, db, pass);
   
    if (mysql_ping() >= 1)
    {
        print("INFO: Connected To MySQL!");
    }
    else
    {
        print("INFO: Can't Connect To MySQL!");
    }
mysql_query("CREATE TABLE IF NOT EXISTS `entrances` ( \
  `ID` int(3) NOT NULL, \
  `Name` varchar(25) NOT NULL, \
  `X` float NOT NULL, \
  `Y` float NOT NULL, \
  `Z` float NOT NULL, \
  `exitX` float NOT NULL, \
  `exitY` float NOT NULL, \
  `exitZ` float NOT NULL, \
  `Interior` int(5) NOT NULL, \
  `VirtualW` int(3) NOT NULL \
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
);
}
The plugin will be almost plug & play.
Not sure if you won't need to join strings.
I think it's the best(coded, not featured) released entrance system.
+ You should add a command /createinterior (which automaticly saves it into mysql). That way people could add different places dynamically.
Reply
#13

bugged, not working, crashing
Reply
#14

Quote:
Originally Posted by Scottas
Посмотреть сообщение
bugged, not working, crashing


I hate you! Xd

Wups i will add ur edited stock later.

BTW Thanks.
Reply
#15

Epic that saves me from alot of lines :P.
Reply
#16

very nice 9/10
Reply
#17

Thanks guys.
Reply
#18

Bug: You're NOT clearing the result after OnFilterScriptInit. That may cause crashes.
Reply
#19

Quote:
Originally Posted by wups
Посмотреть сообщение
Bug: You're NOT clearing the result after OnFilterScriptInit. That may cause crashes.
Thank you! My Big Fail :<

New Link: http://pastebin.com/hXLMTAFm
Reply
#20

now I have to turn off my server thanks for your script
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)