DN0817 Posted August 13, 2023 Share Posted August 13, 2023 Hey there, i'm fairly new to setting up a server and I got a script based off of the ultimate reallife script. And loading up it has 2 errors but I wanna clear this one up first. I would be really glad if someone could help me. This is the Error: ERROR: [grs]/reallife_server/biz/biz.lua:53: attempt to get length of global 'bizkeys' (a nil value) ERROR: Unable to start resource reallife_server; Start up of resource cancelled by script The script (I didn't know if a snippet is enough or if you need the whole script but I think more is better than less this time): bizArray = {} function setBizData () pnsDohertyIcon = createPickup ( -1908.7257080078, 276.80416870117, 40.696102142334, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", pnsDohertyIcon, onBizPickupHit ) pnsJuniperIcon = createPickup ( -2431.1665039063, 1028.9090576172, 50.039852142334, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", pnsJuniperIcon, onBizPickupHit ) pnsLVIcon = createPickup ( 1967.053, 2166.98, 10.82, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", pnsLVIcon, onBizPickupHit ) pnsLSIcon = createPickup ( 2072.669, -1834.77, 13.555, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", pnsLSIcon, onBizPickupHit ) pizzaStackIcon = createPickup ( -1720.0610351563, 1356.5998535156, 6.8367257118225, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", pizzaStackIcon, onBizPickupHit ) mystiesBarIcon = createPickup ( -2242.4169921875, -89.888648986816, 34.969539642334, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", mystiesBarIcon, onBizPickupHit ) sprunkIcon = createPickup ( -1752.3122558594, -144.58361816406, 3.2039132118225, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", sprunkIcon, onBizPickupHit ) visageHotelIcon = createPickup ( 2110.69, 1870.49, 10.47, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", visageHotelIcon, onBizPickupHit ) vankHoffIcon = createPickup ( -2405.16, 325.73, 34.82, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", vankHoffIcon, onBizPickupHit ) ------------------------------------------------------ tankstelleNordIcon = createPickup ( -2420.09765625, 969.890625, 45.296875, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", tankstelleNordIcon, onBizPickupHit ) tankstelleSuedIcon = createPickup ( -1675.880859375, 431.7705078125, 7.1796875, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", tankstelleSuedIcon, onBizPickupHit ) tankstellePineIcon = createPickup ( -2231.6591796875, -2558.095703125, 31.921875, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", tankstellePineIcon, onBizPickupHit ) --------------------------------------------- bizIcons = { [pnsDohertyIcon]="PaynSprayWangcars", [pnsJuniperIcon]="PaynSprayJuniper", [pnsLVIcon]="PaynSprayLV", [pnsLSIcon]="PaynSprayLS", [pizzaStackIcon]="WellStackedPizza", [mystiesBarIcon]="MistysBar", [sprunkIcon]="Sprunk", [visageHotelIcon]="Visage", [vankHoffIcon]="VankHoff", [tankstelleNordIcon]="TankstelleNord", [tankstelleSuedIcon]="TankstelleSued", [tankstellePineIcon]="TankstellePine" } OttosAutosIcon = createPickup ( -1639.7821044922, 1202.6267089844, 6.879873752594, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", OttosAutosIcon, onBizPickupHit ) TraeumeUndHoffnungen = createPickup ( -127.10718536377, 2258.1259765625, 28.063650131226, 3, 1239, 1, 0 ) addEventHandler ( "onPickupHit", TraeumeUndHoffnungen, onBizPickupHit ) setBizDataSQL ( ) bizkeys = { [1]="PaynSprayWangcars", [2]="PaynSprayJuniper", [3]="Sprunk", [4]="WellStackedPizza", [5]="MistysBar", [6]="Visage", [7]="VankHoff", [8]="TankstelleNord", [9]="TankstelleSued", [10]="TankstellePine", [11]="PaynSprayLV", [12]="PaynSprayLS" } end setTimer ( setBizData, 1000, 1 ) function updateBizKasse () for i=1, #bizkeys do if bizkeys ~= "WellStackedPizza" then dbExec ( handler, "UPDATE ?? SET ??=? WHERE ??=?", "biz", "Kasse", bizArray[bizkeys]["kasse"], "ID", i ) end end outputDebugString ( "Bizkassen wurden gespeichert!" ) updateCoopData () end setTimer ( updateBizKasse, 20*60*1000, 0 ) function onBizPickupHit ( hit ) if source == TraeumeUndHoffnungen then outputChatBox ( "Es gibt wichtigeres als Geld ...", hit, 125, 125, 200 ) elseif bizIcons[source] then local biz = bizIcons[source] local besitzer = bizArray[biz]["inhaber"] if besitzer == "none" then besitzer = "Niemandem" end local bizname = bizArray[biz]["name"] local bizprice = bizArray[biz]["preis"] outputChatBox ( bizname..", gehört: "..besitzer.." - Preis: "..bizprice.." $ und 50 Stunden Mindestspielzeit!", hit, 125, 0, 0 ) if besitzer == "Niemandem" then triggerClientEvent ( hit, "infobox_start", getRootElement(), "Tippe /buybiz\n[bar/bank], um\ndas Geschäft zu\nkaufen! Bei\nbank fallen 2 %\nmehr Kosten an!", 7500, 0, 125, 0 ) end elseif OttosAutosIcon == source then outputChatBox ( "Tippe /givecar [Name] [Eigener Slot] [Slot beim neuen Besitzer], um das Auto an jemanden zu geben.", hit, 200, 200, 0 ) end end function buybiz_func ( player, cmd, typ ) local hatgeld = false local cash = 0 if typ == "bar" then cash = vioGetElementData ( player, "money" ) hatgeld = true elseif typ == "bank" then cash = vioGetElementData ( player, "bankmoney" ) hatgeld = true if not cash then hatgeld = false end end if hatgeld then local biz, bizkey = getNearestBiz ( player ) if biz then local bizprice = false if typ == "bar" then bizprice = bizArray[biz]["preis"] else bizprice = bizArray[biz]["preis"] * 1.02 end if not bizprice then return end if bizprice > cash then return end if bizprice <= cash then if bizArray[biz]["inhaber"] == "none" then if vioGetElementData ( player, "bizkey" ) == 0 then triggerClientEvent ( player, "infobox_start", getRootElement(), "\nGeschäft gekauft!\nTippe /bizhelp\nfür mehr\nInformationen!", 7500, 0, 125, 0 ) vioSetElementData ( player, "bizkey", bizkey ) local pname = getPlayerName ( player ) dbExec ( handler, "UPDATE ?? SET ??=? WHERE ??=?", "userdata", "Bizschluessel", bizkey, "UID", playerUID[pname] ) dbExec ( handler, "UPDATE ?? SET ??=? WHERE ??=?", "biz", "UID", playerUID[pname], "ID", bizkey ) bizArray[biz]["inhaber"] = pname if typ == "bar" then vioSetElementData ( player, "money", vioGetElementData ( player, "money" ) - bizprice ) else vioSetElementData ( player, "bankmoney", vioGetElementData ( player, "bankmoney" ) - bizprice ) end local x, y, z = getElementPosition ( player ) setCameraMatrix ( player, x+10, y+10, z+10, x, y, z ) setTimer ( fixBizBuyCam, 5000, 1, player ) triggerClientEvent ( player, "achievsound", getRootElement() ) else outputChatBox ( "Du hast bereits ein Geschäft - tippe zuerst /sellbiz ein, um dein altes Geschäft zu verkaufen.", player, 125, 0, 0 ) end else triggerClientEvent ( player, "infobox_start", getRootElement(), "\nDas Geschäft\ngehört bereits\njemandem!!", 7500, 125, 0, 0 ) end else triggerClientEvent ( player, "infobox_start", getRootElement(), "\n\nDu hast nicht\ngenug Geld!", 7500, 125, 0, 0 ) end else triggerClientEvent ( player, "infobox_start", getRootElement(), "\n\nDu bist bei\nkeinem Geschaeft!", 7500, 125, 0, 0 ) end else triggerClientEvent ( player, "infobox_start", getRootElement(), "\nTippe /buybiz\n[bar/bank], um\ndas Geschäft zu\nkaufen!", 7500, 0, 125, 0 ) end end addCommandHandler ( "buybiz", buybiz_func ) function sellbiz_func ( player ) if vioGetElementData ( player, "bizkey" ) == 0 then outputChatBox ( "Du hast kein Geschäft!", player, 125, 0, 0 ) else local key = vioGetElementData ( player, "bizkey" ) local biz = bizkeys[key] bizArray[biz]["inhaber"] = "none" local bizprice = bizArray[biz]["preis"] local pname = getPlayerName ( player ) outputDebugString ( "Spieler "..pname.." hat sein Geschäft verkauft." ) outputChatBox ( "Du hast dein Geschäft verkauft und erhaelst "..bizprice.." $!", player, 0, 125, 0 ) vioSetElementData ( player, "bizkey", 0 ) vioSetElementData ( player, "money", vioGetElementData ( player, "money" ) + bizprice ) dbExec ( handler, "UPDATE ?? SET ??=? WHERE ??=?", "userdata", "Bizschluessel", 0, "UID", playerUID[pname] ) dbExec ( handler, "UPDATE ?? SET ??=? WHERE ??=?", "biz", "UID", 0, "ID", key ) datasave_remote ( player ) end end addCommandHandler ( "sellbiz", sellbiz_func ) function fixBizBuyCam ( player ) setCameraTarget ( player, player ) end function getNearestBiz ( player ) local x1, y1, z1 = getElementPosition ( player ) for icon, biz in pairs ( bizIcons ) do local x2, y2, z2 = getElementPosition ( icon ) if getDistanceBetweenPoints3D ( x1, y1, z1, x2, y2, z2 ) <= 3 then for i=1, #bizkeys do if bizkeys == biz then return biz, i end end end end return false, false end function bizhelp_func ( player ) local bizkey = tonumber ( vioGetElementData ( player, "bizkey" ) ) if bizkey == 0 then outputChatBox ( "Du besitzt kein Geschaeft!", player, 125, 0, 0 ) else local biz = bizkeys[bizkey] local bizname = bizArray[biz]["name"] outputChatBox ( "Dein Geschäft: "..bizname..", Kasse: "..bizArray[biz]["kasse"].." $.", player, 200, 200, 15 ) outputChatBox ( "/sellbiz - Geschäft verkaufen, /bizhelp - Diese Hilfe, /bizdraw - Geld abheben, /bizstore - Geld einlagern.", player, 125, 125, 200 ) end end addCommandHandler ( "bizhelp", bizhelp_func ) function bizdraw_func ( player, cmd, amount ) if vioGetElementData ( player, "bizkey" ) > 0 then if amount then local amount = tonumber ( amount ) and math.abs ( tonumber ( amount ) ) or false if amount then local key = vioGetElementData ( player, "bizkey" ) local biz = bizkeys[key] local curmoney = bizArray[biz]["kasse"] if curmoney >= amount then bizArray[biz]["kasse"] = curmoney - amount vioSetElementData ( player, "money", vioGetElementData ( player, "money" ) + amount ) infobox ( player, amount.."$\nrausgenommen", 4000, 0, 200, 0 ) else outputChatBox ( "Du hast nicht so viel Geld in deinem Geschäft!", player, 125, 0, 0 ) end else outputChatBox ( "Bitte gib eine gültige Summe an!", player, 125, 0, 0 ) end else outputChatBox ( "Bitte gib eine gültige Summe an!", player, 125, 0, 0 ) end else outputChatBox ( "Du besitzt kein Geschäft!", player, 125, 0, 0 ) end end addCommandHandler ( "bizdraw", bizdraw_func ) function bizstore_func ( player, cmd, amount ) local key = vioGetElementData ( player, "bizkey" ) if key and key > 0 then if amount and tonumber ( amount ) then local amount = math.abs ( tonumber ( amount ) ) if amount then local biz = bizkeys[key] if vioGetElementData ( player, "money" ) >= amount then bizArray[biz]["kasse"] = bizArray[biz]["kasse"] + amount vioSetElementData ( player, "money", vioGetElementData ( player, "money" ) - amount ) infobox ( player, amount.."$\nreingetan", 4000, 0, 200, 0 ) else outputChatBox ( "Du hast nicht genug Geld bei dir!", player, 125, 0, 0 ) end else outputChatBox ( "Bitte gib eine gültige Summe an!", player, 125, 0, 0 ) end else outputChatBox ( "Bitte gib eine gültige Summe an!", player, 125, 0, 0 ) end else outputChatBox ( "Du besitzt kein Geschäft!", player, 125, 0, 0 ) end end addCommandHandler ( "bizstore", bizstore_func ) function addMoneyToBiz ( id, amount ) local biz = bizkeys[id] bizArray[biz]["kasse"] = bizArray[biz]["kasse"] + amount end Link to comment
, Melvin Posted August 14, 2023 Share Posted August 14, 2023 (edited) Spoiler يبدو أن هناك مشكلة في السيناريو البرمجي الذي قد تكون مسببة للأخطاء التي ترى عبارات الخطأ الخاصة بها. الخطأ الرئيسي الذي يتم الإشارة إليه هو: ``` attempt to get global 'bizkeys' (a nil value) ``` هذا يشير إلى أن المتغير `bizkeys` غير معرف في هذا السياق. يبدو أن هناك جزءًا من البرنامج النصي لا يزال غير مكتمل أو تم تجاهله، وهذا هو السبب في حدوث هذه الأخطاء. الخطأ الذي يظهر في السيناريو يحدث عندما يحاول البرنامج النصي الوصول إلى قيمة في جدول (أو مصفوفة) دون تعريفها أو بدون تهيئتها بشكل صحيح. لهذا الغرض، يجب التأكد من تعريف وتهيئة المتغيرات والجداول (أو المصفوفات) بشكل صحيح قبل استخدامها. هنا بعض الخطوات التي يمكنك اتباعها لحل هذه المشكلة: 1. **تعريف وتهيئة المتغيرات**: تأكد من أن جميع المتغيرات المستخدمة في البرنامج النصي معرفة وتهيئتها بشكل صحيح قبل استخدامها. ضع تعريفات المتغيرات في الأماكن المناسبة في البرنامج النصي. 2. **تحقق من الأكواد ذات الصلة**: الأكواد التي تستخدم المتغيرات غالبًا ما تكون في حاجة إلى تعريفات وإعدادات سابقة. تحقق من الأكواد المحيطة بالأماكن التي تم الإشارة إليها في رسائل الخطأ للتحقق من السياق والترتيب الصحيح. 3. **تحقق من تسلسل الأحداث**: قد يتطلب بعض البرامج تنفيذ أحداث معينة في تسلسل معين. تحقق من تسلسل الأحداث في برنامجك وتأكد من أن كل جزء يتم تنفيذه في الوقت المناسب. 4. **تحقق من نطاق المتغيرات**: تأكد من أن المتغيرات التي تتم استخدامها في وظائفك معرفة في النطاق الصحيح. تجنب استخدام متغيرات غير معرفة في نطاق الوظائف. 5. **التحقق من الشروط والتحكم الشرطي**: تحقق من الشروط والتحكم الشرطي في الأماكن التي يتم فيها استخدام المتغيرات. تأكد من أن الشروط تعمل كما هو متوقع وأنها تحافظ على تعريفات المتغيرات اللازمة. 6. **التحقق من أمثلة المتغيرات**: تحقق من الأمثلة المشابهة في البرنامج النصي وتأكد من أنها تعمل بشكل صحيح. يمكن أن تكون لديك أمثلة سابقة للأكواد تعمل بشكل جيد، ويمكن أن تساعدك في تحديد الاختلافات في الأكواد التي تسبب المشكلة. عند مراجعة وإصلاح الأكواد، تأكد من تجربتها بشكل منفصل بعد كل تغيير للتحقق من حل المشكلة وعدم حدوث أخطاء جديدة. It appears that there is a problem with the script that may be causing the errors for which you are seeing error statements. The main error being pointed out is: ``` attempt to get global 'bizkeys' (a nil value) ``` This indicates that the variable `bizkeys` is not defined in this context. It seems that some part of the script is still incomplete or left out, which is why these errors occur. The error that appears in the scenario occurs when the script tries to access a value in a table (or array) without defining it or not initializing it properly. For this purpose, you must ensure that variables and tables (or arrays) are properly defined and initialized before using them. Here are some steps you can take to solve this problem: 1. **Declare and initialize variables**: Ensure that all variables used in the script are properly defined and initialized before using them. Put variable definitions in the appropriate places in the script. 2. **Check related code**: Code that uses variables often needs definitions and presets. Check the code around the places indicated in the error messages for context and correct order. 3. **Check event sequence**: Some programs may require certain events to be executed in a specific sequence. Check the sequence of events in your program and ensure that each part is executed in a timely manner. 4. **Check Variable Scope**: Ensure that the variables that are used in your functions are defined in the correct scope. Avoid using undefined variables in the scope of functions. 5. **Check conditions and conditional controls**: Check conditions and conditional controls where variables are used. Ensure that the conditions work as expected and that they maintain the necessary variable definitions. 6. **Check Variable Examples**: Check similar examples in the script and make sure they work correctly. You may have previous code examples that work well, and can help you identify code differences that are causing the problem. When reviewing and fixing your code, be sure to try it separately after each change to verify that the problem is resolved and that no new errors occur. Edited August 15, 2023 by Vinyard used google translate to show the English version of the message 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