stefutz101 Posted March 28, 2016 Share Posted March 28, 2016 addCommandHandler("setvehiclefaction", function(player, cmd, name, value) if exports.brpExports:isPlayerLeadAdmin(player) then if value then local vehicle = getPedOccupiedVehicle(player) if vehicle then setElementData(vehicle, "vehicle.faction", tonumber(value)) setElementData(vehicle, "factions.vehicle", tonumber(value)) setElementData(vehicle, "vehicle.owner", 0) setElementData(vehicle, "vehicle.tint", 0) for i,v in ipairs(getElementsByType("veh")) do local xml = xmlLoadFile("vehicles.map") local new = xmlFindChild(xml, "veh", 0) if tonumber(getElementData(v, "id")) == exports.brpExports:getIDVehicle(vehicle) then xmlNodeSetAttribute(new, "tinted", 1) xmlNodeSetAttribute(new, "owner", 0) xmlNodeSetAttribute(new, "factionid", value) xmlSaveFile(xml) xmlUnloadFile(xml) break end end outputChatBox(getPlayerName(player) .. "'s vehicle faction changed to " .. tonumber(value) .. ".", player, 220, 220, 0, false) outputServerLog("[VEHICLE] [CMD/SETVEHICLEFACTION]: " .. getPlayerName(player) .. " set " .. getPlayerName(player) .. "'s vehicle faction to " .. tonumber(value) .. ".") else outputChatBox("Player is not in a vehicle.", player, 255, 0, 0, false) end else outputChatBox("Syntax: /" .. cmd .. " ", player, 220, 220, 0, false) end end end ) xml file "416" id="91363" posx="1080.384765625" posy="574.166015625" posz="19.779340744019" rotx="359.24194335938" roty="358.69812011719" rotz="136.69738769531" interior="0" dimension="0" color1="1" color2="3" health="857" fuel="99" engineState="1" lightsState="0" handbrakeState="0" lockState="0" factionid="0" createdby="st3f101" owner="st3f101" tinted="1"> "416" id="3721" posx="1198.267578125" posy="-1331.52734375" posz="13.3984375" rotx="0" roty="0" rotz="166.51403808594" interior="0" dimension="0" color1="1" color2="3" health="1000" fuel="100" engineState="0" lightsState="0" handbrakeState="1" lockState="0" factionid="0" createdby="st3f101" owner="st3f101" tinted="1"> "416" id="86495" posx="1188.79296875" posy="-1326.890625" posz="13.574413299561" rotx="0" roty="0" rotz="293.36965942383" interior="0" dimension="0" color1="1" color2="3" health="1000" fuel="100" engineState="0" lightsState="0" handbrakeState="1" lockState="0" factionid="0" createdby="st3f101" owner="0" tinted="0"> "416" id="22245" posx="1199.4345703125" posy="-1318.2509765625" posz="13.3984375" rotx="0" roty="0" rotz="341.40811157227" interior="0" dimension="0" color1="1" color2="3" health="1000" fuel="100" engineState="0" lightsState="0" handbrakeState="1" lockState="0" factionid="0" createdby="st3f101" owner="0" tinted="0"> "445" id="6495" posx="1047.7626953125" posy="514.13671875" posz="19.8828125" rotx="0" roty="0" rotz="73.321136474609" interior="0" dimension="0" color1="1" color2="2" health="1000" fuel="100" engineState="0" lightsState="0" handbrakeState="1" lockState="0" factionid="0" createdby="SmK" owner="James_Coner" tinted="1"> No matter in what car i am . It modify only first child . Where what's the problem ? Link to comment
Simple0x47 Posted March 28, 2016 Share Posted March 28, 2016 The problem is that you don't specify anywhere which vehicle is going to be modified, making the script modify only the first entry. You could make use of the vehicle id to specify which entry you want to modify. Link to comment
stefutz101 Posted March 28, 2016 Author Share Posted March 28, 2016 i want to edit vehicle what is occuped by source. How can i do that ? I dont know how to do that , can you give me an example ? for i,v in ipairs(getElementsByType("veh")) do local new = xmlFindChild(xml, "veh", i-1) if getElementData(vehicle, "vehicle.id") or 0 == xmlNodeGetAttribute(new, "id") then outputChatBox(i,player) local vpx, vpy, vpz = getElementPosition(vehicle) local vrx, vry, vrz = getElementRotation(vehicle) xmlNodeSetAttribute(new, "posx", vpx) xmlNodeSetAttribute(new, "posy", vpy) xmlNodeSetAttribute(new, "posz", vpz) xmlNodeSetAttribute(new, "rotx", vrx) xmlNodeSetAttribute(new, "roty", vry) xmlNodeSetAttribute(new, "rotz", vrz) xmlSaveFile(xml) xmlUnloadFile(xml) outputChatBox("Vehicle respawn position saved.", player, 220, 220, 0, false) outputServerLog("[VEHICLE] [CMD/PARK] " .. getPlayerName(player) .. " parked vehicle ID " .. getElementData(vehicle, "vehicle.id") .. " to " .. math.floor(vpx * 100) / 100 .. ", " .. math.floor(vpy * 100) / 100 .. ", " .. math.floor(vpz * 100) / 100 .. ".") setVehicleRespawnPosition(vehicle, vpx, vpy, vpz, vrx, vry, vrz) break end end This ? I want to find in that file in wich child i is car id in what i am and change position ... help , please ? 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