forked from Simnation/Main
neues consum script
This commit is contained in:
parent
e491cb80bb
commit
f28aeabf6b
163 changed files with 2364 additions and 10287 deletions
173
resources/[tools]/bzzz_spawnped/client/main.lua
Normal file
173
resources/[tools]/bzzz_spawnped/client/main.lua
Normal file
|
@ -0,0 +1,173 @@
|
|||
local spawnedAnimals = {}
|
||||
local spawnedPersons = {}
|
||||
local spawnedProps = {}
|
||||
local isPedsSpawned = false
|
||||
local count = 0
|
||||
|
||||
---Detete all things (Persons, Animals, Object). On resource stop.
|
||||
---@param resourceName string
|
||||
---@return string? count
|
||||
local function deleteAll(resourceName)
|
||||
if GetCurrentResourceName() ~= resourceName then
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in pairs(spawnedPersons) do
|
||||
DeletePed(v)
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
for k, v in pairs(spawnedAnimals) do
|
||||
DeletePed(v)
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
for k, v in pairs(spawnedProps) do
|
||||
DeleteObject(v)
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
return print(('[Resource Stopped] Delete %s Persons, Animals, Props'):format(count))
|
||||
end
|
||||
|
||||
---Load a model. Check if model is valid. If it is already loaded, it immediately returns the hash value.
|
||||
---@param hash number
|
||||
---@return number? hash
|
||||
local function requestModel(hash)
|
||||
if not tonumber(hash) then
|
||||
return print(('[RequestModel Function] That value: %s its not number/hash. Use backtics ``'):format(hash))
|
||||
end
|
||||
|
||||
if not IsModelValid(hash) then
|
||||
return print(('[RequestModel Function] Attempted to load invalid model %s'):format(hash))
|
||||
end
|
||||
|
||||
if HasModelLoaded(hash) then
|
||||
return hash
|
||||
end
|
||||
|
||||
RequestModel(hash)
|
||||
while not HasModelLoaded(hash) do
|
||||
Wait(50)
|
||||
end
|
||||
|
||||
return hash
|
||||
end
|
||||
|
||||
---Load a dict. Check if animDict is valid. If it is already loaded, it immediately returns the animDict value.
|
||||
---@param animDict string
|
||||
---@return string? animDict
|
||||
local function requestAnimDict(animDict)
|
||||
if type(animDict) ~= 'string' then
|
||||
return print(('[RequestAnimDict Function] Expected animDict to have type string (received %s)'):format(type(animDict)))
|
||||
end
|
||||
|
||||
if not DoesAnimDictExist(animDict) then
|
||||
return print(('[RequestAnimDict Function] Attempted to load invalid animDict %s'):format(animDict))
|
||||
end
|
||||
|
||||
if HasAnimDictLoaded(animDict) then
|
||||
return animDict
|
||||
end
|
||||
|
||||
RequestAnimDict(animDict)
|
||||
while not HasAnimDictLoaded(animDict) do
|
||||
Wait(50)
|
||||
end
|
||||
|
||||
return animDict
|
||||
end
|
||||
|
||||
---Spawn Persons, Animal and object. Save that things in 3 tables.
|
||||
local function spawnPeds()
|
||||
if isPedsSpawned then
|
||||
return
|
||||
end
|
||||
|
||||
isPedsSpawned = true
|
||||
|
||||
for i = 1, #Config.Animals, 1 do
|
||||
local Animal = Config.Animals[i]
|
||||
|
||||
requestModel(Animal.animalHash)
|
||||
|
||||
local createdAnimal = CreatePed('ANIMAL', Animal.animalHash, Animal.animalCoords.x, Animal.animalCoords.y, Animal.animalCoords.z, Animal.animalCoords.w, false, false)
|
||||
|
||||
FreezeEntityPosition(createdAnimal, Animal.animalSettings.FreezeAnimal)
|
||||
|
||||
SetEntityInvincible(createdAnimal, Animal.animalSettings.Invincible)
|
||||
SetPedDiesWhenInjured(createdAnimal, not Animal.animalSettings.Invincible)
|
||||
SetPedCanPlayAmbientAnims(createdAnimal, Animal.animalSettings.Invincible)
|
||||
SetPedCanRagdollFromPlayerImpact(createdAnimal, not Animal.animalSettings.Invincible)
|
||||
|
||||
SetBlockingOfNonTemporaryEvents(createdAnimal, Animal.animalSettings.BlockingOfNonTemporaryEvents)
|
||||
|
||||
SetEntityAsMissionEntity(createdAnimal, true, true)
|
||||
SetModelAsNoLongerNeeded(Animal.animalHash)
|
||||
|
||||
if Animal.animalScenario then
|
||||
TaskStartScenarioInPlace(createdAnimal, Animal.animalScenario, -1, true)
|
||||
end
|
||||
|
||||
spawnedAnimals[i] = createdAnimal
|
||||
end
|
||||
|
||||
for i = 1, #Config.Persons, 1 do
|
||||
local Person = Config.Persons[i]
|
||||
|
||||
requestModel(Person.pedHash)
|
||||
|
||||
local createdPed = CreatePed('ANIMAL', Person.pedHash, Person.pedCoords.x, Person.pedCoords.y, Person.pedCoords.z, Person.pedCoords.w, false, false)
|
||||
|
||||
FreezeEntityPosition(createdPed, Person.pedSettings.FreezePerson or false)
|
||||
|
||||
if Person.pedSettings.Invincible then
|
||||
SetEntityInvincible(createdPed, true)
|
||||
SetPedDiesWhenInjured(createdPed, false)
|
||||
SetPedCanPlayAmbientAnims(createdPed, true)
|
||||
SetPedCanRagdollFromPlayerImpact(createdPed, false)
|
||||
end
|
||||
|
||||
SetBlockingOfNonTemporaryEvents(createdPed, Person.pedSettings.BlockingOfNonTemporaryEvents)
|
||||
|
||||
SetEntityAsMissionEntity(createdPed, true, true)
|
||||
SetModelAsNoLongerNeeded(Person.pedHash)
|
||||
|
||||
if Person.pedAnimation.animDict and Person.pedAnimation.animName and Person.pedAnimation.animFlag then
|
||||
requestAnimDict(Person.pedAnimation.animDict)
|
||||
|
||||
TaskPlayAnim(createdPed, Person.pedAnimation.animDict, Person.pedAnimation.animName, 2.0, 2.0, -1, Person.pedAnimation.animFlag, 0, false, false, false)
|
||||
end
|
||||
|
||||
if Person.pedProp.propHash and Person.pedProp.propBone and Person.pedProp.propPlacement then
|
||||
local pedCoords = GetEntityCoords(createdPed)
|
||||
local x, y, z = table.unpack(pedCoords)
|
||||
local xPos, yPos, zPos, xRot, yRot, zRot = table.unpack(Person.pedProp.propPlacement)
|
||||
|
||||
requestModel(Person.pedProp.propHash)
|
||||
|
||||
local createdProp = CreateObject(Person.pedProp.propHash, x, y, z+0.2, true, true, true)
|
||||
|
||||
AttachEntityToEntity(createdProp, createdPed, GetPedBoneIndex(createdPed, Person.pedProp.propBone), xPos, yPos, zPos, xRot, yRot, zRot, true, true, false, true, 1, true)
|
||||
SetModelAsNoLongerNeeded(Person.pedProp.propHash)
|
||||
|
||||
spawnedProps[i] = createdProp
|
||||
end
|
||||
|
||||
spawnedPersons[i] = createdPed
|
||||
end
|
||||
end
|
||||
|
||||
---@param resourceName string
|
||||
---@return function? spawnPeds
|
||||
local function spawnPedsOnStart(resourceName)
|
||||
if GetCurrentResourceName() ~= resourceName then
|
||||
return
|
||||
end
|
||||
|
||||
return spawnPeds()
|
||||
end
|
||||
|
||||
AddEventHandler('playerSpawned', spawnPeds)
|
||||
AddEventHandler('onResourceStart', spawnPedsOnStart)
|
||||
AddEventHandler('onResourceStop', deleteAll)
|
54
resources/[tools]/bzzz_spawnped/config.lua
Normal file
54
resources/[tools]/bzzz_spawnped/config.lua
Normal file
|
@ -0,0 +1,54 @@
|
|||
Config = {
|
||||
Animals = {
|
||||
{
|
||||
animalHash = `a_c_cow`, -- Use ``(backticks) because it's faster than using GetHashKey
|
||||
-- https://docs.fivem.net/docs/game-references/ped-models/#animals
|
||||
animalCoords = vector4(1580.2, 2169.23, 78.22, 40.94 ), -- x, y, z, heading
|
||||
animalScenario = 'WORLD_COW_GRAZING', -- https://github.com/DioneB/gtav-scenarios
|
||||
animalSettings = {
|
||||
FreezeAnimal = true, -- Using only FreezeEntityPosition
|
||||
Invincible = true, -- Using SetEntityInvincible, SetPedDiesWhenInjured, SetPedCanPlayAmbientAnims, SetPedCanRagdollFromPlayerImpact
|
||||
BlockingOfNonTemporaryEvents = true, -- Using SetBlockingOfNonTemporaryEvents
|
||||
},
|
||||
},
|
||||
{
|
||||
animalHash = `a_c_hen`,
|
||||
animalCoords = vector4(1582.36, 2167.7, 78.3, 8.31),
|
||||
animalScenario = 'WORLD_HEN_PECKING',
|
||||
animalSettings = {
|
||||
FreezeAnimal = true,
|
||||
Invincible = true,
|
||||
BlockingOfNonTemporaryEvents = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Persons = {
|
||||
{
|
||||
pedHash = `a_m_m_farmer_01`, -- Use ``(backticks) because it's faster than using GetHashKey
|
||||
pedCoords = vector4(1584.36, 2169.41, 78.29, 184.73), -- x, y, z, heading
|
||||
pedAnimation = {
|
||||
animDict = 'random@burial',
|
||||
animName = 'a_burial',
|
||||
animFlag = 1,
|
||||
},
|
||||
pedProp = {
|
||||
propHash = `prop_tool_shovel`,
|
||||
propBone = 28422, -- boneIndex (https://wiki.rage.mp/index.php?title=Bones)
|
||||
propPlacement = {
|
||||
0.0, -- xPos
|
||||
0.0, -- yPos
|
||||
0.24, -- zPos
|
||||
0.0, -- xRot
|
||||
0.0, -- yRot
|
||||
0.0, -- zRot
|
||||
},
|
||||
},
|
||||
pedSettings = {
|
||||
FreezePerson = true, -- Using only FreezeEntityPosition
|
||||
Invincible = true, -- Using SetEntityInvincible, SetPedDiesWhenInjured, SetPedCanPlayAmbientAnims, SetPedCanRagdollFromPlayerImpact
|
||||
BlockingOfNonTemporaryEvents = true, -- Using SetBlockingOfNonTemporaryEvents
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
16
resources/[tools]/bzzz_spawnped/fxmanifest.lua
Normal file
16
resources/[tools]/bzzz_spawnped/fxmanifest.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
--[[ FX Information ]]--
|
||||
fx_version 'cerulean'
|
||||
lua54 'yes'
|
||||
game 'gta5'
|
||||
|
||||
--[[ Resource Information ]]--
|
||||
name 'bzzz_spawnped'
|
||||
version '0.0.1'
|
||||
description 'Simple ped & animal configurator'
|
||||
author 'Fantík & Bzzz'
|
||||
|
||||
--[[ Manifest ]]--
|
||||
client_scripts {
|
||||
'config.lua',
|
||||
'client/main.lua',
|
||||
}
|
BIN
resources/[tools]/bzzz_spawnped/images/1.png
Normal file
BIN
resources/[tools]/bzzz_spawnped/images/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 MiB |
BIN
resources/[tools]/bzzz_spawnped/images/2.png
Normal file
BIN
resources/[tools]/bzzz_spawnped/images/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
Loading…
Add table
Add a link
Reference in a new issue