MTA Team 0xCiBeR Posted February 21, 2013 MTA Team Share Posted February 21, 2013 Bueno pues he sacado este script de un resource de la comunidad llamado : Buycarsmod El problema con este script es lo siguiente: 1-Quiero que en vez de guardar el nick del jugador, se guarde la cuenta 2-Eliminar lo de /lockcar y /unlockcar aca el cars_main: cars={} buycarpickup={} maxcars = 0 addEventHandler ( "onResourceStart", getResourceRootElement(), function () local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) if (houseroot) then for i,v in ipairs (xmlNodeGetChildren(houseroot)) do local carmodel = xmlNodeGetAttribute (v,"model") local x = xmlNodeGetAttribute (v,"x") local y = xmlNodeGetAttribute (v,"y") local z = xmlNodeGetAttribute (v,"z") local color1 = xmlNodeGetAttribute (v,"color1") local color2 = xmlNodeGetAttribute (v,"color2") local owner = xmlNodeGetAttribute (v,"owner") local price = xmlNodeGetAttribute (v,"price") local lock = xmlNodeGetAttribute (v,"lock") local a = xmlNodeGetAttribute (v,"a") cars[i] = createVehicle ( tonumber(carmodel),tonumber(x),tonumber(y),tonumber(z), 0, 0, tonumber(a) ) setElementInterior ( cars[i], 0 ) setElementData (cars[i],"xpos",tonumber(x)) setElementData (cars[i],"ypos",tonumber(y)) setElementData (cars[i],"zpos",tonumber(z)) setElementData (cars[i],"angle",tonumber(a)) setElementData (cars[i],"owner",owner) setElementData (cars[i],"price",tonumber(price)) setElementData (cars[i],"lock",tonumber(lock)) setElementData (cars[i], "num", i ) setVehicleColor ( cars[i], tonumber(color1), tonumber(color2), 0, 0 ) if(lock == 1) then setVehicleLocked ( car, true ) end if getElementData ( cars[i], "owner" ) == "Nobody" then buycarpickup[i] = createPickup ( x, y, z, 3, 1274 ) attachElements ( buycarpickup[i], cars[i], 0, 0, 1.9 ) end maxcars = maxcars+1 end outputDebugString ("Cars loaded!") end end ) function saveCars () local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) if (houseroot) then for i,v in ipairs (xmlNodeGetChildren(houseroot)) do local color1, color2, color3, color4 = getVehicleColor ( cars[i] ) xmlNodeSetAttribute ( v, "model", getElementModel(cars[i]) ) xmlNodeSetAttribute ( v, "x", getElementData(cars[i], "xpos") ) xmlNodeSetAttribute ( v, "y", getElementData(cars[i], "ypos") ) xmlNodeSetAttribute ( v, "z", getElementData(cars[i], "zpos") ) xmlNodeSetAttribute ( v, "a", getElementData(cars[i], "angle") ) xmlNodeSetAttribute ( v, "color1", color1 ) xmlNodeSetAttribute ( v, "color2", color2 ) xmlNodeSetAttribute ( v, "owner", getElementData(cars[i], "owner") ) xmlNodeSetAttribute ( v, "price", getElementData(cars[i], "price") ) xmlNodeSetAttribute ( v, "lock", getElementData(cars[i], "lock") ) end xmlSaveFile(root) end end function adminCreateVehicle ( source, cmd ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) local createdcar = xmlCreateChild ( houseroot, "vehicle" ) local carmodel = xmlNodeSetAttribute ( createdcar, "model", "451" ) local x, y, z = getElementPosition ( source ) local xa,ya,a = getElementRotation ( source ) xmlNodeSetAttribute ( createdcar, "x", x ) xmlNodeSetAttribute ( createdcar, "y", y ) xmlNodeSetAttribute ( createdcar, "z", z ) xmlNodeSetAttribute ( createdcar, "a", a ) xmlNodeSetAttribute ( createdcar, "color1", "0" ) xmlNodeSetAttribute ( createdcar, "color2", "0" ) xmlNodeSetAttribute ( createdcar, "owner", "Nobody" ) xmlNodeSetAttribute ( createdcar, "price", "0" ) xmlNodeSetAttribute ( createdcar, "lock", "0" ) cars[maxcars+1] = createVehicle ( 451,x,y,z,0,0,a ) setElementData (cars[maxcars+1],"xpos",x) setElementData (cars[maxcars+1],"ypos",y) setElementData (cars[maxcars+1],"zpos",z) setElementData (cars[maxcars+1],"angle", a) setElementData (cars[maxcars+1],"owner","Nobody") setElementData (cars[maxcars+1],"price",0) setElementData (cars[maxcars+1],"lock",0) xmlSaveFile(root) maxcars = maxcars+1 else outputChatBox ("Error: You can't use this command",source, 255,255,127 ) end end addCommandHandler ("acarcreate", adminCreateVehicle) addCommandHandler ("acarsave", saveCars) function getCar ( car ) return cars[car] end function enterVehicle ( source, seat, jacked ) local playercar = getPedOccupiedVehicle ( source ) if(seat == 0) then if getElementData(source, "owner") and getElementData(source, "owner" ) ~= getAccountName(getPlayerAccount(player)) then outputChatBox ("Este es tu carro Privado!" ) else outputChatBox ("El dueño del auto es: "..getElementData ( playercar, "owner" ).."",source, 255,255,127 ) end else local price = getElementData ( playercar, "price" ) triggerClientEvent ( source, "showBuyCar", source, price) toggleAllControls ( source, false, true, false ) return true end end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) function AcceptToBuyCar ( ) local playercar = getPedOccupiedVehicle ( source ) if(getElementData ( playercar, "owner" ) == "Nobody") then if(getPlayerMoney ( source ) > tonumber(getElementData ( playercar, "price"))) then setElementData ( playercar, "owner", getPlayerName ( source )) takePlayerMoney ( source, tonumber(getElementData ( playercar, "price" ))) toggleAllControls ( source, true ) outputChatBox ("You buy this car!", source, 243,149,72 ) destroyElement(buycarpickup[getElementData(playercar,"num")]) saveCars () else outputChatBox ("Error: You don't have enought money", source, 243,149,72 ) setControlState ( source, "enter_exit", true ) end end end addEvent("acceptBuyCar",true) addEventHandler("acceptBuyCar",root,AcceptToBuyCar) function playerCarLock ( source, cmd) for i,v in ipairs (cars) do if(getElementData ( cars[i], "owner" ) == getPlayerName ( source )) then setVehicleLocked ( cars[i], true ) setElementData (cars[i],"lock", 1) outputChatBox ("You closed your car",source, 243,149,72 ) saveCars() end end end addCommandHandler ("lockmycar",playerCarLock) function playerCarUnLock ( source, cmd) for i,v in ipairs (cars) do if(getElementData ( cars[i], "owner" ) == getPlayerName ( source )) then setVehicleLocked ( cars[i], false ) setElementData (cars[i],"lock", 0) outputChatBox ("You opened your car",source, 243,149,72 ) saveCars() end end end addCommandHandler ("unlockmycar",playerCarUnLock) y el client side comands: function adminSetCarModel ( source, cmd, model ) if(model) then if((tonumber(model) > 399) and (tonumber(model) < 612))then local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then if(isPedInVehicle(source)) then local playercar = getPedOccupiedVehicle ( source ) setElementModel (playercar,tonumber(model)) saveCars() else outputChatBox ("Error: You isn't in car",source, 255,255,127 ) end else outputChatBox ("Error: You can't use this command",source, 255,255,127 ) end else outputChatBox ("Error: Model ID must be between 400 and 611",source, 255,255,127 ) end else outputChatBox ("Правильно: /acarmodel vehicle model",source, 255,255,127 ) end end addCommandHandler ("acarmodel", adminSetCarModel) function adminSetCarColor ( source, cmd, color1, color2 ) if(color2) then local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then if(isPedInVehicle(source)) then local playercar = getPedOccupiedVehicle ( source ) setVehicleColor (playercar,color1,color2,0,0) saveCars() else outputChatBox ("Error: You isn't in car",source, 255,255,127 ) end else outputChatBox ("Error: You can't use this command",source, 255,255,127 ) end else outputChatBox ("Correct: /acarcolor [color 1] color 2",source, 255,255,127 ) end end addCommandHandler ("acarcolor", adminSetCarColor) function adminSetCarPrice ( source, cmd, carprice ) if(carprice) then local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then if(isPedInVehicle(source)) then local playercar = getPedOccupiedVehicle ( source ) setElementData(playercar, "price", tonumber(carprice)) outputChatBox ("You set car "..tostring(playercar).." price $"..tostring(carprice).."",source, 243,149,72 ) saveCars() else outputChatBox ("Error: You isn't in car",source, 255,255,127 ) end else outputChatBox ("Error: You can't use this command",source, 255,255,127 ) end else outputChatBox ("Correct: /acarprice car price",source, 255,255,127 ) end end addCommandHandler ("acarprice", adminSetCarPrice) function adminSetCarPark ( source, cmd) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then if(isPedInVehicle(source)) then local playercar = getPedOccupiedVehicle ( source ) local x, y, z = getElementPosition ( source ) local xa,ya,a = getElementRotation ( source ) setElementData (playercar,"xpos",x) setElementData (playercar,"ypos",y) setElementData (playercar,"zpos",z) setElementData (playercar,"angle",a) outputChatBox ("You set car "..tostring(playercar).." spawn point",source, 243,149,72 ) saveCars() else outputChatBox ("Error: You isn't in car",source, 255,255,127 ) end else outputChatBox ("Error: You can't use this command",source, 255,255,127 ) end end addCommandHandler ("acarpark", adminSetCarPark) function playerCarPark ( source, cmd) if(isPedInVehicle(source)) then local playercar = getPedOccupiedVehicle ( source ) if(getElementData ( playercar, "owner" ) == getPlayerName ( source )) then local x, y, z = getElementPosition ( source ) local xa,ya,a = getElementRotation ( playercar ) setElementData (playercar,"xpos",x) setElementData (playercar,"ypos",y) setElementData (playercar,"zpos",z) setElementData (playercar,"angle",a) outputChatBox ("You parked your car, don't forget to close it!",source, 243,149,72 ) saveCars() else outputChatBox ("Error: It is not your car!",source, 255,255,127 ) end else outputChatBox ("Error: You isn't in car",source, 255,255,127 ) end end addCommandHandler ("carpark",playerCarPark) function playerCarSell ( source, cmd) if(isPedInVehicle(source)) then local playercar = getPedOccupiedVehicle ( source ) if(getElementData ( playercar, "owner" ) == getPlayerName ( source )) then setElementData (playercar,"owner","Nobody") givePlayerMoney ( source, getElementData ( playercar, "price" )/100*50 ) outputChatBox ("You sold your car!",source, 243,149,72 ) saveCars() else outputChatBox ("Error: It is not your car!",source, 255,255,127 ) end else outputChatBox ("Error: You isn't in car",source, 255,255,127 ) end end addCommandHandler ("carsell",playerCarSell) como seria el script con lo que indique que necesitaba,xq lo he intentado pero falla Gracias Link to comment
Castillo Posted February 21, 2013 Share Posted February 21, 2013 Usa: getPlayerAccount getAccountName Link to comment
MTA Team 0xCiBeR Posted February 21, 2013 Author MTA Team Share Posted February 21, 2013 Y donde saco lo de lock y unlock para que cuando el dueño salga no deje a nadie entrar, sin necesidad del /lockcar y el /unlockcar? Link to comment
MTA Team 0xCiBeR Posted February 21, 2013 Author MTA Team Share Posted February 21, 2013 Snake asi? cars={} buycarpickup={} maxcars = 0 addEventHandler ( "onResourceStart", getResourceRootElement(), function () local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) if (houseroot) then for i,v in ipairs (xmlNodeGetChildren(houseroot)) do local carmodel = xmlNodeGetAttribute (v,"model") local x = xmlNodeGetAttribute (v,"x") local y = xmlNodeGetAttribute (v,"y") local z = xmlNodeGetAttribute (v,"z") local color1 = xmlNodeGetAttribute (v,"color1") local color2 = xmlNodeGetAttribute (v,"color2") local owner = xmlNodeGetAttribute (v,"owner") local price = xmlNodeGetAttribute (v,"price") local lock = xmlNodeGetAttribute (v,"lock") local a = xmlNodeGetAttribute (v,"a") cars[i] = createVehicle ( tonumber(carmodel),tonumber(x),tonumber(y),tonumber(z), 0, 0, tonumber(a) ) setElementInterior ( cars[i], 0 ) setElementData (cars[i],"xpos",tonumber(x)) setElementData (cars[i],"ypos",tonumber(y)) setElementData (cars[i],"zpos",tonumber(z)) setElementData (cars[i],"angle",tonumber(a)) setElementData (cars[i],"owner",owner) setElementData (cars[i],"price",tonumber(price)) setElementData (cars[i],"lock",tonumber(lock)) setElementData (cars[i], "num", i ) setVehicleColor ( cars[i], tonumber(color1), tonumber(color2), 0, 0 ) if(lock == 1) then setVehicleLocked ( car, true ) end if getElementData ( cars[i], "owner" ) == "Nobody" then buycarpickup[i] = createPickup ( x, y, z, 3, 1274 ) attachElements ( buycarpickup[i], cars[i], 0, 0, 1.9 ) end maxcars = maxcars+1 end outputDebugString ("Cars loaded!") end end ) function saveCars () local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) if (houseroot) then for i,v in ipairs (xmlNodeGetChildren(houseroot)) do local color1, color2, color3, color4 = getVehicleColor ( cars[i] ) xmlNodeSetAttribute ( v, "model", getElementModel(cars[i]) ) xmlNodeSetAttribute ( v, "x", getElementData(cars[i], "xpos") ) xmlNodeSetAttribute ( v, "y", getElementData(cars[i], "ypos") ) xmlNodeSetAttribute ( v, "z", getElementData(cars[i], "zpos") ) xmlNodeSetAttribute ( v, "a", getElementData(cars[i], "angle") ) xmlNodeSetAttribute ( v, "color1", color1 ) xmlNodeSetAttribute ( v, "color2", color2 ) xmlNodeSetAttribute ( v, "owner", getElementData(cars[i], "owner") ) xmlNodeSetAttribute ( v, "price", getElementData(cars[i], "price") ) xmlNodeSetAttribute ( v, "lock", getElementData(cars[i], "lock") ) end xmlSaveFile(root) end end function adminCreateVehicle ( source, cmd ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) local createdcar = xmlCreateChild ( houseroot, "vehicle" ) local carmodel = xmlNodeSetAttribute ( createdcar, "model", "451" ) local x, y, z = getElementPosition ( source ) local xa,ya,a = getElementRotation ( source ) xmlNodeSetAttribute ( createdcar, "x", x ) xmlNodeSetAttribute ( createdcar, "y", y ) xmlNodeSetAttribute ( createdcar, "z", z ) xmlNodeSetAttribute ( createdcar, "a", a ) xmlNodeSetAttribute ( createdcar, "color1", "0" ) xmlNodeSetAttribute ( createdcar, "color2", "0" ) xmlNodeSetAttribute ( createdcar, "owner", "Nobody" ) xmlNodeSetAttribute ( createdcar, "price", "0" ) xmlNodeSetAttribute ( createdcar, "lock", "0" ) cars[maxcars+1] = createVehicle ( 451,x,y,z,0,0,a ) setElementData (cars[maxcars+1],"xpos",x) setElementData (cars[maxcars+1],"ypos",y) setElementData (cars[maxcars+1],"zpos",z) setElementData (cars[maxcars+1],"angle", a) setElementData (cars[maxcars+1],"owner","Nobody") setElementData (cars[maxcars+1],"price",0) setElementData (cars[maxcars+1],"lock",0) xmlSaveFile(root) maxcars = maxcars+1 else outputChatBox ("Error: You can't use this command",source, 255,255,127 ) end end addCommandHandler ("acarcreate", adminCreateVehicle) addCommandHandler ("acarsave", saveCars) function getCar ( car ) return cars[car] end function enterVehicle ( source, seat, jacked ) local playercar = getPedOccupiedVehicle ( source ) if(seat == 0) then if getElementData(source, "owner") and getElementData(source, "owner" ) ~= getAccountName(getPlayerAccount(player)) then outputChatBox ("Este es tu carro Privado!" ) else outputChatBox ("El dueño del auto es: "..getElementData ( playercar, "owner" ).."",source, 255,255,127 ) end else local price = getElementData ( playercar, "price" ) triggerClientEvent ( source, "showBuyCar", source, price) toggleAllControls ( source, false, true, false ) return true end end end end addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) function AcceptToBuyCar ( ) local playercar = getPedOccupiedVehicle ( source ) if(getElementData ( playercar, "owner" ) == "Nobody") then if(getPlayerMoney ( source ) > tonumber(getElementData ( playercar, "price"))) then setElementData ( playercar, "owner", getAccountName(getPlayerAccount(player)) takePlayerMoney ( source, tonumber(getElementData ( playercar, "price" ))) toggleAllControls ( source, true ) outputChatBox ("You buy this car!", source, 243,149,72 ) destroyElement(buycarpickup[getElementData(playercar,"num")]) saveCars () else outputChatBox ("Error: You don't have enought money", source, 243,149,72 ) setControlState ( source, "enter_exit", true ) end end end addEvent("acceptBuyCar",true) addEventHandler("acceptBuyCar",root,AcceptToBuyCar) function playerCarLock ( source, cmd) for i,v in ipairs (cars) do if(getElementData ( cars[i], "owner" ) == getAccountName(getPlayerAccount(player)) then setVehicleLocked ( cars[i], true ) setElementData (cars[i],"lock", 1) outputChatBox ("You closed your car",source, 243,149,72 ) saveCars() end end end addCommandHandler ("lockmycar",playerCarLock) function playerCarUnLock ( source, cmd) for i,v in ipairs (cars) do if(getElementData ( cars[i], "owner" ) == getAccountName(getPlayerAccount(player)) then setVehicleLocked ( cars[i], false ) setElementData (cars[i],"lock", 0) outputChatBox ("You opened your car",source, 243,149,72 ) saveCars() end end end addCommandHandler ("unlockmycar",playerCarUnLock) Link to comment
Castillo Posted February 21, 2013 Share Posted February 21, 2013 Lo que podes hacer es al intentar entrar, verificar si el dueño es el que intenta entrar, y si no, cancelas el evento. Evento: onVehicleStartEnter Funciones: getElementData cancelEvent Link to comment
MTA Team 0xCiBeR Posted February 21, 2013 Author MTA Team Share Posted February 21, 2013 ASi?: function enterVehicle ( source, seat, jacked ) local playercar = getPedOccupiedVehicle ( source ) if(seat == 0) then if getElementData(source, "owner") and getElementData(source, "owner" ) ~= getAccountName(getPlayerAccount(player)) then outputChatBox ("El dueño del auto es: "..getElementData ( playercar, "owner" ).."",source, 255,255,127 ) else outputChatBox ("Es tu auto") cancelEvent () end else local price = getElementData ( playercar, "price" ) triggerClientEvent ( source, "showBuyCar", source, price) toggleAllControls ( source, false, true, false ) return true end end end end Link to comment
Castillo Posted February 21, 2013 Share Posted February 21, 2013 No entiendo, le falta el evento, ademas de que tiene cosas de mas, tipo el precio y otras cosas. Link to comment
MTA Team 0xCiBeR Posted February 21, 2013 Author MTA Team Share Posted February 21, 2013 Disculpa, el evento seria onVehicleStartEnter Es una tienda esto... Link to comment
Castillo Posted February 21, 2013 Share Posted February 21, 2013 Pero estamos hablando de un script para que el coche solo lo pueda usar su dueño, no tiene nada que ver con una tienda. Link to comment
MTA Team 0xCiBeR Posted February 21, 2013 Author MTA Team Share Posted February 21, 2013 La idea del script es el siguiente: Un admin crea carros..Estos carros se podran comprar..Una vez que alguien compre el carro, nadie debera poder entrar,El dueño podra estacionarlo donde quiera,El dueño podra venderlo cuando quiera. Entonces, el script de la comunidad guarda todo por nombre del jugador, lo cual no es conveninte ya que si te cambias el nick no sirve, entonces lo he pasado para que funcione con cuentas, pero no anda, ya que cuando compro el auto, salgo y quiero volver a entrar, me vuelve a saltar el gui de compra... aca el script completo: cars={} buycarpickup={} maxcars = 0 addEventHandler ( "onResourceStart", getResourceRootElement(), function () local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) if (houseroot) then for i,v in ipairs (xmlNodeGetChildren(houseroot)) do local carmodel = xmlNodeGetAttribute (v,"model") local x = xmlNodeGetAttribute (v,"x") local y = xmlNodeGetAttribute (v,"y") local z = xmlNodeGetAttribute (v,"z") local color1 = xmlNodeGetAttribute (v,"color1") local color2 = xmlNodeGetAttribute (v,"color2") local owner = xmlNodeGetAttribute (v,"owner") local price = xmlNodeGetAttribute (v,"price") local a = xmlNodeGetAttribute (v,"a") cars[i] = createVehicle ( tonumber(carmodel),tonumber(x),tonumber(y),tonumber(z), 0, 0, tonumber(a) ) setElementInterior ( cars[i], 0 ) setElementData (cars[i],"xpos",tonumber(x)) setElementData (cars[i],"ypos",tonumber(y)) setElementData (cars[i],"zpos",tonumber(z)) setElementData (cars[i],"angle",tonumber(a)) setElementData (cars[i],"owner",owner) setElementData (cars[i],"price",tonumber(price)) setElementData (cars[i], "num", i ) setVehicleColor ( cars[i], tonumber(color1), tonumber(color2), 0, 0 ) if getElementData ( cars[i], "owner" ) == "Nobody" then buycarpickup[i] = createPickup ( x, y, z, 3, 1274 ) attachElements ( buycarpickup[i], cars[i], 0, 0, 1.9 ) end maxcars = maxcars+1 end outputDebugString ("Tienda de Carros By CiBeR! Cargada") end end ) function saveCars () local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) if (houseroot) then for i,v in ipairs (xmlNodeGetChildren(houseroot)) do local color1, color2, color3, color4 = getVehicleColor ( cars[i] ) xmlNodeSetAttribute ( v, "model", getElementModel(cars[i]) ) xmlNodeSetAttribute ( v, "x", getElementData(cars[i], "xpos") ) xmlNodeSetAttribute ( v, "y", getElementData(cars[i], "ypos") ) xmlNodeSetAttribute ( v, "z", getElementData(cars[i], "zpos") ) xmlNodeSetAttribute ( v, "a", getElementData(cars[i], "angle") ) xmlNodeSetAttribute ( v, "color1", color1 ) xmlNodeSetAttribute ( v, "color2", color2 ) xmlNodeSetAttribute ( v, "owner", getElementData(cars[i], "owner") ) xmlNodeSetAttribute ( v, "price", getElementData(cars[i], "price") ) end xmlSaveFile(root) end end function adminCreateVehicle ( source, cmd ) local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "Admin" ) ) then local root = xmlLoadFile ("cars.xml") local houseroot = xmlFindChild (root,"cars",0) local createdcar = xmlCreateChild ( houseroot, "vehicle" ) local carmodel = xmlNodeSetAttribute ( createdcar, "model", "451" ) local x, y, z = getElementPosition ( source ) local xa,ya,a = getElementRotation ( source ) xmlNodeSetAttribute ( createdcar, "x", x ) xmlNodeSetAttribute ( createdcar, "y", y ) xmlNodeSetAttribute ( createdcar, "z", z ) xmlNodeSetAttribute ( createdcar, "a", a ) xmlNodeSetAttribute ( createdcar, "color1", "0" ) xmlNodeSetAttribute ( createdcar, "color2", "0" ) xmlNodeSetAttribute ( createdcar, "owner", "Nobody" ) xmlNodeSetAttribute ( createdcar, "price", "0" ) cars[maxcars+1] = createVehicle ( 451,x,y,z,0,0,a ) setElementData (cars[maxcars+1],"xpos",x) setElementData (cars[maxcars+1],"ypos",y) setElementData (cars[maxcars+1],"zpos",z) setElementData (cars[maxcars+1],"angle", a) setElementData (cars[maxcars+1],"owner","Nobody") setElementData (cars[maxcars+1],"price",0) xmlSaveFile(root) maxcars = maxcars+1 else outputChatBox ("Error: No puedes usar este comando!",source, 255,255,127 ) end end addCommandHandler ("crearcarro", adminCreateVehicle) addCommandHandler ("guardarcarro", saveCars) function getCar ( car ) return cars[car] end function enterVehicle ( source, seat, jacked ) local playercar = getPedOccupiedVehicle ( source ) if(seat == 0) then if getElementData(source, "owner") and getElementData(source, "owner" ) ~= getAccountName(getPlayerAccount(source)) then outputChatBox ("El dueño del auto es: "..getElementData ( playercar, "owner" ).."",source, 255,255,127 ) else local price = getElementData ( playercar, "price" ) triggerClientEvent ( source, "showBuyCar", source, price) toggleAllControls ( source, false, true, false ) return true end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) function AcceptToBuyCar ( ) local playercar = getPedOccupiedVehicle ( source ) if(getElementData ( playercar, "owner" ) == "Nobody") then if(getPlayerMoney ( source ) > tonumber(getElementData ( playercar, "price"))) then setElementData ( playercar, "owner", getAccountName(getPlayerAccount(player))) takePlayerMoney ( source, tonumber(getElementData ( playercar, "price" ))) toggleAllControls ( source, true ) outputChatBox ("Has comprado el auto", source, 243,149,72 ) destroyElement(buycarpickup[getElementData(playercar,"num")]) saveCars () else outputChatBox ("Error: No tienes sufucuente dinero", source, 243,149,72 ) setControlState ( source, "enter_exit", true ) end end end addEvent("acceptBuyCar",true) addEventHandler("acceptBuyCar",root,AcceptToBuyCar) Link to comment
Recommended Posts