This is a mobile optimized page that loads fast, if you want to load the real page, click this text.

Вопрос Определяем материал поверхности под машиной

DDStudio

Участник портала
17 Авг 2024
20
5
15
Пиши просто:
JavaScript:
materials[entityMaterial]
Не нужно лишних превращений в строку.
JavaScript:
let pos = localPlayer.vehicle.position;
let entityMaterial = mp.raycasting.testCapsule(pos, new mp.Vector3(pos.x, pos.y, pos.z - 5), 0.5, null, 1);
if (entityMaterial) LastMaterialID = materials[entityMaterial['material']];
mp.events.callRemote('console', entityMaterial['material']);
mp.events.callRemote('console', LastMaterialID);

в консоль вывелось:

Код:
4044798976
null

например, тот же самый асфальт выводится:

Код:
282940568
Tarmac

а добавленное мной значение - нет. ID материала всегда возвращается один и тот же на этом объекте, но при поиске в объекте - null
 

kirillzver

Гуру
2 Ноя 2020
167
122
104
Пришли полностью объект из которого достаешь данные (materials)
 

DDStudio

Участник портала
17 Авг 2024
20
5
15
Пришли полностью объект из которого достаешь данные (materials)

JavaScript:
let materials = {
    "5236042":"Blood",
    "13626292":"Temp30",
    "15972667":"MetalHollowSmall",
    "32752644":"Spine3",
    "47470226":"Temp11",
    "63305994":"Temp10",
    "113101985":"HandLeft",
    "122789469":"Cloth",
    "125958708":"MetalChainlinkLarge",
    "126470059":"WoodSolidPolished",
    "127813971":"RockNoinst",
    "158576196":"CarpetSolidDusty",
    "223086562":"Marsh",
    "236511221":"CardboardSheet",
    "244521486":"GlassBulletproof",
    "282940568":"Tarmac",
    "286224918":"AnimalDefault",
    "289630530":"Linoleum",
    "312396330":"MudPothole",
    "332778253":"VfxMetalFlame",
    "359120722":"ConcretePothole",
    "435688960":"Water",
    "465002639":"Temp23",
    "474149820":"Paper",
    "483400232":"Buttocks",
    "509508168":"SandDryDeep",
    "510490462":"SandCompact",
    "513061559":"CarGlassOpaque",
    "555004797":"WoodSolidMedium",
    "560985072":"ClaySoft",
    "576169331":"Cobblestone",
    "581794674":"Bushes",
    "592446772":"SandstoneSolid",
    "602884284":"CarGlassMedium",
    "605776921":"PhysPooltableSurface",
    "611561919":"VfxMetalWaterTower",
    "627123000":"PlasticHollow",
    "652772852":"ShinLeft",
    "669292054":"CarpetSolid",
    "673696729":"SlattedBlinds",
    "702596674":"Temp12",
    "722686013":"WoodOldCreaky",
    "746881105":"Temp01",
    "752131025":"MetalSolidLarge",
    "762193613":"MetalChainlinkSmall",
    "765206029":"Stone",
    "772722531":"PlasticHollowClear",
    "808719444":"Foam",
    "815762359":"WoodSolidLarge",
    "834144982":"MetalCorrugatedIron",
    "868733839":"FreshMeat",
    "889255498":"Temp27",
    "909950165":"SandWet",
    "937503243":"GlassShootThrough",
    "951832588":"GravelSmall",
    "972939963":"PhysPooltableCushion",
    "998201806":"VfxWoodBeerBarrel",
    "999829011":"Puddle",
    "1011960114":"Temp17",
    "1026054937":"Temp09",
    "1045062756":"LowerArmLeft",
    "1059629996":"EmissivePlastic",
    "1061250033":"Temp06",
    "1070994698":"CarGlassStrong",
    "1078418101":"Temp29",
    "1109728704":"MudDeep",
    "1144315879":"ClayHard",
    "1176309403":"WoodChipboard",
    "1187676648":"Concrete",
    "1247281098":"CarGlassWeak",
    "1288448767":"SandWetDeep",
    "1333033863":"Grass",
    "1341866303":"FeatherPillow",
    "1343679702":"Temp08",
    "1345867677":"PhysCarVoid",
    "1354180827":"Fibreglass",
    "1354993138":"Temp18",
    "1429989756":"Tvscreen",
    "1441114862":"BushesNoinst",
    "1457572381":"Spine2",
    "1500272081":"GlassOpaque",
    "1501078253":"EmissiveGlass",
    "1501153539":"UpperArmRight",
    "1550304810":"SnowTarmac",
    "1584636462":"MarshDeep",
    "1619704960":"SnowDeep",
    "1635937914":"MudSoft",
    "1639053622":"Brick",
    "1666473731":"PhysNoFriction",
    "1718294164":"Neck",
    "1755188853":"RoofTile",
    "1761524221":"MetalDuct",
    "1777921590":"LowerArmRight",
    "1845676458":"Laminate",
    "1849540536":"MetalHollowMedium",
    "1886546517":"TarmacPothole",
    "1907048430":"PavingSlab",
    "1911121241":"Temp03",
    "1913209870":"SandstoneBrittle",
    "1923995104":"Temp04",
    "1925605558":"GravelTrainTrack",
    "1926285543":"FootLeft",
    "1945073303":"Marble",
    "1952288305":"Temp25",
    "1963820161":"Temp24",
    "1993976879":"WoodHollowSmall",
    "2000961972":"HandRight",
    "2011204130":"WoodLattice",
    "2015599386":"ConcretePavement",
    "2016463089":"PhysCasterRusty",
    "2100727187":"MetalRailing",
    "2128369009":"GravelLarge",
    "2130571536":"CarSofttopClear",
    "2137197282":"CarPlastic",
    "2409420288":"RoadSide",
    "4044798976":"RoadGrid",
    "-1775485061":"Default",
    "-1084640111":"ConcreteDusty",
    "-1301352528":"TarmacPainted",
    "-250168275":"RumbleStrip",
    "-954112554":"BreezeBlock",
    "-840216541":"Rock",
    "-124769592":"RockMossy",
    "-1595148316":"SandLoose",
    "-1907520769":"SandTrack",
    "-1136057692":"SandUnderwater",
    "-786060715":"Ice",
    "-1931024423":"IceTarmac",
    "-1937569590":"SnowLoose",
    "-878560889":"SnowCompact",
    "-356706482":"GravelDeep",
    "-1885547121":"DirtTrack",
    "-1942898710":"MudHard",
    "-273490167":"MudUnderwater",
    "-700658213":"Soil",
    "-461750719":"GrassLong",
    "-1286696947":"GrassShort",
    "-1833527165":"Hay",
    "-913351839":"Twigs",
    "-2041329971":"Leaves",
    "-309121453":"Woodchips",
    "-1915425863":"TreeBark",
    "-1447280105":"MetalSolidSmall",
    "-365631240":"MetalSolidMedium",
    "-583213831":"MetalHollowLarge",
    "-426118011":"MetalGrille",
    "-231260695":"MetalGarageDoor",
    "-754997699":"MetalManhole",
    "-399872228":"WoodSolidSmall",
    "-749452322":"WoodFloorDusty",
    "-365476163":"WoodHollowMedium",
    "-925419289":"WoodHollowLarge",
    "-1742843392":"WoodHighDensity",
    "-1186320715":"Ceramic",
    "-1417164731":"RoofFelt",
    "-642658848":"Tarpaulin",
    "-2073312001":"Plastic",
    "-1625995479":"PlasticHighDensity",
    "-1859721013":"PlasticClear",
    "-1338473170":"PlasticHighDensityClear",
    "-766055098":"FibreglassHollow",
    "-145735917":"Rubber",
    "-783934672":"RubberHollow",
    "-1396484943":"CarpetFloorboard",
    "-574122433":"PlasterSolid",
    "-251888898":"PlasterBrittle",
    "-1409054440":"CardboardBox",
    "-1756927331":"Polystyrene",
    "-570470900":"Leather",
    "-1619794068":"Perspex",
    "-93061983":"CarMetal",
    "-979647862":"CarSofttop",
    "-1721915930":"CarGlassBulletproof",
    "-634481305":"Oil",
    "-1634184340":"Petrol",
    "-1445160429":"DriedMeat",
    "-309134265":"VfxMetalElectrified",
    "-691277294":"VfxMetalSteam",
    "-1693813558":"PhysGolfBall",
    "-256704763":"PhysTennisBall",
    "-235302683":"PhysCaster",
    "-291631035":"PhysPedCapsule",
    "-1170043733":"PhysElectricFence",
    "-2013761145":"PhysElectricMetal",
    "-1543323456":"PhysBarbedWire",
    "-748341562":"PhysPooltableBall",
    "-460535871":"ThighLeft",
    "-236981255":"ThighRight",
    "-446036155":"ShinRight",
    "-1369136684":"FootRight",
    "-1922286884":"Spine0",
    "-1140112869":"Spine1",
    "-1469616465":"ClavicleLeft",
    "-510342358":"UpperArmLeft",
    "-1557288998":"ClavicleRight",
    "-735392753":"Head",
    "-1916939624":"CarEngine",
    "-1147361576":"BrickPavement",
    "-2047468855":"PhysDynamicCoverBound",
    "-2140087047":"WoodHighFriction",
    "-729112334":"MetalSolidRoadSurface",
    "-2088174996":"StuntRampSurface",
    "-1977970111":"Temp02",
    "-1393662448":"Temp05",
    "-1765523682":"Temp07",
    "-1637485913":"Temp13",
    "-645955574":"Temp14",
    "-1583997931":"Temp15",
    "-1512735273":"Temp16",
    "-801804446":"Temp19",
    "-2052880405":"Temp20",
    "-1037756060":"Temp21",
    "-620388353":"Temp22",
    "-1116253098":"Temp26",
    "-1179674098":"Temp28"
}

сам код
JavaScript:
let materialID = null;
let LastMaterialID = null;
mp.events.add('render', () => {
    if(localPlayer.vehicle && localPlayer.vehicle.getPedInSeat(-1) == localPlayer.handle) {

        let pos = localPlayer.vehicle.position;
        let entityMaterial = mp.raycasting.testCapsule(pos, new mp.Vector3(pos.x, pos.y, pos.z - 5), 0.5, null, 1);
        if (entityMaterial) LastMaterialID = materials[entityMaterial['material']];
        if (materialID != LastMaterialID) {
            mp.events.callRemote('console', entityMaterial['material']);
            mp.events.callRemote('console', LastMaterialID);
            
            mp.events.callRemote('console', '------------');
            materialID = LastMaterialID;
        }

    }
});