Registering Command & Spawn Ped

Hi there a quick run down, I am messing around with some scripts for my local server, (So it wont matter if I mess up!). Any ways I wanted to spawn a shop worker within the shop when doing a command, I wont go in to why at this point. Any ways I have this code here…

RegisterCommand(‘ped’, function()

local result = local RequestMenuPedModel(mp_m_shopkeep_01) = ESX.Game.RequestModel(mp_m_shopkeep_01)

print(json.encode())

end)

I am wondering if this will work? Or what even that will do? Could you advise me please?

Thank you. (Yes im a dummy in making scripts so be nice!)

“Thank you. (Yes im a dummy in making scripts so be nice!)” all good, thats what learning and questioning is for :slight_smile:

No, this code wont spawn the Shop-Keeper.

This is how you can do it:

RegisterCommand(‘ped’, function()
local ped = RequestModel(GetHashKey("PED"))
	
    while not HasModelLoaded(GetHashKey("PED")) do
        Wait(1)
    end
	

			local npc = CreatePed(4, ped, X,Y,Z, HEADING, false, true)
			
			SetEntityHeading(npc,HEADING)
			FreezeEntityPosition(npc, true)
			SetEntityInvincible(npc, true)
			SetBlockingOfNonTemporaryEvents(npc, true)
		
Wait(1000)
SetModelAsNoLongerNeeded(GetHashKey("PED"))
	end)

Ah is that using the command? I was using visual studio codes snippets.

Thank u.

Thank you! PS does this have to be server side I take it? Thank you again! I also wanted it for esx shopkeeper job that I am trying to do. Hard for first timer. :slight_smile: Any advice will be appricated oh and credited!

This is client sided. (you can see it because of the RequestModel and SetModelAsNoLongerNeeded, these Natives Request the Model so the client can see it, otherwise it would not be there)

1 Like

There is one thing I get confused about is (souce) and ary or what ever they are called. Can someone explain what it is? Do you put your event in there or something? Thank you.

source is normally the players handle in an serversided event which was called by an client.

1 Like

Thank you for your help much appricated.

1 Like

Hi sorry to bother ya but need some advice again. I am trying to get ai to respond when they are shooting but I dont want it gta v style. (As I disabled that)

AddEventHandler(“shotsfired”), function()

TriggerServerEvent(“shotsfired”,)

SetDispatchCopsForPlayer(GetAiBlip, GetActivePlayers toggle)

SetDispatchSpawnLocation(x, y, z)

SetPlayerWantedLevelNoDrop

end)

Then I want to send a notification saying “Cops are being sent to your location!” (PS this is for fun only learning coding.)

function GetActivePlayers(name, message)

is IsPedShooting = (true) SetDispatchCopsForPlayer(player, if element == true then

 add SendDuiMessage = (meessage "~g~Cops are being sent!")

end)

Will this work so far? As I have no idea if it will. But obviously I dont want cops if they dont shoot…

Thanks Legend.

no problem, i like to help you :slight_smile:
Could you please send the entire code again using the code tool? (in between this letters: ` )

or just click here:
image
then put your code in between the generated lines

function GetActivePlayers(name, message)
  is IsPedShooting = (true) SetDispatchCopsForPlayer(player, if element == true then
     add SendDuiMessage = (meessage "~g~Cops are being sent!")
  end)
AddEventHandler("shotsfired"), function()
  TriggerServerEvent("shotsfired",)
  SetDispatchCopsForPlayer(GetAiBlip, GetActivePlayers toggle)
  SetDispatchSpawnLocation(x, y, z)
  SetPlayerWantedLevelNoDrop
end)
SetPlayerWantedLevel(
	2, 
	wantedLevel = wantedLeveld player = GetPlayerByEntityID
)

(PS: I did try and send message to discord that a player is shooting but failed! Lol Learn and try cant feck up lol)

I think u get the giff of what im trying to achive! Thank you, you can add me here and I send my discord if u want? Thanks again dude. (Sorry if female)

Thanks Legend.