Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <crashdetect>
- #include <Pawn.CMD>
- #include <a_mysql>
- #include <sscanf2>
- #include <easy-mysql>
- #include <streamer>
- // Definiciones.
- #define MAX_COMMERCE 100 // MÁXIMO DE NEGOCIOS EN TODO EL SERVIDOR.
- #define MAX_COMMERCE_INT 100
- #define TBL_COMMERCE "commerce"
- #define TBL_COMMERCE_INTERIOR "commerce_interior"
- #define COMM_STATE_SALE "ON_SALE"
- #define COMM_STATE_NOTSALE "NOT_SALE"
- #define FILTERSCRIPT
- // Enumeraciones.
- enum _commerceInfo
- {
- ID,
- Name[50 + 1],
- Owner,
- ownerName[24 + 1],
- Price,
- State,
- Interior, // SA-MP INTERIOR
- World, // SA-MP WORLD
- customInterior, // INTERIOR PERSONALIZADO QUE SE UTILIZARÁ COMO INTERIOR DEL NEGOCIO.
- Float:entryPosX,
- Float:entryPosY,
- Float:entryPosZ,
- STREAMER_TAG_3D_TEXT_LABEL:dynamicLabelId
- };
- enum _commerceInterior
- {
- ID,
- Name[30 + 1],
- Interior,
- World,
- Float:intPosX,
- Float:intPosY,
- Float:intPosZ,
- STREAMER_TAG_3D_TEXT_LABEL:dynamicLabelId
- };
- // Variables.
- new commerceInfo[MAX_COMMERCE][_commerceInfo];
- new commerceInterior[MAX_COMMERCE_INT][_commerceInterior];
- new MySQL:hDb;
- public OnFilterScriptInit()
- {
- print("Cargando property-manage");
- SQL::Connect("localhost", "teamkproj", "123", "db_kproj");
- if(mysql_errno(hDb) > 0 )
- {
- // ERROR CON LA BASE DE DATOS.
- print("[MySQL] No se ha podido conectar a la base de datos.");
- }
- else
- {
- // CONEXIÓN A LA BASE DE DATOS CORRECTA.
- print("[MySQL] Se ha conectado correctamente a la base de datos.");
- /*if(!SQL::ExistsTable(TBL_COMMERCE))
- {
- new handle = SQL::Open(SQL::CREATE, TBL_COMMERCE);
- SQL::AddTableColumn(handle, "comm_id", SQL_TYPE_INT, 11, false, true, true);
- SQL::AddTableColumn(handle, "comm_name", SQL_TYPE_VCHAR, 50);
- SQL::AddTableColumn(handle, "comm_owner", SQL_TYPE_INT);
- SQL::AddTableColumn(handle, "comm_price", SQL_TYPE_INT);
- SQL::AddTableColumn(handle, "comm_state", SQL_TYPE_VCHAR, 30);
- SQL::AddTableColumn(handle, "comm_entryx", SQL_TYPE_FLOAT);
- SQL::AddTableColumn(handle, "comm_entryy", SQL_TYPE_FLOAT);
- SQL::AddTableColumn(handle, "comm_entryz", SQL_TYPE_FLOAT);
- SQL::AddTableColumn(handle, "comm_entrya", SQL_TYPE_FLOAT);
- SQL::Close(handle);
- }
- if(!SQL::ExistsTable(TBL_COMMERCE_INTERIOR))
- {
- new handle = SQL::Open(SQL::CREATE, TBL_COMMERCE);
- SQL::AddTableColumn(handle, "cint_id", SQL_TYPE_INT, 11, false, true, true);
- SQL::AddTableColumn(handle, "cint_world", SQL_TYPE_INT, 50);
- SQL::AddTableColumn(handle, "cint_interior", SQL_TYPE_INT);
- SQL::AddTableColumn(handle, "cint_posx", SQL_TYPE_FLOAT);
- SQL::AddTableColumn(handle, "cint_posy", SQL_TYPE_FLOAT);
- SQL::AddTableColumn(handle, "cint_posz", SQL_TYPE_FLOAT);
- SQL::AddTableColumn(handle, "cint_posa", SQL_TYPE_FLOAT);
- SQL::Close(handle);
- }*/
- loadCommerce();
- loadCommerceInterior();
- }
- return true;
- }
- public OnFilterScriptExit()
- {
- mysql_close(hDb);
- return true;
- }
- CMD:comprarnegocio(playerid, params[])
- {
- new nearCommerce = getPlayerNearCommerce(playerid);
- if( nearCommerce == -1 )
- return SendClientMessage(playerid, -1, "ERROR: No estás cerca de ningún negocio.");
- if( strcmp(commerceInfo[nearCommerce][State], COMM_STATE_SALE, true) )
- return SendClientMessage(playerid, -1, "ERROR: Este negocio no esta en venta.");
- if( GetPlayerMoney(playerid) < commerceInfo[ nearCommerce ][Price] )
- return SendClientMessage(playerid, -1, "ERROR: No tienes suficiente dinero para hacer esta compra.");
- commerceInfo[ nearCommerce ][Owner] = 1; // CAMBIAR 1 POR LA VARIABLE QUE REPRESENTA EL ID DE CUENTA DEL JUGADOR.
- GivePlayerMoney(playerid, -commerceInfo[ nearCommerce ][Price]);
- SendClientMessage(playerid, -1, "Se ha comprado el negocio correctamente.");
- updateCommerce(nearCommerce);
- return true;
- }
- CMD:crearnegocio(playerid, params[])
- {
- if( !IsPlayerAdmin(playerid) )
- return SendClientMessage(playerid, -1, "ERROR: Solo administradores pueden crear negocios.");
- new p_name[30 + 1], p_price, p_int;
- if( sscanf(params, "s[30]dd", p_name, p_price, p_int) )
- return SendClientMessage(playerid, -1, "Utilización: /crearnegocio [Nombre] [Precio] [ID del Interior (DB) (/commint) ]");
- if(!existCommerceInterior(p_int))
- return SendClientMessage(playerid, -1, "ERROR: No se ha encontrado ningún interior (personalizado) con la ID que se ha indicado.");
- new Float:pPosX, Float:pPosY, Float:pPosZ, pInterior, pWorld;
- GetPlayerPos(playerid, pPosX, pPosY, pPosZ);
- pInterior = GetPlayerInterior(playerid);
- pWorld = GetPlayerVirtualWorld(playerid);
- new commId = createCommerce(p_name, p_price, pWorld, pInterior, p_int, pPosX, pPosY, pPosZ);
- if( commId > 0 )
- {
- new strMessage[144 + 1];
- format(strMessage, sizeof(strMessage), "Se ha creado exitosamente el negocio %s(ID: %d)", p_name, commId);
- SendClientMessage(playerid, -1, strMessage);
- }
- else
- {
- SendClientMessage(playerid, -1, "ERROR: Un problema a ocurrido al intentar crear la casa.");
- }
- return true;
- }
- CMD:borrarnegocio(playerid, params[])
- {
- if( !IsPlayerAdmin(playerid) )
- return SendClientMessage(playerid, -1, "ERROR: Solo administradores pueden borrar negocios.");
- new nearCommerce = getPlayerNearCommerce(playerid);
- if( nearCommerce == -1 )
- return SendClientMessage(playerid, -1, "ERROR: No estás cerca de ningún negocio.");
- new strMessage[144 + 1];
- format(strMessage, sizeof(strMessage), "Se borrará el negocio %s[ID: %d].", commerceInfo[nearCommerce][Name], commerceInfo[nearCommerce][ID]);
- SendClientMessage(playerid, -1, strMessage);
- deleteCommerce(nearCommerce);
- return true;
- }
- CMD:borrarnegint(playerid, params[])
- {
- if( !IsPlayerAdmin(playerid) )
- return SendClientMessage(playerid, -1, "ERROR: Solo administradores pueden borrar interiores de negocios.");
- new p_cint;
- if( sscanf(params, "d", p_cint) )
- return SendClientMessage(playerid, -1, "Utilización: /borrarnegint [ID]");
- if( !existCommerceInterior(p_cint) )
- return SendClientMessage(playerid, -1, "ERROR: El ID de interior de negocio que se ha indicado no es correcto.");
- new commId = -1;
- new handle = SQL::Open(SQL::READ, TBL_COMMERCE, "cint_id", p_cint);
- SQL::ReadInt(handle, "comm_id", commId);
- SQL::Close(handle);
- if( commId != -1 )
- return SendClientMessage(playerid, -1, "ERROR: Este interior esta siendo utilizado por uno o varios negocios, elimina el negocio o cambia el interior.");
- new strMessage[144 + 1];
- format(strMessage, sizeof(strMessage), "Se borrará el interior de negocio %s[ID: %d].", commerceInterior[p_cint][Name], commerceInterior[p_cint][ID]);
- SendClientMessage(playerid, -1, strMessage);
- deleteCommerceInterior(p_cint);
- return true;
- }
- CMD:crearnegint(playerid, params[])
- {
- if( !IsPlayerAdmin(playerid) )
- return SendClientMessage(playerid, -1, "ERROR: Solo administradores pueden crear negocios.");
- new p_name[30], p_world, p_interior;
- if( sscanf(params, "s[30]D(0)D(0)", p_name, p_world, p_interior) )
- return SendClientMessage(playerid, -1, "Utilización: /crearcomint [Nombre] [Mundo Virtual] [Interior (SA-MP)]");
- p_world = ( (p_world < 0 ) ? (GetPlayerVirtualWorld(playerid)) : (p_world) );
- p_interior = ( (p_interior < 0 ) ? (GetPlayerInterior(playerid)) : (p_interior) );
- new Float:pPosX, Float:pPosY, Float:pPosZ;
- GetPlayerPos(playerid, pPosX, pPosY, pPosZ);
- new commIntId = createCommerceInterior(p_name, p_world, p_interior, pPosX, pPosY, pPosZ), strMessage[144 + 1];
- if( commIntId > 0 )
- {
- format(strMessage, sizeof(strMessage), "Se ha creado el interior personalizado %s(ID: %d).", p_name, commIntId);
- }
- else
- {
- SendClientMessage(playerid, -1, "ERROR: Un problema a ocurrido al intentar crear la casa.");
- }
- return true;
- }
- loadCommerce()
- {
- // CARGANDO NEGOCIOS.
- new handle = SQL::Open(SQL::MTREAD, TBL_COMMERCE), tempId, commerceCount, strLabel[144 + 1];
- SQL::ReadRetrievedRows(handle, i)
- {
- SQL::ReadInt(handle, "comm_id", tempId, i);
- SQL::ReadInt(handle, "comm_id", commerceInfo[tempId][ID], i);
- SQL::ReadString(handle, "comm_name", commerceInfo[tempId][Name], 50, i);
- SQL::ReadInt(handle, "comm_owner", commerceInfo[tempId][Owner], i);
- SQL::ReadInt(handle, "comm_price", commerceInfo[tempId][Price], i);
- SQL::ReadInt(handle, "comm_state", commerceInfo[tempId][State], i);
- SQL::ReadInt(handle, "comm_world", commerceInfo[tempId][World], i);
- SQL::ReadInt(handle, "comm_interior", commerceInfo[tempId][Interior], i);
- SQL::ReadInt(handle, "cint_id", commerceInfo[tempId][customInterior], i);
- SQL::ReadFloat(handle, "comm_entryx", commerceInfo[tempId][entryPosX], i);
- SQL::ReadFloat(handle, "comm_entryy", commerceInfo[tempId][entryPosY], i);
- SQL::ReadFloat(handle, "comm_entryz", commerceInfo[tempId][entryPosZ], i);
- // CREANDO ETIQUETA.
- if(!strcmp(commerceInfo[tempId][State], COMM_STATE_SALE, true))
- {
- format(strLabel, sizeof(strLabel), "%s (ID: %d)\nPropietario: %s\nPrecio: $%d\n\n/negocio comprar", commerceInfo[tempId][Name], tempId, commerceInfo[tempId][Owner], commerceInfo[tempId][Price]);
- commerceInfo[tempId][dynamicLabelId] = CreateDynamic3DTextLabel(strLabel, -1, commerceInfo[tempId][entryPosX], commerceInfo[tempId][entryPosY], commerceInfo[tempId][entryPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInfo[tempId][World], commerceInfo[tempId][Interior]);
- }
- else if(!strcmp(commerceInfo[tempId][State], COMM_STATE_NOTSALE, true))
- {
- format(strLabel, sizeof(strLabel), "%s (ID: %d)\nPropietario: %s", commerceInfo[tempId][Name], tempId, commerceInfo[tempId][Owner], commerceInfo[tempId][Price]);
- commerceInfo[tempId][dynamicLabelId] = CreateDynamic3DTextLabel(strLabel, -1, commerceInfo[tempId][entryPosX], commerceInfo[tempId][entryPosY], commerceInfo[tempId][entryPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInfo[tempId][World], commerceInfo[tempId][Interior]);
- }
- printf("[Negocio] Se ha cargado el negocio %s (ID: %d).", commerceInfo[tempId][Name], tempId);
- commerceCount++;
- }
- }
- loadCommerceInterior()
- {
- // CARGANDO NEGOCIOS.
- new handle = SQL::Open(SQL::MTREAD, TBL_COMMERCE_INTERIOR), tempId, commerceCount;
- SQL::ReadRetrievedRows(handle, i)
- {
- SQL::ReadInt(handle, "cint_id", tempId, i);
- SQL::ReadInt(handle, "cint_id", commerceInterior[tempId][ID], i);
- SQL::ReadString(handle, "cint_name", commerceInterior[tempId][Name], 50, i);
- SQL::ReadInt(handle, "cint_world", commerceInterior[tempId][World], i);
- SQL::ReadInt(handle, "cint_interior", commerceInterior[tempId][Interior], i);
- SQL::ReadFloat(handle, "cint_posx", commerceInterior[tempId][intPosX], i);
- SQL::ReadFloat(handle, "cint_posy", commerceInterior[tempId][intPosY], i);
- SQL::ReadFloat(handle, "cint_posz", commerceInterior[tempId][intPosZ], i);
- commerceInterior[tempId][dynamicLabelId] = CreateDynamic3DTextLabel("Escribe /salirnegocio o presiona Y para salir del negocio.", -1, commerceInterior[tempId][intPosX], commerceInterior[tempId][intPosY], commerceInterior[tempId][intPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInterior[tempId][World], commerceInterior[tempId][Interior]);
- printf("[Interior] Se ha cargado el interior de negocio %s(ID: %d).", commerceInterior[tempId][Name], tempId);
- commerceCount++;
- }
- }
- updateCommerce(id, bool:redrawig = false)
- {
- new handle = SQL::Open(SQL::UPDATE, TBL_COMMERCE, "comm_id", id);
- SQL::WriteString(handle, "comm_name", commerceInfo[id][Name]);
- SQL::WriteInt(handle, "comm_owner", commerceInfo[id][Owner]);
- SQL::WriteInt(handle, "comm_price", commerceInfo[id][Price]);
- SQL::WriteString(handle, "comm_state", commerceInfo[id][State]);
- SQL::WriteFloat(handle, "comm_entryx", commerceInfo[id][entryPosX]);
- SQL::WriteFloat(handle, "comm_entryy", commerceInfo[id][entryPosY]);
- SQL::WriteFloat(handle, "comm_entryz", commerceInfo[id][entryPosZ]);
- SQL::Close(handle);
- printf("[Negocio] Se ha actualizado los datos del negocio %d", id);
- if(redrawig)
- {
- new strLabel[144 + 1];
- DestroyDynamic3DTextLabel(commerceInfo[id][dynamicLabelId]);
- if(!strcmp(commerceInfo[id][State], COMM_STATE_SALE, true))
- {
- format(strLabel, sizeof(strLabel), "%s (ID: %d)\nPropietario: %s\nPrecio: $%d\n\n/negocio comprar", commerceInfo[id][Name], id, commerceInfo[id][Owner], commerceInfo[id][Price]);
- commerceInfo[id][dynamicLabelId] = CreateDynamic3DTextLabel(strLabel, -1, commerceInfo[id][entryPosX], commerceInfo[id][entryPosY], commerceInfo[id][entryPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInfo[id][World], commerceInfo[id][Interior]);
- }
- else if(!strcmp(commerceInfo[id][State], COMM_STATE_NOTSALE, true))
- {
- format(strLabel, sizeof(strLabel), "%s (ID: %d)\nPropietario: %s", commerceInfo[id][Name], id, commerceInfo[id][Owner], commerceInfo[id][Price]);
- commerceInfo[id][dynamicLabelId] = CreateDynamic3DTextLabel(strLabel, -1, commerceInfo[id][entryPosX], commerceInfo[id][entryPosY], commerceInfo[id][entryPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInfo[id][World], commerceInfo[id][Interior]);
- }
- }
- return true;
- }
- getPlayerNearCommerce(playerid)
- {
- new nearId = -1;
- for(new a = 0, b = sizeof(commerceInfo); a < b; a++)
- {
- if( commerceInfo[a][ID] == 0 )
- continue;
- if( IsPlayerInRangeOfPoint(playerid, 10.0, commerceInfo[a][entryPosX], commerceInfo[a][entryPosY], commerceInfo[a][entryPosZ]) )
- {
- nearId = a;
- break;
- }
- }
- return nearId;
- }
- createCommerce(commName[], commPrice, commWorld, commInterior, commCustomInterior, Float:commPosX, Float:commPosY, Float:commPosZ)
- {
- new commerceId = 0;
- new handle = SQL::Open(SQL::INSERT, TBL_COMMERCE);
- SQL::ToggleAutoIncrement(handle, true);
- SQL::WriteString(handle, "comm_name", commName);
- SQL::WriteString(handle, "comm_state", COMM_STATE_SALE);
- SQL::WriteInt(handle, "comm_price", commPrice);
- SQL::WriteInt(handle, "comm_world", commWorld);
- SQL::WriteInt(handle, "comm_interior", commInterior);
- SQL::WriteInt(handle, "cint_id", commCustomInterior);
- SQL::WriteFloat(handle, "comm_entryposx", commPosX);
- SQL::WriteFloat(handle, "comm_entryposy", commPosY);
- SQL::WriteFloat(handle, "comm_entryposz", commPosZ);
- commerceId = SQL::Close(handle);
- commerceInfo[commerceId][ID] = commerceId;
- format(commerceInfo[commerceId][Name], 50, "%s", commName);
- commerceInfo[commerceId][Owner] = 0;
- format(commerceInfo[commerceId][ownerName], 30, "%s", "Mobilaria R&A");
- commerceInfo[commerceId][Price] = commPrice;
- format(commerceInfo[commerceId][State], 30, "%s", COMM_STATE_SALE);
- commerceInfo[commerceId][Interior] = commInterior;
- commerceInfo[commerceId][World] = commWorld;
- commerceInfo[commerceId][customInterior] = commCustomInterior;
- commerceInfo[commerceId][entryPosX] = commPosX;
- commerceInfo[commerceId][entryPosY] = commPosY;
- commerceInfo[commerceId][entryPosZ] = commPosZ;
- new strLabel[144 + 1];
- format(strLabel, sizeof(strLabel), "%s (ID: %d)\nPropietario: %s\nPrecio: $%d\n\n/negocio comprar", commerceInfo[commerceId][Name], commerceId, commerceInfo[commerceId][ownerName], commerceInfo[commerceId][Price]);
- commerceInfo[commerceId][dynamicLabelId] = CreateDynamic3DTextLabel(strLabel, -1, commerceInfo[commerceId][entryPosX], commerceInfo[commerceId][entryPosY], commerceInfo[commerceId][entryPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInfo[commerceId][World], commerceInfo[commerceId][Interior]);
- return commerceId;
- }
- createCommerceInterior(comIntName[], comIntWorld, comIntInterior, Float:comIntPosX, Float:comIntPosY, Float:comIntPosZ)
- {
- new commerceInteriorId = 0;
- new handle = SQL::Open(SQL::INSERT, TBL_COMMERCE_INTERIOR);
- SQL::ToggleAutoIncrement(handle, true);
- SQL::WriteString(handle, "cint_name", comIntName);
- SQL::WriteInt(handle, "cint_world", comIntWorld);
- SQL::WriteInt(handle, "cint_interior", comIntInterior);
- SQL::WriteFloat(handle, "cint_posx", comIntPosX);
- SQL::WriteFloat(handle, "cint_posy", comIntPosY);
- SQL::WriteFloat(handle, "cint_posz", comIntPosZ);
- commerceInteriorId = SQL::Close(handle);
- commerceInterior[commerceInteriorId][ID] = commerceInteriorId;
- format(commerceInterior[commerceInteriorId][Name], 30, "%s", comIntName);
- commerceInterior[commerceInteriorId][Interior] = comIntInterior;
- commerceInterior[commerceInteriorId][World] = comIntWorld;
- commerceInterior[commerceInteriorId][intPosX] = comIntPosX;
- commerceInterior[commerceInteriorId][intPosY] = comIntPosY;
- commerceInterior[commerceInteriorId][intPosZ] = comIntPosZ;
- commerceInterior[commerceInteriorId][dynamicLabelId] = CreateDynamic3DTextLabel("Escribe /salirnegocio o presiona Y para salir del negocio.", -1, commerceInterior[commerceInteriorId][intPosX], commerceInterior[commerceInteriorId][intPosY], commerceInterior[commerceInteriorId][intPosZ], 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, commerceInterior[commerceInteriorId][World], commerceInterior[commerceInteriorId][Interior]);
- return commerceInteriorId;
- }
- deleteCommerce(id)
- {
- SQL::DeleteRow(TBL_COMMERCE, "comm_id", id);
- DestroyDynamic3DTextLabel(commerceInfo[id][dynamicLabelId]);
- commerceInfo[id][Name][0] = EOS;
- commerceInfo[id][ownerName][0] = EOS;
- commerceInfo[id][ID] =
- commerceInfo[id][Owner] =
- commerceInfo[id][Price] =
- commerceInfo[id][State] =
- commerceInfo[id][Interior] =
- commerceInfo[id][World] =
- commerceInfo[id][customInterior] = 0;
- commerceInfo[id][entryPosX] =
- commerceInfo[id][entryPosY] =
- commerceInfo[id][entryPosZ] = 0.0;
- commerceInfo[id][dynamicLabelId] = STREAMER_TAG_3D_TEXT_LABEL:-1;
- return true;
- }
- deleteCommerceInterior(id)
- {
- SQL::DeleteRow(TBL_COMMERCE, "cint_id", id);
- DestroyDynamic3DTextLabel(commerceInterior[id][dynamicLabelId]);
- commerceInterior[id][Name][0] = EOS;
- commerceInterior[id][ID] =
- commerceInterior[id][Interior] =
- commerceInterior[id][World] = 0;
- commerceInterior[id][intPosX] =
- commerceInterior[id][intPosY] =
- commerceInterior[id][intPosZ] = 0.0;
- commerceInterior[id][dynamicLabelId] = STREAMER_TAG_3D_TEXT_LABEL:-1;
- return true;
- }
- existCommerceInterior(id)
- {
- new commerceInteriorId = 0;
- new handle = SQL::Open(SQL::READ, TBL_COMMERCE_INTERIOR, "cint_id", id);
- SQL::ReadInt(handle, "cint_id", commerceInteriorId);
- SQL::Close(handle);
- return ( (commerceInteriorId > 0 ) ? (true) : (false) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement