Last active
October 6, 2021 07:14
-
-
Save yannbcf/ca68458b808c55adb499de0ff6c64774 to your computer and use it in GitHub Desktop.
create ped
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function requestModel(modelHash, tries = 0) { | |
return new Promise((resolve) => { | |
if (!native.isModelValid(modelHash)) return resolve(false); | |
if (native.hasModelLoaded(modelHash)) return resolve(true); | |
if (tries == 0) native.requestModel(modelHash); | |
if (tries == 40) return resolve(false); | |
setTimeout(() => { | |
if (!native.hasModelLoaded(modelHash)) { | |
return resolve(requestModel(modelHash, ++tries)); | |
} | |
resolve(true); | |
}, 25); | |
}); | |
} | |
async function createPed(hash, posX, posY, posZ, rot) { | |
const isRequested = await requestModel(hash); | |
if (!isRequested) return -1; | |
const ped = native.createPed(2, (alt.hash(hash)), posX, posY, posZ, rot, false, false); | |
native.setEntityAsMissionEntity(ped, true, false); // make sure its not despawned by game engine | |
native.setBlockingOfNonTemporaryEvents(ped, true); // make sure ped doesnt flee etc only do what its told | |
native.setPedCanBeTargetted(ped, false); | |
native.setPedCanBeKnockedOffVehicle(ped, 1); | |
native.setPedCanBeDraggedOut(ped, false); | |
native.setPedSuffersCriticalHits(ped, false); | |
native.setPedDropsWeaponsWhenDead(ped, false); | |
native.setPedDiesInstantlyInWater(ped, false); | |
native.setPedCanRagdoll(ped, false); | |
native.setPedDiesWhenInjured(ped, false); | |
native.taskSetBlockingOfNonTemporaryEvents(ped, true); | |
native.setPedFleeAttributes(ped, 0, false); | |
native.setPedConfigFlag(ped, 32, false); // ped cannot fly thru windscreen | |
native.setPedConfigFlag(ped, 281, true); // ped no writhe | |
native.setPedGetOutUpsideDownVehicle(ped, false); | |
native.setPedCanEvasiveDive(ped, false); | |
native.setEntityInvincible(ped, true); | |
native.freezeEntityPosition(ped, true); | |
return ped; | |
} | |
(async() => { | |
const shop = await createPed("mp_m_shopkeep_01", 24.36923, -1347.4154, 29.482056, -1.3852693); | |
if (shop === -1) return; | |
alt.setInterval(() => { | |
if (native.isPlayerFreeAimingAtEntity(player.scriptID, shop)) { | |
alt.log("Working!"); | |
} | |
}, 2500); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment