Jump to content

setRadioChannel(0) causes C Stack overflow


Recommended Posts

Posted

So im experienting with MTA and Lua and noticed that setRadioChannel(0) didnt work for me at first so i added it in the onClientPlayerRadioSwitch event which works but causes a C Stack Overflow.

addEventHandler("onClientPlayerRadioSwitch",getRootElement(),function()  
  
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if(vehicle) then 
        if(getElementModel(vehicle) == 432) then 
            setRadioChannel(0) 
            cancelEvent() 
        end 
    end 
     
end) 

Edit it seems it doesnt matter which radio number you enter and it doesnt matter if you cancel the event or not

Posted

setRadioChannel may be triggering 'onClientPlayerRadioSwitch'!

Actually from the looks of it, I would say it definitely triggers that event.

signatures.php?user=TIM3&combo=69&bg=1

  • MTA Team
Posted

In effect, it does trigger that event, so it's cycling the same function over and over causing a stack overflow.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted
addEventHandler("onClientPlayerRadioSwitch", root, 
function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if (vehicle) then 
        if (getElementModel(vehicle) == 432) then 
            if getRadioChannel() ~= 0 then 
                setRadioChannel(0) 
                cancelEvent() 
            end 
        end 
    end 
end) 

  • Thanks 1
CiTLh.png
Posted

Well stack overflow is a function that call another function which call the first function this called a trail function You should visit lua user wiki to see how to fix it !

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

  • MTA Team
Posted
addEventHandler("onClientPlayerRadioSwitch", root, 
function() 
    local vehicle = getPedOccupiedVehicle(localPlayer) 
    if (vehicle) then 
        if (getElementModel(vehicle) == 432) then 
            if getRadioChannel() ~= 0 then 
                setRadioChannel(0) 
                cancelEvent() 
            end 
        end 
    end 
end) 

Should fix it perfectly.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...