DarkMagic Posted July 13, 2018 Share Posted July 13, 2018 Hello guys! I wnt to make a Ped , with Name, Tags etc. but the script says error :/. Debugscript says:ERROR:mta_shootingrange/sourceC.lua : 14 : attempt to index global 'ped'(a nil value) Here is the script: local pedPos = { {1539.3648681641, -1354.3519287109, 329.46493530273, 0, 0, 180, "Jacky", 10}, } addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () for index, value in ipairs (pedPos) do if isElement(pedPos[index]) then destroyElement(pedPos[index]) else ped[index] = createPed(value[8], value[1], value[2], value[3]) setElementRotation(ped[index], 0, 0, 90) ped[index]:setData("ped:shooting", true) ped[index]:setData("ped:shooting", true) setElementFrozen(ped[index], true) ped[index]:setData("ped:name", value[7]) ped[index]:setData("name:tags", "Shooting Range") end end end) Link to comment
Moderators IIYAMA Posted July 13, 2018 Moderators Share Posted July 13, 2018 The table `ped`, does not exist. Don't need to use the table `pedPos` instead? Please read the section guidelines, to learn how to format your code. Link to comment
Moderators Citizen Posted July 13, 2018 Moderators Share Posted July 13, 2018 Try this (check the comments): local ped = {} -- created the empty list to store peds local pedPos = { {1539.3648681641, -1354.3519287109, 329.46493530273, 0, 0, 180, "Jacky", 10}, } addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () for index, value in ipairs (pedPos) do if isElement(ped[index]) then -- we want to get a possible ped from ped table not pedPos destroyElement(ped[index]) -- same here else ped[index] = createPed(value[8], value[1], value[2], value[3]) setElementRotation(ped[index], 0, 0, 90) ped[index]:setData("ped:shooting", true) ped[index]:setData("ped:shooting", true) setElementFrozen(ped[index], true) ped[index]:setData("ped:name", value[7]) ped[index]:setData("name:tags", "Shooting Range") end end end) Link to comment
DarkMagic Posted July 13, 2018 Author Share Posted July 13, 2018 The create ped now working , but there is an another error: ERROR:mta_shootingrange:SourceC.lua:22:attempt to index field '?' (a userdata value) Link to comment
Galactix Posted July 13, 2018 Share Posted July 13, 2018 Show the script causing the error maybe? Link to comment
DarkMagic Posted July 14, 2018 Author Share Posted July 14, 2018 (edited) local monitorSize = {guiGetScreenSize()} local panelSize = {300, 350} local panelPos = {monitorSize[1]/2-panelSize[1]/2, monitorSize[2]/2-panelSize[2]/2} local pedPos = {} local pedPos = { {1539.3648681641, -1354.3519287109, 329.46493530273, 0, 0, 180, "Jacky", 10}, } local weapons= {{"M4"}, {"AK-47"}, {"MP5"}, {"UZI/Tec-9"}, {"Colt-45"}, {"Desert Eagle"}, {"Silenced Colt"}, {"Sörétes"}} local Font1 = dxCreateFont("files/Roboto.ttf", 11) show = false addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () for index, value in ipairs (pedPos) do if isElement(pedPos[index]) then destroyElement(pedPos[index]) else pedPos[index] = createPed(value[8], value[1], value[2], value[3]) setElementRotation(pedPos[index], 0, 0, 90) pedPos[index]:setData("ped:shooting", true) pedPos[index]:setData("ped:shooting", true) setElementFrozen(pedPos[index], true) pedPos[index]:setData("ped:name", value[7]) pedPos[index]:setData("name:tags", "Shooting Range") end end end) function panelRender() if not show then return end dxDrawRectangle(panelPos[1], panelPos[2], panelSize[1], panelSize[2], tocolor(0, 0, 0, 160)) dxDrawRectangle(panelPos[1], panelPos[2], panelSize[1], panelSize[2]-320, tocolor(0, 0, 0, 200)) dxDrawText(" Name - #7cc576Shootingrange", panelPos[1]+580, panelPos[2]-25, panelSize[1]+100, panelSize[2]+70, tocolor(255, 255, 255, 255), 1, Font1, "center", "center", false, false, false, true) dxDrawText("Welcome " ..getPlayerName(localPlayer):gsub("_", " ") .. " to the Shootingrange!", panelPos[1]+10, panelPos[2]+50, panelSize[1]-100, panelSize[2]-400, tocolor(255, 255, 255, 255), 1, Font1) show = true for _, value in ipairs(weapons) do if value[1] == "M4" then dxDrawText(value[1], panelPos[1], panelPos[2], panelSize[1], panelSize[2], tocolor(255, 255, 10, 255)) end end end addEventHandler("onClientRender", root, panelRender) function mutat() show = true if show then panelRender () end end addCommandHandler("mutat", mutat) that ' s the script Edited July 14, 2018 by DarkMagic Bad script Link to comment
Moderators Citizen Posted July 14, 2018 Moderators Share Posted July 14, 2018 (edited) Why did you revert the code we fixed for you ??? local monitorSize = {guiGetScreenSize()} local panelSize = {300, 350} local panelPos = {monitorSize[1]/2-panelSize[1]/2, monitorSize[2]/2-panelSize[2]/2} local pedPos = {} -- it was ped here not pedPos local pedPos = { {1539.3648681641, -1354.3519287109, 329.46493530273, 0, 0, 180, "Jacky", 10}, } local weapons= {{"M4"}, {"AK-47"}, {"MP5"}, {"UZI/Tec-9"}, {"Colt-45"}, {"Desert Eagle"}, {"Silenced Colt"}, {"Sörétes"}} local Font1 = dxCreateFont("files/Roboto.ttf", 11) show = false addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () for index, value in ipairs (pedPos) do if isElement(pedPos[index]) then -- it was ped here not pedPos destroyElement(pedPos[index]) -- it was ped here not pedPos else pedPos[index] = createPed(value[8], value[1], value[2], value[3]) -- it was ped here not pedPos setElementRotation(pedPos[index], 0, 0, 90) -- it was ped here not pedPos pedPos[index]:setData("ped:shooting", true) -- it was ped here not pedPos pedPos[index]:setData("ped:shooting", true) -- it was ped here not pedPos setElementFrozen(pedPos[index], true) -- it was ped here not pedPos pedPos[index]:setData("ped:name", value[7]) -- it was ped here not pedPos pedPos[index]:setData("name:tags", "Shooting Range") -- it was ped here not pedPos end end end) Also use the <> button to add code. Edited July 14, 2018 by Citizen Link to comment
DarkMagic Posted July 15, 2018 Author Share Posted July 15, 2018 (edited) Still not working : debug says : ERROR:mta_shootingrange:SourceC.lua:22:attempt to index field '?' (a userdata value) Code: < local monitorSize = {guiGetScreenSize()} local panelSize = {300, 350} local panelPos = {monitorSize[1]/2-panelSize[1]/2, monitorSize[2]/2-panelSize[2]/2} local ped = {} local marker = {} local pedPos = { {1539.3648681641, -1354.3519287109, 329.46493530273, 0, 0, 180, "Jacky", 10}, } local weapons= {{"M4"}, {"AK-47"}, {"MP5"}, {"UZI/Tec-9"}, {"Colt-45"}, {"Desert Eagle"}, {"Silenced Colt"}, {"Sörétes"}} local Font1 = dxCreateFont("files/Roboto.ttf", 10) show = false local marker = createMarker(1539.3648681641, -1354.3519287109, 328.46493530273, "cylinder", 1, 100, 158, 100, 240, localPlayer) addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () for index, value in ipairs (pedPos) do if isElement(ped[index]) then -- we want to get a possible ped from ped table not pedPos destroyElement(ped[index]) -- same here else ped[index] = createPed(value[8], value[1], value[2], value[3]) setElementRotation(ped[index], 0, 0, 90) ped[index]:setData("ped:shooting", true) ped[index]:setData("ped:shooting", true) setElementFrozen(ped[index], true) ped[index]:setData("ped:name", "Name") ped[index]:setData("name:tags", "Tag") end end end) /> Edited July 15, 2018 by DarkMagic . Link to comment
Discord Moderators Pirulax Posted July 15, 2018 Discord Moderators Share Posted July 15, 2018 (edited) Use the <> tag please. Enable OOP(Object Orientated Programming) in meta.xml using the <oop>true</oop> tag. Or just use setElementData() instead of :setData(), because using OOP only sometimes makes no sense at all. Or if you want a fairly good looking script then you should use :setRotation() instead of setElementRotation() and use :setFrozen() instead of setElementFrozen() Edited July 15, 2018 by Pirulax 1 Link to comment
DarkMagic Posted July 15, 2018 Author Share Posted July 15, 2018 Thank ' s The problem is solved. Link to comment
Discord Moderators Pirulax Posted July 15, 2018 Discord Moderators Share Posted July 15, 2018 Nah, at least you learned something from that ExternalGaming gm Good to see that. 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