Jump to content

Need help


sckatchof

Recommended Posts

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

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
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
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 by Guest
Link to comment

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...