Merged realestate_listings into master
This commit is contained in:
commit
27e8f154d6
@ -24,3 +24,5 @@
|
|||||||
- Called when a player enters a vehicle as a driver
|
- Called when a player enters a vehicle as a driver
|
||||||
- `OnPlayerLogin( playerid, accountid )`
|
- `OnPlayerLogin( playerid, accountid )`
|
||||||
- Called when a player successfully logs into their account
|
- Called when a player successfully logs into their account
|
||||||
|
- `OnHouseOwnerChange( houseid, ownerid )`
|
||||||
|
- Called when the ownership of a home is changed
|
||||||
|
@ -8,3 +8,4 @@
|
|||||||
/* ** Includes ** */
|
/* ** Includes ** */
|
||||||
#include "irresistible\cnr\features\houses\house.pwn"
|
#include "irresistible\cnr\features\houses\house.pwn"
|
||||||
#include "irresistible\cnr\features\houses\furniture.pwn"
|
#include "irresistible\cnr\features\houses\furniture.pwn"
|
||||||
|
#include "irresistible\cnr\features\houses\realestate.pwn"
|
||||||
|
@ -488,6 +488,15 @@ hook OnPlayerSelectDynObject( playerid, objectid, modelid, Float:x, Float:y, Flo
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hook OnHouseOwnerChange( houseid, owner )
|
||||||
|
{
|
||||||
|
if ( owner != 0 ) // transfer furniture only to valid owner
|
||||||
|
{
|
||||||
|
mysql_single_query( sprintf( "UPDATE `FURNITURE` SET `OWNER`=%d WHERE `HOUSE_ID`=%d", owner, houseid ) );
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
hook OnPlayerConnect( playerid )
|
hook OnPlayerConnect( playerid )
|
||||||
{
|
{
|
||||||
//Katie - 271.884979,306.631988,999.148437 - DEFAULT - 2
|
//Katie - 271.884979,306.631988,999.148437 - DEFAULT - 2
|
||||||
|
@ -386,6 +386,7 @@ CMD:bruteforce( playerid, params[ ] )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CMD:house( playerid, params[ ] ) return cmd_h( playerid, params );
|
||||||
CMD:h( playerid, params[ ] )
|
CMD:h( playerid, params[ ] )
|
||||||
{
|
{
|
||||||
if ( p_accountSecurityData[ playerid ] [ E_ID ] && ! p_accountSecurityData[ playerid ] [ E_VERIFIED ] && p_accountSecurityData[ playerid ] [ E_MODE ] != SECURITY_MODE_DISABLED )
|
if ( p_accountSecurityData[ playerid ] [ E_ID ] && ! p_accountSecurityData[ playerid ] [ E_VERIFIED ] && p_accountSecurityData[ playerid ] [ E_MODE ] != SECURITY_MODE_DISABLED )
|
||||||
@ -397,9 +398,8 @@ CMD:h( playerid, params[ ] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
new
|
new
|
||||||
ID = p_InHouse[ playerid ],
|
ID = p_InHouse[ playerid ];
|
||||||
query[ 140 ]
|
|
||||||
;
|
|
||||||
if ( strmatch( params, "spawn" ) )
|
if ( strmatch( params, "spawn" ) )
|
||||||
{
|
{
|
||||||
SendServerMessage( playerid, "We have changed the command to simply "COL_GREY"/spawn"COL_WHITE"." );
|
SendServerMessage( playerid, "We have changed the command to simply "COL_GREY"/spawn"COL_WHITE"." );
|
||||||
@ -443,7 +443,7 @@ CMD:h( playerid, params[ ] )
|
|||||||
GivePlayerCash( playerid, -( g_houseData[ i ] [ E_COST ] ) );
|
GivePlayerCash( playerid, -( g_houseData[ i ] [ E_COST ] ) );
|
||||||
autosaveStart( playerid, true ); // force_save
|
autosaveStart( playerid, true ); // force_save
|
||||||
SendServerMessage( playerid, "You have bought this home for "COL_GOLD"%s"COL_WHITE"!", cash_format( g_houseData[ i ] [ E_COST ] ) );
|
SendServerMessage( playerid, "You have bought this home for "COL_GOLD"%s"COL_WHITE"!", cash_format( g_houseData[ i ] [ E_COST ] ) );
|
||||||
SetHouseOwner( i, ReturnPlayerName( playerid ) );
|
SetHouseOwner( i, p_AccountID[ playerid ], ReturnPlayerName( playerid ) );
|
||||||
|
|
||||||
p_OwnedHouses[ playerid ] ++;
|
p_OwnedHouses[ playerid ] ++;
|
||||||
return 1;
|
return 1;
|
||||||
@ -462,30 +462,10 @@ CMD:h( playerid, params[ ] )
|
|||||||
format( szBigString, sizeof( szBigString ), "[SELL] [%s] %s | %s | %d\r\n", getCurrentDate( ), ReturnPlayerName( playerid ), g_houseData[ ID ][ E_OWNER ], ID );
|
format( szBigString, sizeof( szBigString ), "[SELL] [%s] %s | %s | %d\r\n", getCurrentDate( ), ReturnPlayerName( playerid ), g_houseData[ ID ][ E_OWNER ], ID );
|
||||||
AddFileLogLine( "log_houses.txt", szBigString );
|
AddFileLogLine( "log_houses.txt", szBigString );
|
||||||
p_OwnedHouses[ playerid ] --;
|
p_OwnedHouses[ playerid ] --;
|
||||||
format( g_houseData[ ID ] [ E_PASSWORD ], 4, "N/A" );
|
SetHouseForAuction( ID );
|
||||||
format( g_houseData[ ID ] [ E_OWNER ], 7, "No-one" );
|
|
||||||
format( g_houseData[ ID ] [ E_HOUSE_NAME ], 5, "Home" );
|
|
||||||
for( new i; i < MAX_HOUSE_WEAPONS; i++ ) { g_HouseWeapons[ ID ] [ i ] = 0, g_HouseWeaponAmmo[ ID ] [ i ] = -1; }
|
|
||||||
SaveHouseWeaponStorage( ID );
|
|
||||||
GivePlayerCash( playerid, ( g_houseData[ ID ] [ E_COST ] / 2 ) );
|
GivePlayerCash( playerid, ( g_houseData[ ID ] [ E_COST ] / 2 ) );
|
||||||
destroyAllFurniture( ID );
|
|
||||||
FillHomeWithFurniture( ID, 0 );
|
|
||||||
g_houseData[ ID ] [ E_TX ] = g_houseInteriors[ 0 ] [ E_EX ];
|
|
||||||
g_houseData[ ID ] [ E_TY ] = g_houseInteriors[ 0 ] [ E_EY ];
|
|
||||||
g_houseData[ ID ] [ E_TZ ] = g_houseInteriors[ 0 ] [ E_EZ ];
|
|
||||||
g_houseData[ ID ] [ E_INTERIOR_ID ] = 2;
|
|
||||||
format( query, sizeof( query ), "UPDATE HOUSES SET OWNER='No-one',PASSWORD='N/A',NAME='Home',TX=%f,TY=%f,TZ=%f,INTERIOR=%d WHERE ID=%d", g_houseData[ ID ] [ E_TX ], g_houseData[ ID ] [ E_TY ], g_houseData[ ID ] [ E_TZ ], g_houseData[ ID ] [ E_INTERIOR_ID ], ID );
|
|
||||||
mysql_single_query( query );
|
|
||||||
format( szBigString, sizeof( szBigString ), ""COL_GOLD"House:"COL_WHITE" Home(%d)\n"COL_GOLD"Owner:"COL_WHITE" No-one\n"COL_GOLD"Price:"COL_WHITE" %s", ID, cash_format( g_houseData[ ID ] [ E_COST ] ) );
|
|
||||||
UpdateDynamic3DTextLabelText( g_houseData[ ID ] [ E_LABEL ] [ 0 ], COLOR_WHITE, szBigString );
|
|
||||||
DestroyDynamic3DTextLabel( g_houseData[ ID ] [ E_LABEL ] [ 1 ] );
|
|
||||||
g_houseData[ ID ] [ E_LABEL ] [ 1 ] = CreateDynamic3DTextLabel( "[EXIT]", COLOR_GOLD, g_houseData[ ID ] [ E_TX ], g_houseData[ ID ] [ E_TY ], g_houseData[ ID ] [ E_TZ ], 20.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, g_houseData[ ID ] [ E_WORLD ] );
|
|
||||||
DestroyDynamicCP( g_houseData[ ID ] [ E_CHECKPOINT ] [ 1 ] );
|
|
||||||
g_houseData[ ID ] [ E_CHECKPOINT ] [ 1 ] = CreateDynamicCP( g_houseData[ ID ] [ E_TX ], g_houseData[ ID ] [ E_TY ], g_houseData[ ID ] [ E_TZ ], 1.0, g_houseData[ ID ] [ E_WORLD ], g_houseData[ ID ] [ E_INTERIOR_ID ], -1, 50.0 );
|
|
||||||
SetPlayerPos( playerid, g_houseData[ ID ] [ E_EX ], g_houseData[ ID ] [ E_EY ], g_houseData[ ID ] [ E_EZ ] );
|
SetPlayerPos( playerid, g_houseData[ ID ] [ E_EX ], g_houseData[ ID ] [ E_EY ], g_houseData[ ID ] [ E_EZ ] );
|
||||||
DestroyDynamicMapIcon( g_houseData[ ID ] [ E_MAP_ICON ] );
|
SetPlayerInterior( playerid, 0 ), SetPlayerVirtualWorld( playerid, 0 );
|
||||||
SetPlayerInterior( playerid, 0 );
|
|
||||||
SetPlayerVirtualWorld( playerid, 0 );
|
|
||||||
SendServerMessage( playerid, "You have successfully sold your house for "COL_GOLD"%s", cash_format( ( g_houseData[ ID ] [ E_COST ] / 2 ) ) );
|
SendServerMessage( playerid, "You have successfully sold your house for "COL_GOLD"%s", cash_format( ( g_houseData[ ID ] [ E_COST ] / 2 ) ) );
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -534,8 +514,7 @@ CMD:h( playerid, params[ ] )
|
|||||||
p_OwnedHouses[ playerid ] ++;
|
p_OwnedHouses[ playerid ] ++;
|
||||||
|
|
||||||
// destroyAllFurniture( houseid );
|
// destroyAllFurniture( houseid );
|
||||||
mysql_single_query( sprintf( "UPDATE `FURNITURE` SET `OWNER`=%d WHERE `HOUSE_ID`=%d", p_AccountID[ playerid ], houseid ) );
|
SetHouseOwner( houseid, p_AccountID[ playerid ], ReturnPlayerName( playerid ) );
|
||||||
SetHouseOwner( houseid, ReturnPlayerName( playerid ) );
|
|
||||||
|
|
||||||
GivePlayerCash( playerid, -sellingprice );
|
GivePlayerCash( playerid, -sellingprice );
|
||||||
GivePlayerCash( sellerid, sellingprice );
|
GivePlayerCash( sellerid, sellingprice );
|
||||||
@ -621,7 +600,7 @@ thread OnHouseLoad( )
|
|||||||
// Make Lorenc the owner of unowned VIP houses
|
// Make Lorenc the owner of unowned VIP houses
|
||||||
foreach ( new houseid : houses ) if ( g_houseData[ houseid ] [ E_COST ] < 10000 ) {
|
foreach ( new houseid : houses ) if ( g_houseData[ houseid ] [ E_COST ] < 10000 ) {
|
||||||
if ( strmatch( g_houseData[ houseid ] [ E_OWNER ], "No-one" ) ) {
|
if ( strmatch( g_houseData[ houseid ] [ E_OWNER ], "No-one" ) ) {
|
||||||
SetHouseOwner( houseid, "Lorenc" );
|
SetHouseOwner( houseid, 1, "Lorenc" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -735,7 +714,9 @@ stock SetHouseForAuction( ID )
|
|||||||
SendClientMessage( player, -1, ""COL_PINK"[HOUSE]"COL_WHITE" One of your houses has been taken for auction.");
|
SendClientMessage( player, -1, ""COL_PINK"[HOUSE]"COL_WHITE" One of your houses has been taken for auction.");
|
||||||
p_OwnedHouses[ player ] --;
|
p_OwnedHouses[ player ] --;
|
||||||
}
|
}
|
||||||
|
CallLocalFunction( "OnHouseOwnerChange", "dd", ID, 0 );
|
||||||
for( new i; i < MAX_HOUSE_WEAPONS; i++ ) { g_HouseWeapons[ ID ] [ i ] = 0, g_HouseWeaponAmmo[ ID ] [ i ] = -1; }
|
for( new i; i < MAX_HOUSE_WEAPONS; i++ ) { g_HouseWeapons[ ID ] [ i ] = 0, g_HouseWeaponAmmo[ ID ] [ i ] = -1; }
|
||||||
|
SaveHouseWeaponStorage( ID );
|
||||||
format( g_houseData[ ID ] [ E_PASSWORD ], 4, "N/A" );
|
format( g_houseData[ ID ] [ E_PASSWORD ], 4, "N/A" );
|
||||||
format( g_houseData[ ID ] [ E_OWNER ], 7, "No-one" );
|
format( g_houseData[ ID ] [ E_OWNER ], 7, "No-one" );
|
||||||
format( g_houseData[ ID ] [ E_HOUSE_NAME ], 5, "Home" );
|
format( g_houseData[ ID ] [ E_HOUSE_NAME ], 5, "Home" );
|
||||||
@ -758,26 +739,29 @@ stock SetHouseForAuction( ID )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stock SetHouseOwner( houseid, szOwner[ MAX_PLAYER_NAME ] )
|
stock SetHouseOwner( houseid, owner, owner_name[ 24 ] )
|
||||||
{
|
{
|
||||||
if ( ! Iter_Contains( houses, houseid ) || isnull( szOwner ) )
|
if ( ! Iter_Contains( houses, houseid ) || ! strlen( owner_name ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
new
|
// copy home owner name to variable
|
||||||
query[ 128 ]
|
strcpy( g_houseData[ houseid ] [ E_OWNER ], owner_name );
|
||||||
;
|
|
||||||
format( g_houseData[ houseid ] [ E_OWNER ], 24, "%s", szOwner );
|
|
||||||
|
|
||||||
format( query, sizeof( query ), "UPDATE HOUSES SET OWNER='%s' WHERE ID=%d", mysql_escape( szOwner ), houseid );
|
// update in database
|
||||||
mysql_single_query( query );
|
mysql_format( dbHandle, szNormalString, sizeof( szNormalString ), "UPDATE HOUSES SET OWNER='%e' WHERE ID=%d", g_houseData[ houseid ] [ E_OWNER ], houseid );
|
||||||
|
mysql_single_query( szNormalString );
|
||||||
|
|
||||||
|
// callback when the home owner changes
|
||||||
|
CallLocalFunction( "OnHouseOwnerChange", "dd", houseid, owner );
|
||||||
|
|
||||||
|
// refresh label
|
||||||
DestroyDynamicMapIcon( g_houseData[ houseid ] [ E_MAP_ICON ] );
|
DestroyDynamicMapIcon( g_houseData[ houseid ] [ E_MAP_ICON ] );
|
||||||
format( szBigString, sizeof( szBigString ), ""COL_GOLD"House:"COL_WHITE" Home(%d)\n"COL_GOLD"Owner:"COL_WHITE" %s\n"COL_GOLD"Price:"COL_WHITE" %s", houseid, g_houseData[ houseid ] [ E_OWNER ], cash_format( g_houseData[ houseid ] [ E_COST ] ) );
|
format( szBigString, sizeof( szBigString ), ""COL_GOLD"House:"COL_WHITE" Home(%d)\n"COL_GOLD"Owner:"COL_WHITE" %s\n"COL_GOLD"Price:"COL_WHITE" %s", houseid, g_houseData[ houseid ] [ E_OWNER ], cash_format( g_houseData[ houseid ] [ E_COST ] ) );
|
||||||
UpdateDynamic3DTextLabelText( g_houseData[ houseid ] [ E_LABEL ] [ 0 ], COLOR_WHITE, szBigString );
|
UpdateDynamic3DTextLabelText( g_houseData[ houseid ] [ E_LABEL ] [ 0 ], COLOR_WHITE, szBigString );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stock SwitchHouseOwners( ID, playerid, buyerid )
|
/*stock SwitchHouseOwners( ID, playerid, buyerid )
|
||||||
{
|
{
|
||||||
if ( IsPlayerConnected( playerid ) )
|
if ( IsPlayerConnected( playerid ) )
|
||||||
{
|
{
|
||||||
@ -805,7 +789,7 @@ stock SwitchHouseOwners( ID, playerid, buyerid )
|
|||||||
g_houseData[ ID ] [ E_CHECKPOINT ] [ 1 ] = CreateDynamicCP( g_houseData[ ID ] [ E_TX ], g_houseData[ ID ] [ E_TY ], g_houseData[ ID ] [ E_TZ ], 1.0, g_houseData[ ID ] [ E_WORLD ], g_houseData[ ID ] [ E_INTERIOR_ID ], -1, 50.0 );
|
g_houseData[ ID ] [ E_CHECKPOINT ] [ 1 ] = CreateDynamicCP( g_houseData[ ID ] [ E_TX ], g_houseData[ ID ] [ E_TY ], g_houseData[ ID ] [ E_TZ ], 1.0, g_houseData[ ID ] [ E_WORLD ], g_houseData[ ID ] [ E_INTERIOR_ID ], -1, 50.0 );
|
||||||
|
|
||||||
DestroyDynamicMapIcon( g_houseData[ ID ] [ E_MAP_ICON ] );
|
DestroyDynamicMapIcon( g_houseData[ ID ] [ E_MAP_ICON ] );
|
||||||
}
|
}*/
|
||||||
|
|
||||||
stock GetPlayerOwnedHouses( playerid )
|
stock GetPlayerOwnedHouses( playerid )
|
||||||
{
|
{
|
||||||
|
315
gamemodes/irresistible/cnr/features/houses/realestate.pwn
Normal file
315
gamemodes/irresistible/cnr/features/houses/realestate.pwn
Normal file
@ -0,0 +1,315 @@
|
|||||||
|
/*
|
||||||
|
* Irresistible Gaming (c) 2018
|
||||||
|
* Developed by Lorenc Pekaj
|
||||||
|
* Module: cnr\features\home\realestate.pwn
|
||||||
|
* Purpose: home listings for player homes
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* ** Includes ** */
|
||||||
|
#include < YSI\y_hooks >
|
||||||
|
|
||||||
|
/* ** Definitions ** */
|
||||||
|
#define DIALOG_HOUSE_LISTINGS 5838
|
||||||
|
#define DIALOG_HOUSE_LIST_VIEW 5839
|
||||||
|
|
||||||
|
/* ** Macros ** */
|
||||||
|
#define ShowPlayerHomeListings(%0) \
|
||||||
|
mysql_tquery( dbHandle, "SELECT HL.ID, HL.HOUSE_ID, H.NAME, U.NAME AS OWNER, HL.ASK FROM HOUSE_LISTINGS HL INNER JOIN HOUSES H ON H.ID = HL.HOUSE_ID INNER JOIN USERS U ON U.ID = HL.USER_ID WHERE SALE_DATE IS NULL", "HouseListing_OnShowHomes", "d", %0 )
|
||||||
|
|
||||||
|
#define ShowPlayerHomeListing(%0,%1) \
|
||||||
|
mysql_tquery( dbHandle, sprintf( "SELECT * FROM `HOUSE_LISTINGS` WHERE `ID` = %d", %1 ), "HouseListing_OnShowHome", "dd", %0, %1 )
|
||||||
|
|
||||||
|
/* ** Constants ** */
|
||||||
|
static const
|
||||||
|
HOUSE_LISTING_FEE = 75000;
|
||||||
|
|
||||||
|
/* ** Variables ** */
|
||||||
|
static stock
|
||||||
|
p_CurrentListings [ MAX_PLAYERS ] [ 50 ]; // TODO: add pagination
|
||||||
|
|
||||||
|
/* ** Hooks ** */
|
||||||
|
hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
|
||||||
|
{
|
||||||
|
if ( dialogid == DIALOG_HOUSE_LISTINGS && response )
|
||||||
|
{
|
||||||
|
for ( new i = 0, x = 0; i < sizeof ( p_CurrentListings ); i ++ ) if ( p_CurrentListings[ playerid ] [ i ] != -1 )
|
||||||
|
{
|
||||||
|
if ( x == listitem )
|
||||||
|
{
|
||||||
|
ShowPlayerHomeListing( playerid, p_CurrentListings[ playerid ] [ i ] );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( dialogid == DIALOG_HOUSE_LIST_VIEW )
|
||||||
|
{
|
||||||
|
if ( ! response )
|
||||||
|
return ShowPlayerHomeListings( playerid );
|
||||||
|
|
||||||
|
new houseid = GetPVarInt( playerid, "house_listing_houseid" );
|
||||||
|
new listingid = GetPVarInt( playerid, "house_listing_viewid" );
|
||||||
|
|
||||||
|
switch ( listitem )
|
||||||
|
{
|
||||||
|
case 0: mysql_tquery( dbHandle, sprintf( "SELECT *, UNIX_TIMESTAMP(`SALE_DATE`) as `SALE_DATE_TS` FROM `HOUSE_LISTINGS` WHERE `ID` = %d", listingid ), "HouseListing_OnBuyHome", "dd", playerid, listingid );
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if ( IsPlayerInAnyVehicle( playerid ) )
|
||||||
|
{
|
||||||
|
GPS_SetPlayerWaypoint( playerid, g_houseData[ houseid ] [ E_HOUSE_NAME ], g_houseData[ houseid ] [ E_EX ], g_houseData[ houseid ] [ E_EY ], g_houseData[ houseid ] [ E_EZ ] );
|
||||||
|
SendClientMessageFormatted( playerid, -1, ""COL_GREY"[GPS]"COL_WHITE" You have set your destination to %s. Follow the arrow to reach your destination.", g_houseData[ houseid ] [ E_HOUSE_NAME ] );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowPlayerHomeListing( playerid, listingid );
|
||||||
|
SendError( playerid, "You need to be in a vehicle to set a GPS waypoint." );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hook OnHouseOwnerChange( houseid, owner )
|
||||||
|
{
|
||||||
|
mysql_single_query( sprintf( "DELETE FROM `HOUSE_LISTINGS` WHERE `HOUSE_ID` = %d AND `SALE_DATE` IS NULL", houseid ) );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ** Commands ** */
|
||||||
|
CMD:realestate( playerid, params[ ] ) return cmd_estate( playerid, params );
|
||||||
|
CMD:estate( playerid, params[ ] )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
houseid = p_InHouse[ playerid ];
|
||||||
|
|
||||||
|
if ( strmatch( params, "list cancel" ) )
|
||||||
|
{
|
||||||
|
if ( ! Iter_Contains( houses, houseid ) ) return SendError( playerid, "You are not inside of any home." );
|
||||||
|
else if ( ! IsPlayerHomeOwner( playerid, houseid ) ) return SendError( playerid, "You are not the owner of this home." );
|
||||||
|
{
|
||||||
|
mysql_tquery( dbHandle, sprintf( "DELETE FROM `HOUSE_LISTINGS` WHERE `HOUSE_ID` = %d AND `SALE_DATE` IS NULL", houseid ), "HouseListing_OnDeleteListing", "dd", playerid, houseid );
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if ( !strcmp( params, "list", false, 4 ) )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
Float: coins;
|
||||||
|
|
||||||
|
if ( sscanf( params[ 5 ], "f", coins ) ) return SendUsage( playerid, "/estate list [IC_ASK_PRICE/CANCEL]");
|
||||||
|
else if ( ! Iter_Contains( houses, houseid ) ) return SendError( playerid, "You are not inside of any home." );
|
||||||
|
else if ( g_houseData[ houseid ] [ E_COST ] > 2500 ) return SendError( playerid, "This home is not a V.I.P home." );
|
||||||
|
else if ( ! IsPlayerHomeOwner( playerid, houseid ) ) return SendError( playerid, "You are not the owner of this home." );
|
||||||
|
else if ( coins < 25.0 ) return SendError( playerid, "Please specify an ask price greater than 25.00 IC." );
|
||||||
|
else if ( coins > 25000.0 ) return SendError( playerid, "Please specify an ask price less than 25,000 IC." );
|
||||||
|
else if ( GetPlayerCash( playerid ) < HOUSE_LISTING_FEE && GetPlayerVIPLevel( playerid ) < VIP_GOLD ) return SendError( playerid, "You need at least %s to create a house listing.", cash_format( HOUSE_LISTING_FEE ) );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mysql_tquery( dbHandle, sprintf( "SELECT * FROM `HOUSE_LISTINGS` WHERE `HOUSE_ID` = %d AND `SALE_DATE` IS NULL", houseid ), "HouseListing_OnCreateListing", "ddf", playerid, houseid, coins );
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ShowPlayerHomeListings( playerid );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ** SQL Threads ** */
|
||||||
|
thread HouseListing_OnShowHomes( playerid )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
rows = cache_get_row_count( );
|
||||||
|
|
||||||
|
if ( rows )
|
||||||
|
{
|
||||||
|
static
|
||||||
|
location[ MAX_ZONE_NAME ],
|
||||||
|
city[ 3 ],
|
||||||
|
house_name[ 32 ],
|
||||||
|
owner[ 24 ];
|
||||||
|
|
||||||
|
// set headers
|
||||||
|
szLargeString = ""COL_GREY"House\t"COL_GREY"Owner\t"COL_GREY"Location\t"COL_GREY"Ask Price (IC)\n";
|
||||||
|
|
||||||
|
for ( new row = 0; row < sizeof ( p_CurrentListings[ ] ); row ++ )
|
||||||
|
{
|
||||||
|
if ( row < rows )
|
||||||
|
{
|
||||||
|
// store all the listing ids to the player
|
||||||
|
p_CurrentListings[ playerid ] [ row ] = cache_get_field_content_int( row, "ID" );
|
||||||
|
|
||||||
|
cache_get_field_content( row, "NAME", house_name );
|
||||||
|
cache_get_field_content( row, "OWNER", owner );
|
||||||
|
|
||||||
|
new houseid = cache_get_field_content_int( row, "HOUSE_ID" );
|
||||||
|
|
||||||
|
Get2DCityShort( city, g_houseData[ houseid ] [ E_EX ], g_houseData[ houseid ] [ E_EY ] );
|
||||||
|
GetZoneFromCoordinates( location, g_houseData[ houseid ] [ E_EX ], g_houseData[ houseid ] [ E_EY ], .placeholder = "Island" );
|
||||||
|
|
||||||
|
new Float: coins = cache_get_field_content_float( row, "ASK" );
|
||||||
|
|
||||||
|
format( szLargeString, sizeof( szLargeString ), "%s%s\t%s\t%s, %s\t"COL_GREEN"%s IC\n", szLargeString, house_name, owner, location, city, number_format( coins, .decimals = 2 ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p_CurrentListings[ playerid ] [ row ] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SendServerMessage( playerid, "You can list your own home using "COL_GREY"/estate list"COL_WHITE" for %s (or free if you're GOLD V.I.P).", cash_format( HOUSE_LISTING_FEE ) );
|
||||||
|
return ShowPlayerDialog( playerid, DIALOG_HOUSE_LISTINGS, DIALOG_STYLE_TABLIST_HEADERS, ""COL_GOLD"Irresistible Coin - "COL_WHITE"Premium Home Estate", szLargeString, "Select", "Back" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SendError( playerid, "There are no available homes for sale at current." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread HouseListing_OnShowHome( playerid, house_listing_id )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
rows = cache_get_row_count( );
|
||||||
|
|
||||||
|
if ( rows )
|
||||||
|
{
|
||||||
|
new house_id = cache_get_field_content_int( 0, "HOUSE_ID" );
|
||||||
|
new Float: coins = cache_get_field_content_float( 0, "ASK" );
|
||||||
|
|
||||||
|
SetPVarInt( playerid, "house_listing_viewid", house_listing_id );
|
||||||
|
SetPVarInt( playerid, "house_listing_houseid", house_id );
|
||||||
|
|
||||||
|
return ShowPlayerDialog(
|
||||||
|
playerid, DIALOG_HOUSE_LIST_VIEW, DIALOG_STYLE_TABLIST,
|
||||||
|
""COL_GOLD"Irresistible Coin - "COL_WHITE"Premium Home Estate",
|
||||||
|
sprintf( "Purchase Home\t"COL_GREEN"%s IC\nSet GPS Waypoint\t"COL_GREY">>>", number_format( coins, .decimals = 2 ) ),
|
||||||
|
"Select", "Back"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SendError( playerid, "An error has occurred, please try again." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread HouseListing_OnBuyHome( playerid, house_listing_id )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
rows = cache_get_row_count( );
|
||||||
|
|
||||||
|
if ( rows )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
Float: ask_price = cache_get_field_content_float( 0, "ASK" );
|
||||||
|
|
||||||
|
// does the dude even have the coins
|
||||||
|
if ( GetPlayerIrresistibleCoins( playerid ) < ask_price ) {
|
||||||
|
ShowPlayerHomeListing( playerid, house_listing_id );
|
||||||
|
return SendError( playerid, "You do not have enough Irresistible Coins for this home (%s IC).", number_format( ask_price, .decimals = 2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if sale already completed
|
||||||
|
new
|
||||||
|
sale_date_ts = cache_get_field_content_int( 0, "SALE_DATE_TS" );
|
||||||
|
|
||||||
|
if ( sale_date_ts != 0 && GetServerTime( ) > sale_date_ts ) {
|
||||||
|
return SendError( playerid, "You can no longer buy this home as it has been sold." );
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if buyer is the player himself
|
||||||
|
new
|
||||||
|
owner_account_id = cache_get_field_content_int( 0, "USER_ID" );
|
||||||
|
|
||||||
|
if ( GetPlayerAccountID( playerid ) == owner_account_id ) {
|
||||||
|
ShowPlayerHomeListing( playerid, house_listing_id );
|
||||||
|
return SendError( playerid, "You cannot buy your own home." );
|
||||||
|
}
|
||||||
|
|
||||||
|
// credit seller if they are on/offline
|
||||||
|
new
|
||||||
|
sellerid;
|
||||||
|
|
||||||
|
foreach ( sellerid : Player ) if ( GetPlayerAccountID( sellerid ) == owner_account_id ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate seller id
|
||||||
|
if ( 0 <= sellerid < MAX_PLAYERS && Iter_Contains( Player, sellerid ) ) {
|
||||||
|
p_OwnedHouses[ sellerid ] --;
|
||||||
|
GivePlayerIrresistibleCoins( sellerid, ask_price );
|
||||||
|
SendServerMessage( sellerid, "You have successfully sold your house for "COL_GOLD"%s IC"COL_WHITE" to %s(%d)!", number_format( ask_price, .decimals = 2 ), ReturnPlayerName( playerid ), playerid );
|
||||||
|
} else {
|
||||||
|
mysql_single_query( sprintf( "UPDATE `USERS` SET `COINS` = `COINS` + %0.2f WHERE `ID` = %d", ask_price, owner_account_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
new
|
||||||
|
houseid = cache_get_field_content_int( 0, "HOUSE_ID" );
|
||||||
|
|
||||||
|
// show sellers name & house name
|
||||||
|
SendServerMessage( playerid, "You have successfully bought %s's home (%s"COL_WHITE") for "COL_GOLD"%s IC"COL_WHITE"!", g_houseData[ houseid ] [ E_OWNER ], g_houseData[ houseid ] [ E_HOUSE_NAME ], number_format( ask_price, .decimals = 2 ) );
|
||||||
|
|
||||||
|
// set listing as sold and transfer home
|
||||||
|
mysql_single_query( sprintf( "UPDATE `HOUSE_LISTINGS` SET `SALE_DATE` = CURRENT_TIMESTAMP WHERE `ID` = %d", house_listing_id ) );
|
||||||
|
SetHouseOwner( houseid, GetPlayerAccountID( playerid ), ReturnPlayerName( playerid ) );
|
||||||
|
GivePlayerIrresistibleCoins( playerid, -ask_price );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SendError( playerid, "An error has occurred, please try again." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread HouseListing_OnCreateListing( playerid, houseid, Float: ask_price )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
rows = cache_get_row_count( );
|
||||||
|
|
||||||
|
if ( ! rows )
|
||||||
|
{
|
||||||
|
// debit user account
|
||||||
|
if ( GetPlayerVIPLevel( playerid ) < VIP_GOLD ) {
|
||||||
|
GivePlayerCash( playerid, -HOUSE_LISTING_FEE );
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert into database and notify
|
||||||
|
mysql_single_query( sprintf( "INSERT INTO `HOUSE_LISTINGS` (`HOUSE_ID`, `USER_ID`, `ASK`) VALUES (%d, %d, %f)", houseid, GetPlayerAccountID( playerid ), ask_price ) );
|
||||||
|
return SendServerMessage( playerid, "You have listed your home. You can retract your listing using "COL_GREY"/estate list cancel"COL_WHITE"." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SendError( playerid, "This home is already listed. You can retract your listing using "COL_GREY"/estate list cancel"COL_WHITE"." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thread HouseListing_OnDeleteListing( playerid, houseid )
|
||||||
|
{
|
||||||
|
new
|
||||||
|
deleted_rows = cache_affected_rows( );
|
||||||
|
|
||||||
|
if ( deleted_rows )
|
||||||
|
{
|
||||||
|
return SendServerMessage( playerid, "You have delisted your home. You can create a new listing using "COL_GREY"/estate list"COL_WHITE"." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SendError( playerid, "This home is not listed on the premium realestate market." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ** Migrations ** */
|
||||||
|
/*
|
||||||
|
DROP TABLE HOUSE_LISTINGS;
|
||||||
|
CREATE TABLE IF NOT EXISTS HOUSE_LISTINGS (
|
||||||
|
ID int(11) AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
HOUSE_ID int(11),
|
||||||
|
USER_ID int(11),
|
||||||
|
ASK float,
|
||||||
|
LISTING_DATE TIMESTAMP default CURRENT_TIMESTAMP,
|
||||||
|
SALE_DATE TIMESTAMP nullable default null,
|
||||||
|
FOREIGN KEY (HOUSE_ID) REFERENCES HOUSES (ID) ON DELETE CASCADE
|
||||||
|
)
|
||||||
|
*/
|
@ -14,19 +14,19 @@ enum SAZONE_MAIN {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum MainCity {
|
enum MainCity {
|
||||||
City_Name[MAX_ZONE_NAME], Float:City_Area[6]
|
City_Short[3], City_Name[MAX_ZONE_NAME], Float:City_Area[6]
|
||||||
};
|
};
|
||||||
|
|
||||||
static const gSACitys[9][MainCity] = {
|
static const gSACitys[9][MainCity] = {
|
||||||
{"Los Santos", {44.60,-2892.90,-242.90,2997.00,-768.00,900.00} },
|
{"LS", "Los Santos", {44.60,-2892.90,-242.90,2997.00,-768.00,900.00} },
|
||||||
{"Las Venturas", {869.40,596.30,-242.90,2997.00,2993.80,900.00} },
|
{"LV", "Las Venturas", {869.40,596.30,-242.90,2997.00,2993.80,900.00} },
|
||||||
{"Bone County", {-480.50,596.30,-242.90,869.40,2993.80,900.00} },
|
{"BC", "Bone County", {-480.50,596.30,-242.90,869.40,2993.80,900.00} },
|
||||||
{"Tierra Robada", {-2997.40,1659.60,-242.90,-480.50,2993.80,900.00} },
|
{"TR", "Tierra Robada", {-2997.40,1659.60,-242.90,-480.50,2993.80,900.00} },
|
||||||
{"Tierra Robada", {-1213.90,596.30,-242.90,-480.50,1659.60,900.00} },
|
{"TR", "Tierra Robada", {-1213.90,596.30,-242.90,-480.50,1659.60,900.00} },
|
||||||
{"San Fierro", {-2997.40,-1115.50,-242.90,-1213.90,1659.60,900.00} },
|
{"SF", "San Fierro", {-2997.40,-1115.50,-242.90,-1213.90,1659.60,900.00} },
|
||||||
{"Red County", {-1213.90,-768.00,-242.90,2997.00,596.30,900.00} },
|
{"RC", "Red County", {-1213.90,-768.00,-242.90,2997.00,596.30,900.00} },
|
||||||
{"Flint County", {-1213.90,-2892.90,-242.90,44.60,-768.00,900.00} },
|
{"FC", "Flint County", {-1213.90,-2892.90,-242.90,44.60,-768.00,900.00} },
|
||||||
{"Whetstone", {-2997.40,-2892.90,-242.90,-1213.90,-1115.50,900.00}}
|
{"WS", "Whetstone", {-2997.40,-2892.90,-242.90,-1213.90,-1115.50,900.00}}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const gSAZones[][SAZONE_MAIN] = {
|
static const gSAZones[][SAZONE_MAIN] = {
|
||||||
@ -421,7 +421,19 @@ stock Get2DCity(zone[], Float:x, Float:y, Float:z = 0.0)
|
|||||||
return format(zone, MAX_ZONE_NAME, "San Andreas");
|
return format(zone, MAX_ZONE_NAME, "San Andreas");
|
||||||
}
|
}
|
||||||
|
|
||||||
stock GetZoneFromCoordinates( zone[ ], Float: x, Float: y, Float: z = 0.0 )
|
stock Get2DCityShort(zone[], Float:x, Float:y)
|
||||||
|
{
|
||||||
|
for( new i = 0, s = sizeof(gSACitys); i < s; i++ )
|
||||||
|
{
|
||||||
|
if(x >= gSACitys[i][City_Area][0] && x <= gSACitys[i][City_Area][3] && y >= gSACitys[i][City_Area][1] && y <= gSACitys[i][City_Area][4])
|
||||||
|
{
|
||||||
|
return format(zone, MAX_ZONE_NAME, gSACitys[i][City_Short]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return format(zone, MAX_ZONE_NAME, "SA");
|
||||||
|
}
|
||||||
|
|
||||||
|
stock GetZoneFromCoordinates( zone[ ], Float: x, Float: y, Float: z = 0.0, const placeholder[ ] = "a place" )
|
||||||
{
|
{
|
||||||
#pragma unused z
|
#pragma unused z
|
||||||
|
|
||||||
@ -433,7 +445,7 @@ stock GetZoneFromCoordinates( zone[ ], Float: x, Float: y, Float: z = 0.0 )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if( i >= sizeof( gSAZones ) )
|
if( i >= sizeof( gSAZones ) )
|
||||||
return format( zone, MAX_ZONE_NAME, "a place" );
|
return format( zone, MAX_ZONE_NAME, placeholder );
|
||||||
|
|
||||||
return strmid( zone, gSAZones[ i ] [ SAZONE_NAME ], false, strlen( gSAZones[ i ] [ SAZONE_NAME ] ), MAX_ZONE_NAME );
|
return strmid( zone, gSAZones[ i ] [ SAZONE_NAME ], false, strlen( gSAZones[ i ] [ SAZONE_NAME ] ), MAX_ZONE_NAME );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user