Jump to content

I need help.


Viudes

Recommended Posts

Posted

say always error "stack overflow" How i can fix this?

 


function spawnVehicle(x,y,z,VehicleName)
id = getVehicleModelFromName(VehicleName)
spawnVeh = spawnVehicle (id, -2322.58496, -1622.78491, 483.70908)
end

addEvent("onSpawnVehicle", true)
addEventHandler("onSpawnVehicle",getRootElement(),spawnVehicle)

 

Posted
function spawnVehicleF(x,y,z,VehicleName)
	id = getVehicleModelFromName(VehicleName)
	spawnVeh = spawnVehicle(id, -2322.58496, -1622.78491, 483.70908)
end
addEvent("onSpawnVehicle", true)
addEventHandler("onSpawnVehicle",getRootElement(),spawnVehicleF)

You can't name the function the same as you'd call the default MTA function or it'll recreate it.

  • Like 1
Posted

Basically you can do like this
 

local _spawn = spawnVehicle

function spawnVehicle ( x, y, z, VehicleName )
    _spawn ( getVehicleModelFromName ( VehicleName ), -2322.58496, -1622.78491, 483.70908 )
end

 

  • Like 1
  • Forum Administrators
Posted
function mySpawnVehicle(x,y,z,VehicleName)
  id = getVehicleModelFromName(VehicleName)
  spawnVeh = spawnVehicle (id, -2322.58496, -1622.78491, 483.70908)
end
addEvent("onSpawnVehicle", true)
addEventHandler("onSpawnVehicle",getRootElement(),mySpawnVehicle)

Don't overwrite function names unless you know what you are doing.

  • Like 1
Posted

Stack overflaw because you called spawnVehicle function within your re-defined spawnVehicle function, this will cause the function to be called infinite times and cause a stack overflaw.

  • Like 1

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...