elseif ( source == ButtonBuyHouse ) then
local nHouse = guiGetText ( housenumber );
triggerServerEvent ( 'HouseSystemBuyHouse', localPlayer, tonumber ( nHouse ) );
end
server side :
addEvent("HouseSystemBuyHouse",true)
addEventHandler ("HouseSystemBuyHouse", getRootElement(),
function(housenumber)
local root = xmlLoadFile ("homes.xml")
local houseHeadRootNode = xmlFindChild (root,"houses",0)
local houseRootNode = xmlFindChild (houseHeadRootNode,"house",tonumber(housenumber))
local price = xmlNodeGetAttribute (houseRootNode,"cost")
local owner = xmlNodeGetAttribute (houseRootNode,"owner")
if not (isGuestAccount (getPlayerAccount(source))) then
if (owner == "") and (getPlayerMoney (source) >= tonumber(price)) then
takePlayerMoney (source,tonumber(price))
xmlNodeSetAttribute (houseRootNode,"owner",getAccountName(getPlayerAccount(source)))
outputChatBox ("Congratulations, you are the new owner!",source,255,0,0,false)
outputChatBox ("Price: ".. tostring(price) .. "$!",source,255,0,0,false)
for i,v in ipairs ( getElementsByType("pickup")) do
local number = getElementData ( v, "housenumber" )
if ( number == housenumber ) then
setPickupType ( v, 3, 1272 )
end
end
xmlSaveFile (root)
elseif not (owner == "") then
outputChatBox ("This house is already Bought!",source,255,0,0,false)
elseif (getPlayerMoney (source) < tonumber(price)) then
outputChatBox ("Sorry, you are too poor!",source,255,0,0,false)
end
end
xmlUnloadFile (root)
end
)