Add callback OnHouseOwnerChange

This commit is contained in:
Lorenc Pekaj 2018-09-25 03:46:21 +10:00
parent 308ea77b57
commit 2bb7604548
4 changed files with 31 additions and 19 deletions

View File

@ -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

View File

@ -488,6 +488,12 @@ hook OnPlayerSelectDynObject( playerid, objectid, modelid, Float:x, Float:y, Flo
return 1; return 1;
} }
hook OnHouseOwnerChange( houseid, 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

View File

@ -444,7 +444,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;
@ -535,7 +535,7 @@ CMD:h( playerid, params[ ] )
p_OwnedHouses[ playerid ] ++; p_OwnedHouses[ playerid ] ++;
// destroyAllFurniture( houseid ); // destroyAllFurniture( houseid );
SetHouseOwner( houseid, ReturnPlayerName( playerid ), .buyerid = playerid ); SetHouseOwner( houseid, p_AccountID[ playerid ], ReturnPlayerName( playerid ) );
GivePlayerCash( playerid, -sellingprice ); GivePlayerCash( playerid, -sellingprice );
GivePlayerCash( sellerid, sellingprice ); GivePlayerCash( sellerid, sellingprice );
@ -621,7 +621,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" );
} }
} }
@ -758,31 +758,29 @@ stock SetHouseForAuction( ID )
return 1; return 1;
} }
stock SetHouseOwner( houseid, szOwner[ MAX_PLAYER_NAME ], buyerid = INVALID_PLAYER_ID ) 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 );
// transfer furniture to account // callback when the home owner changes
if ( buyerid != INVALID_PLAYER_ID ) { CallLocalFunction( "OnHouseOwnerChange", "dd", houseid, owner );
mysql_single_query( sprintf( "UPDATE `FURNITURE` SET `OWNER`=%d WHERE `HOUSE_ID`=%d", p_AccountID[ buyerid ], houseid ) );
}
// 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 ) )
{ {
@ -810,7 +808,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 )
{ {

View File

@ -72,6 +72,12 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
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 ** */ /* ** Commands ** */
hook cmd_h( playerid, params[ ] ) hook cmd_h( playerid, params[ ] )
{ {
@ -236,7 +242,7 @@ thread HouseListing_OnBuyHome( playerid, house_listing_id )
// set listing as sold and transfer home // 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 ) ); mysql_single_query( sprintf( "UPDATE `HOUSE_LISTINGS` SET `SALE_DATE` = CURRENT_TIMESTAMP WHERE `ID` = %d", house_listing_id ) );
SetHouseOwner( houseid, ReturnPlayerName( playerid ), .buyerid = playerid ); SetHouseOwner( houseid, GetPlayerAccountID( playerid ), ReturnPlayerName( playerid ) );
GivePlayerIrresistibleCoins( playerid, -ask_price ); GivePlayerIrresistibleCoins( playerid, -ask_price );
return 1; return 1;
} }