knightscript Posted January 18, 2016 Share Posted January 18, 2016 Hello, i was using a script that would let me add 3 spawn points but not more, and i would like to add more, i have the following table: local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } local random = math.random ( #spawns ) but after this, i have no idea what to do, my current code is this: function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) if not( isGuestAccount (getPlayerAccount(source)) ) then number2 = {216, 220, 222, 226, 230} numberskin2 = number2 [ math.random ( #number2 ) ] skins = {} fadeCamera (source, true) setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, numberskin2, 0, 0, getPlayerTeam(source)) setTimer (setCameraTarget, 1250, 1, source, source) setTimer (fadeCamera, 2000, 1, source, true) end end addEventHandler ("onPlayerWasted", getRootElement(), onWasted) I tried using the same structure as my random skin function, but it doesnt work. Link to comment
vx89 Posted January 18, 2016 Share Posted January 18, 2016 Almost there. local randomSpawn = spawns[math.random( #spawns)] local sX, sY, sZ = unpack(randomSpawn) Link to comment
knightscript Posted January 18, 2016 Author Share Posted January 18, 2016 Hello, i did this and it sent me into the water, could you please send me the whole snippet please? thank you. Link to comment
knightscript Posted January 19, 2016 Author Share Posted January 19, 2016 Excuse me, vx89, i tried many ways and i had no success with using your code, can you tell me wherethat would go? Thank you Link to comment
MisterQuestions Posted January 19, 2016 Share Posted January 19, 2016 Overwrite spawn function or just change name to this... function spawnPlayer(thePlayer) local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } local lucky = math.random ( #spawns ) spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) return true end Link to comment
Castillo Posted January 19, 2016 Share Posted January 19, 2016 That'll cause a infinite loop, since you named your new function like the native MTA function. Link to comment
MisterQuestions Posted January 19, 2016 Share Posted January 19, 2016 True.. Forgot save original function. local _spawnPlayer = spawnplayer function spawnPlayer(thePlayer) local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } local lucky = math.random ( #spawns ) _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) return true end Link to comment
vx89 Posted January 19, 2016 Share Posted January 19, 2016 What are you trying to achieve XeroxMTA? Overriding a function "globally" overrides it only in his resource, which means he could just call his function - no need to override the spawnPlayer. Link to comment
MisterQuestions Posted January 19, 2016 Share Posted January 19, 2016 What are you trying to achieve XeroxMTA? Overriding a function "globally" overrides it only in his resource, which means he could just call his function - no need to override the spawnPlayer. Well... Idk, i just named the function like that . He can simply change function name and thats it. Link to comment
knightscript Posted January 20, 2016 Author Share Posted January 20, 2016 Im getting this error on my debugscript: ERROR: [gamemodes]/knightsv1/broph.lua:183: attempt to call upvalue '_spawnPlayer' (a nil value) The code I have: local _spawnPlayer = spawnplayer function spawnPlayer(thePlayer) local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } local lucky = math.random ( #spawns ) _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) return true end addEventHandler ("onPlayerWasted", getRootElement(), spawnPlayer) Thanks, Link to comment
knightscript Posted January 20, 2016 Author Share Posted January 20, 2016 vx89: local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) number2 = {216, 220, 222, 226, 230} numberskin2 = number2 [ math.random ( #number2 ) ] skins = {} local theWeapon = getPedWeapon (source) local weaponAmmo = getPedTotalAmmo (source) fadeCamera (source, true) local randomSpawn = spawns[math.random( #spawns)] local sX, sY, sZ = unpack(randomSpawn) setTimer (spawnPlayer, 1000, 1, source, sX, sY, sZ, 0, numberskin2, 0, 0, getPlayerTeam(source)) --setTimer (setCameraTarget, 1250, 1, source, source) --setTimer (fadeCamera, 2000, 1, source, true) setTimer (giveWeapon, 2000, 1, source, 24, 100, true) setTimer (giveWeapon, 2000, 1, source, 25, 100, true) setTimer (giveWeapon, 2000, 1, source, 30, 100, true) end addEventHandler ("onPlayerWasted", getRootElement(), onWasted) I commented out SetCameraTarget and fadeCamera because it didnt solve my problem, what do you think? Link to comment
ALw7sH Posted January 20, 2016 Share Posted January 20, 2016 Im getting this error on my debugscript:ERROR: [gamemodes]/knightsv1/broph.lua:183: attempt to call upvalue '_spawnPlayer' (a nil value) The code I have: local _spawnPlayer = spawnplayer function spawnPlayer(thePlayer) local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } local lucky = math.random ( #spawns ) _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) return true end addEventHandler ("onPlayerWasted", getRootElement(), spawnPlayer) Thanks, local _spawnPlayer = spawnPlayer function spawnPlayer(thePlayer) local thePlayer = source or thePlayer local spawns = { { 816.59997558594, -7209.2998046875, 32.799999237061 }, { 707.20001220703, -7272.6000976563, 32.700000762939 }, { 710.5, -7412.8999023438, 32.799999237061 }, { 798.70001220703, -7654, 32.5 }, { 816.09997558594, -7471.3999023438, 30 }, { 812.40002441406, -7321.6000976563, 32.799999237061 }, } local lucky = math.random ( #spawns ) _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) return true end setTimer(function() addEventHandler("onPlayerWasted", getRootElement(), spawnPlayer) end,100,1) Link to comment
knightscript Posted January 20, 2016 Author Share Posted January 20, 2016 Thank you, i solved the problem, i had my "SetCameraTarget" timer way to high (15000)... Thanks guys. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now