[Request] Need help converting .cs to .lua script

Me and my friend like messing around in our own server and I have been attempting to convert the following file from .cs to .lua and function in resources with little success: [Simple Power Punch - GTA5-Mods.com] I was wondering if this was even possible in the format it is, or if someone could even possibly do it for me (pwetty pwease?)
Muchas Gracias,
SaiDuck

1 Like

SimplePowerPunchSettings.7z (4.2 KB)
heres the file too since thats probably easier

I’m not sure how far someone will go in converting 500 lines of code to another programming language, but you should only consider using the native one to apply force to the entity you want to throw.

Have fun!

local DEFAULT_STRENGTH = 30
local currentStrength = DEFAULT_STRENGTH
local STRENGTH_OFFSET = 10
local activated = false
local shouldSave = true
local shouldCheck = false
local shouldIncrease = true
local shouldDecrease = true
local EveryOne = false
local NeverRagdoll = false
local ShouldBeRagdoll = false
local ThereIsNoStoppingMe = true
local ThereIsNoStoppingMeAtAll = true
local WhereYouAimIsWhereYouThrow = true
local curModel = ""
local StartMode = 57 -- Default to F10
local StoreModel = 58 -- Default to F11
local NextStrength = 119 -- Default to F8
local PrevStrength = 118 -- Default to F7

-- Load Configurations from the .ini file
function LoadConfig()
    local content = LoadResourceFile(GetCurrentResourceName(), "SimplePowerPunch.ini")
    if content then
        for line in string.gmatch(content, "[^\r\n]+") do
            if line:find("StartSimplePowerMod") then StartMode = tonumber(line:match("Keys%.(%w+)"))
            elseif line:find("SaveModelWithStrength") then StoreModel = tonumber(line:match("Keys%.(%w+)"))
            elseif line:find("NextStrength") then NextStrength = tonumber(line:match("Keys%.(%w+)"))
            elseif line:find("PrevStrength") then PrevStrength = tonumber(line:match("Keys%.(%w+)"))
            elseif line:find("DefaultStrength") then DEFAULT_STRENGTH = tonumber(line:match("=%s*(%d+)"))
            elseif line:find("StrengthIncreaseDecreaseBy") then STRENGTH_OFFSET = tonumber(line:match("=%s*(%d+)"))
            elseif line:find("ThereIsNoStoppingMe") then ThereIsNoStoppingMe = line:match("=%s*(%a+)") == "true"
            elseif line:find("ThereIsNoStoppingMeAtAll") then ThereIsNoStoppingMeAtAll = line:match("=%s*(%a+)") == "true"
            elseif line:find("WhereYouAimIsWhereYouThrow") then WhereYouAimIsWhereYouThrow = line:match("=%s*(%a+)") == "true"
            elseif line:find("NeverRagdoll") then NeverRagdoll = line:match("=%s*(%a+)") == "true"
            elseif line:find("EveryOne") then EveryOne = line:match("=%s*(%a+)") == "true"
            end
        end
    else
        print("Could not load configuration file.")
    end
end

-- Apply Force to Entity
function ApplyForce(entity, force)
    ApplyForceToEntity(entity, 1, force.x, force.y, force.z, 0, 0, 0, true, true, true, false, true)
end

-- Key Binding Commands
RegisterCommand('toggleSuperPunch', function()
    activated = not activated
    if activated then
        print("Super Punch Activated")
    else
        print("Super Punch Deactivated")
    end
end, false)
RegisterKeyMapping('toggleSuperPunch', 'Toggle Super Punch', 'keyboard', 'F10')

RegisterCommand('increaseStrength', function()
    if activated and shouldIncrease then
        currentStrength = currentStrength + STRENGTH_OFFSET
        print("Strength increased to: " .. currentStrength)
        shouldIncrease = false
    end
end, false)

RegisterCommand('decreaseStrength', function()
    if activated and shouldDecrease then
        currentStrength = currentStrength - STRENGTH_OFFSET
        if currentStrength < DEFAULT_STRENGTH then currentStrength = DEFAULT_STRENGTH end
        print("Strength decreased to: " .. currentStrength)
        shouldDecrease = false
    end
end, false)
RegisterKeyMapping('increaseStrength', 'Increase Strength', 'keyboard', 'F8')
RegisterKeyMapping('decreaseStrength', 'Decrease Strength', 'keyboard', 'F7')

-- Save model and strength
RegisterCommand('saveModel', function()
    if activated and shouldSave then
        SetResourceKvp("ModelBank:currentStrength", tostring(currentStrength))
        print("Model saved with strength " .. currentStrength)
        shouldSave = false
    end
end, false)
RegisterKeyMapping('saveModel', 'Save Model with Strength', 'keyboard', 'F11')

-- Check if player is hitting an entity and apply super punch
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if activated then
            local ped = PlayerPedId()
            if IsControlPressed(0, 24) then -- Attack key (left mouse button)
                local targetPed = GetMeleeTargetForPed(ped)
                if targetPed and DoesEntityExist(targetPed) then
                    SetPedToRagdoll(targetPed, 500, 500, 0, true, true, false)
                    ApplyForce(targetPed, GetEntityForwardVector(ped) * currentStrength)
                end
            end
        end
    end
end)

-- Reset flags for increase/decrease on key release
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if not IsControlPressed(0, 119) then shouldIncrease = true end -- F8
        if not IsControlPressed(0, 118) then shouldDecrease = true end -- F7
    end
end)

-- Load configurations on resource start
AddEventHandler('onResourceStart', function(resourceName)
    if GetCurrentResourceName() == resourceName then
        LoadConfig()
    end
end)
1 Like

Thanks for your help but it doesn’t seem to be working for me and my friend, ill keep working on it myself i bit, thank you though