Shockwave Fivem

Good morning, be good to me because it’s my first lua script. I’m trying to make a script that when “equipped” (/equipe), by pressing a button, the ped releases a shock wave around itself.

Obviously fivem crashes :crazy_face:

this is the client code, if anyone can give me some advice, thank you very much

useCommand = true 

if useCommand == true then
  RegisterCommand("equipe",function(source, args, rawCommand)
    equipe()
  end)
end




function equipe()
  local ped = PlayerPedId()
  SetPedComponentVariation(ped, 9, 15, 0, 0)
  AddTextEntry("HELP", "Appuie sur ~INPUT_DETONATE~ pour exploser.")
  DisplayHelpTextThisFrame("HELP",false)
  while true do
    Citizen.Wait(1)
      if IsControlPressed(0,58) then
        explosion()
        break
      end
     
      if IsPedDeadOrDying(ped, true) then
        break
      end
    end
  end


function explosion(entity)
    local ped = PlayerPedId()
    local posizione = GetEntityCoords(ped)
    local coordinate = GetEntityCoords(entity)
    local dx = coordinate.x - posizione.x
    local dy = coordinate.y - posizione.y
    local dz = coordinate.z - posizione.z
    local distanza = math.sqrt(dx * dx + dy * dy + dz * dz)
    local distanceRate = (50 / distanza) * math.pow(1.04, 1 - distanza)
    ApplyForceToEntity(entity, 1, distanceRate * dx, distanceRate * dy, distanceRate * dz, math.random() * math.random(-1, 1), math.random() * math.random(-1, 1), math.random() * math.random(-1, 1), true, false, true, true, true, true)
end
  






so it doesn’t crash anymore but I don’t think it runs the wave (it doesn’t work on NPCs)

 function explosion(ply)
    local ped = PlayerPedId()
    local posizione = GetEntityCoords(ped)
    local ply = GetPlayerPed(-1)
    local plyCoords = GetEntityCoords(ply, 0)

    local dx = plyCoords.x - posizione.x
    local dy = plyCoords.y - posizione.y
    local dz = plyCoords.z - posizione.z
    local distanza = math.sqrt(dx * dx + dy * dy + dz * dz)
    local distanceRate = (50 / distanza) * math.pow(1.04, 1 - distanza)
    ApplyForceToEntity(ply, 1, distanceRate * dx, distanceRate * dy, distanceRate * dz, math.random() * math.random(-1, 1), math.random() * math.random(-1, 1), math.random() * math.random(-1, 1), true, false, true, true, true, true)
end```

another failed attempt, crash. But I’m sure the problem is here with the entity. Can someone help me please?

  function explosion(playerCoord, entity)
    local coord= GetEntityCoords(entity,true)
    local ped = PlayerPedId()
    local posizione = GetEntityCoords(ped)
    local ply = GetPlayerPed(-1)
    local plyCoords = GetEntityCoords(ply, 0)

    local dx = coord.x - posizione.x
    local dy = coord.y - posizione.y
    local dz = coord.z - posizione.z
    local distanza = math.sqrt(dx * dx + dy * dy + dz * dz)
    local distanceRate = (50 / distanza) * math.pow(1.04, 1 - distanza)
    ApplyForceToEntity(entity, 1, distanceRate * dx, distanceRate * dy, distanceRate * dz, math.random() * math.random(-1, 1), math.random() * math.random(-1, 1), math.random() * math.random(-1, 1), true, false, true, true, true, true)
end

It’s a bit more complicated than how you are currently trying to do it. After a bit of testing I was able to come up with this slightly modified version of the script you provided. It’s still not perfect but it’s a starting place:

useCommand = true 

if useCommand == true then
  RegisterCommand("equipe",function(source, args, rawCommand)
    equipe()
  end)
end

function equipe()
    local ped = PlayerPedId()

    SetPedComponentVariation(ped, 9, 15, 0, 0)
    AddTextEntry("HELP", "Appuie sur ~INPUT_DETONATE~ pour exploser.")
    

    while true do
        Citizen.Wait(1)

        DisplayHelpTextThisFrame("HELP", false)

        if IsControlPressed(0, 58) then
            explosion(PlayerPedId)
            break
        end
     
        if IsPedDeadOrDying(ped, true) then
            break
        end
    end
end


function explosion(sourceEntity)
    local ped = PlayerPedId()
    local pedCoords = GetEntityCoords(ped)


    local pedPool = GetGamePool("CPed")
    
    for i = 1, #pedPool do

        local npc = pedPool[i]

        local npcCoords = GetEntityCoords(npc)

        local dx = pedCoords.x - npcCoords.x
        local dy = pedCoords.y - npcCoords.y
        local dz = pedCoords.z - npcCoords.z
        local distance = math.sqrt(dx*dx + dy*dy + dz*dz)

        local distanceRate = 50 / distance

        local forceType = 3
        local direction = vector3(distanceRate * dx, -distanceRate * dy, distanceRate * dz)       

        local rotation = vector3(0.0, 0.0, 0.0)
        local boneIndex = 0
        local isDirectionRel = false
        local ignoreUpVec = true
        local isForceRel = true
        local p12 = false
        local p13 = true

        SetPedToRagdoll(npc, 1, 1, 0, true, true, true)
        ApplyForceToEntity(npc, forceType, direction, rotation, boneIndex, isDirectionRel, ignoreUpVec, isForceRel, p12, p13)
    end
end

Also this script you are trying to make is kinda sus :upside_down_face:

1 Like

I’m playing on a small server with friends and we’re Native Americans. the idea is to insert a small “super power” as for example in the video https://youtu.be/IQpdwjiu8_E?t=516
at 8:36. I initially tried to convert this script Shockwave [LUA] - GTA5-Mods.com but gave up having little knowledge here.

I saw that the script you modified works with NPCs, it’s a good start. Thank you.

I don’t know how to move

I saw that you used GetEntityCoords(npc) for the coordinates, but how do I get the other online players in range and the players’ vehicles?

NOT TESTED:

For players, something like:

for player in ipairs(GetActivePlayers()) do
 -- do something with the player 
end

For nearby cars, same way as the nearby peds:

local vehiclePool = GetGamePool("CVehicle")

for i = 1, #vehiclePool do
 -- do something with vehiclePool[i]
end

Again, just wrote this code here and didn’t test it so it might not fully work. I might actually develop this into a free script, seems like a fun idea (minus the suicide vest)

1 Like

Thanks for the advice, I continue to try to improve by following your advice. clearly the vest is left over from an old code. I created an item already inserted in the server which is a wooden shaman’s stick, the idea is that with that stick in your hand there will be the “power of the wave”. but this will be a next step, the most complicated part will be the wave