sckatchof Posted April 15, 2012 Share Posted April 15, 2012 hi guys i have a problem when i buy a house nothing ir save in my xml file and pick up don't change this is my event 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 ("You have buy this house for : ".. tostring(price) .. "$",source,255,255,255,false) for i,v in ipairs ( getElementsByType("pickup")) do local number = getElementData ( v, "housenumber" ) if ( number == housenumber ) then setPickupType ( v, 3, 1273 ) 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 ("You don't have enough money.",source,255,0,0,false) end end triggerClientEvent (source,"hideHouseGuiWindow",source) xmlUnloadFile (root) end) Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 Check conditions, use debugscript and tell us what part don't work and explain in a proper english. Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Check conditions, use debugscript and tell us what part don't work and explain in a proper english. nothing it show in debugscript and it work but when i click buy house it show that msg outputChatBox ("You have buy this hou... and and take my money but owner don't save and pickup don't change Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 Check local houseRootNode = xmlFindChild (houseHeadRootNode,"house",tonumber(housenumber)) . Use statement "if" to check if houseRootNode is found and use xmlNodeSetValue instead of xmlNodeSetAttribute. Also, check pickup element data. Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Check local houseRootNode = xmlFindChild (houseHeadRootNode,"house",tonumber(housenumber)) . Use statement "if" to check if houseRootNode is found and use xmlNodeSetValue instead of xmlNodeSetAttribute. Also, check pickup element data. sorry but i don't understand writ me a example if you want . Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 (edited) addEvent ( 'HouseSystemBuyHouse', true ); addEventHandler ( 'HouseSystemBuyHouse', root, function ( nHouse ) local fRoot = xmlLoadFile ( 'homes.xml' ); local fNode = xmlFindChild ( fRoot, 'houses', 0 ) local fHouse = xmlFindChild ( fNode, 'house', tonumber ( nHouse ) ); if ( fHouse ) then local fPrice = xmlNodeGetValue ( fHouse, 'cost' ); local fOwner = xmlNodeGetValue ( fHouse, 'owner' ); if ( not isGuestAccount ( getPlayerAccount ( source ) ) ) then if ( fOwner == '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then takePlayerMoney ( source, tonumber ( fPrice ) ); xmlNodeSetValue ( xmlFindChild ( fHouse, 'owner', 0 ), getAccountName ( getPlayerAccount ( source ) ) ); outputChatBox ( 'You have bought this house for: $' .. price, source, 255, 255, 255, false ); for _, cPickup in ipairs ( getElementsByType 'pickup' ) do if ( getElementData ( cPickup, 'housenumber' ) == nHouse ) then -- check element data 'housenumber' setPickupType ( v, 3, 1273 ); end end xmlSaveFile ( fRoot ) elseif ( fOwner ~= '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then outputChatBox ( 'This house has been already bought!', source, 255, 0, 0, false ); elseif ( getPlayerMoney ( source ) < tonumber ( fPrice ) ) then outputChatBox ( 'You do not have sufficient money!', source, 255, 0, 0, false ); end end else outputChatBox 'Node not found!'; end triggerClientEvent ( source, 'hideHouseGuiWindow', source ); xmlUnloadFile ( fRoot ); end ) Try. Also, check if in chatbox appear 'Node not found!'. Edited April 15, 2012 by Guest Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 (edited) thank for help but it show ( Node not found!' ) and this is my xml file "0" interior="0" x="2495.375" y="-1691.1376953125" z="14.765625" cost="500000" owner="sckatchof" dim="1" /> ... ... Edited April 15, 2012 by Guest Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 Ok. Problem found. Child 'house' where 'house' is nHouse not found. Show your homes.xml Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 (edited) Ok. Problem found. Child 'house' where 'house' is nHouse not found. Show your homes.xml homes.xml Edited April 20, 2012 by Guest Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Copy my code again. thanks for help but don't work . it show in debugscript 3 like this pic : Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 line 1and 2 and lien 14 local fPrice = xmlNodeGetValue ( fHouse, 'cost' ); local fOwner = xmlNodeGetValue ( fHouse, 'owner' ); if ( not isGuestAccount ( getPlayerAccount ( source ) ) ) then if ( fOwner == '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then takePlayerMoney ( source, tonumber ( fPrice ) ); xmlNodeSetValue ( xmlFindChild ( fHouse, 'owner', 0 ), getAccountName ( getPlayerAccount ( source ) ) ); outputChatBox ( 'You have bought this house for: $' .. price, source, 255, 255, 255, false ); for _, cPickup in ipairs ( getElementsByType 'pickup' ) do if ( getElementData ( cPickup, 'housenumber' ) == nHouse ) then -- check element data 'housenumber' setPickupType ( v, 3, 1273 ); end end xmlSaveFile ( fRoot ) elseif ( fOwner ~= '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 Check if house child index 'nHouse' exists. I can't find any error. Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Check if house child index 'nHouse' exists. I can't find any error. it exists Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 Check what's type of nHouse and what number is nHouse. Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Check what's type of nHouse and what number is nHouse. how can i check ! Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 outputChatBox ( type ( nHouse ) .. ' - ' .. nHouse ); Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 outputChatBox ( type ( nHouse ) .. ' - ' .. nHouse ); DraKen i realy don't understand i want when i click buy house it save my account name in xml file and pick up change that what i want and thnx for help again Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Error in this line elseif ( fOwner ~= '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then and wornig in this lines local fPrice = xmlNodeGetValue ( fHouse, 'cost' ); local fOwner = xmlNodeGetValue ( fHouse, 'owner' ); line 1and 2 and lien 14 local fPrice = xmlNodeGetValue ( fHouse, 'cost' ); local fOwner = xmlNodeGetValue ( fHouse, 'owner' ); if ( not isGuestAccount ( getPlayerAccount ( source ) ) ) then if ( fOwner == '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then takePlayerMoney ( source, tonumber ( fPrice ) ); xmlNodeSetValue ( xmlFindChild ( fHouse, 'owner', 0 ), getAccountName ( getPlayerAccount ( source ) ) ); outputChatBox ( 'You have bought this house for: $' .. price, source, 255, 255, 255, false ); for _, cPickup in ipairs ( getElementsByType 'pickup' ) do if ( getElementData ( cPickup, 'housenumber' ) == nHouse ) then -- check element data 'housenumber' setPickupType ( v, 3, 1273 ); end end xmlSaveFile ( fRoot ) elseif ( fOwner ~= '' and getPlayerMoney ( source ) >= tonumber ( fPrice ) ) then Link to comment
sckatchof Posted April 15, 2012 Author Share Posted April 15, 2012 Just tell me what this output. nothing is output Link to comment
drk Posted April 15, 2012 Share Posted April 15, 2012 Wait for another person then, I can't test and fix it now Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now