Script help needed

hey so i am trying to learn .lua and i am very new a couple days old i would say and i have been trying to make a script that you could make someone explode for troll reasons

example /boom (playerid) and then they would go boom

I would need help because i have made a script and it does not work. here is the code i have used

RegisterCommand(‘boom’, function ()
PlayerPedId("") AddEventHandler(AddExplosion)
end) — /boom

i am thinking maybe its because the addexplosion needs to be something else i really dont know someone pls help me and try to explain it

thank you for your time Expan

any help is needed thx

Here you go…

fxmanifest.lua:

fx_version 'cerulean'
game 'gta5'

server_script "server.lua"

server.lua:

RegisterCommand("boom", function(source, args)
	local src = source
	local target = next(args) and tonumber(args[1]) or src
	target = GetPlayerName(target) and target or src
	local coords = GetEntityCoords(GetPlayerPed(target))
	AddExplosion(coords.x, coords.y, coords.z, 9, 1.0, 1, 0, 1065353216, 0)
end) -- /boom

I am not sure where you got that code from and how you thought that would work… Take a look at some basic scripts and see how things actually work. Throwing function names into an event won’t do anything. You need to get values with functions, pass those values as variables to other functions, etc. Take note of the difference between your attempt (which will do nothing) and mine.

Here you can learn Lua → Learn Lua in 15 Minutes
Here you can learn how scripts in FiveM work → Guides for scripting - Cfx.re Docs
Here you can lookup native functions and how to use them → Native Reference - Cfx.re Docs

Good luck! :spades:

1 Like

question here when you did the xyz code why did you put
9, 1.0, 1, 0, 1065353216, 0

Because AddExplosion is a native function that receives a number of parameters.

AddExplosion(
	x --[[ number ]], 
	y --[[ number ]], 
	z --[[ number ]], 
	explosionType --[[ integer ]], 
	damageScale --[[ number ]], 
	isAudible --[[ boolean ]], 
	isInvisible --[[ boolean ]], 
	cameraShake --[[ number ]]
)

More info here → AddExplosion - Natives @ Cfx.re Docs

And you can look up other scripts that use this function by Googling it. So you can see commonly used flags and configurations.