Jump to content

Attempt to concatenate global.


Guest Guest26901

Recommended Posts

  • Other Languages Moderators

Variable id2 is boolean, not number, because setElementData function return boolean. Read arguments on wiki before post something!

Use

getElementData 

function if you want get data.

Also If you want boolean value convert to string use

tostring 

function.

Edited by Guest
Link to comment
  • Other Languages Moderators

and please next time use lua button not Code.

Lj1UB.png

EDIT:

is your code client-side or server-side?

if it client side

outputChatBox in client-side does not need player argument.

btw: player argument here does not look defined.

outputChatBox("Załadowałeś trociny!", player) 

if it server-side

outputChatBox in server-side need player argument.

outputChatBox("Id: " .. id .. "Id 2: " .. id2, 0, 255, 0) 

Link to comment

If i use "getElementData": (this is client script)

  
function towarTrociny() 
    dest = markers[math.random(1, #markers)] 
    if towar == 0 then 
        towar = 1 
        outputChatBox("Załadowałeś trociny!", player) 
        destblip = createBlip( dest[1], dest[2], dest[3], 41, 2, 255, 255, 0, 0, 100) 
        setElementData(source, "id2", dest[4]) 
        id2 = getElementData(source, "id2") 
        outputChatBox("Id: " .. id .. "Id 2: " .. id2, 0, 255, 0) 
    else 
        outputChatBox("Aby załadować ten towar musisz mieć minimum 0 punktów!", 0, 255, 0) 
    end 
end 
  

Error:

Attempt to concatenate global 'id2' (a nil value).

Sorry...

Link to comment
  • Other Languages Moderators

I can't see where is id define.

Since it client-side, Mostly you should use localPlayer Instead of source. Otherwise, post full code, includes the event you're using and the Table (markers).

Link to comment
  
-- Współrzędne: x, y, z   
local markers = { 
                { -1725, -121, 2 }, 
                {-1854, 1402, 6.1}, 
                {-2282, 2278, 4,5}, 
                {-367, 1547, 75,1}, 
                {345, 2534, 16,2}, 
                {1641, 2412, 10}, 
                {-2887, 503, 4}, 
                {-1515, 721, 6}, 
                {-683, 965, 12}, 
                {948, 2279, 11}, 
                {1488, 2146, 10}, 
                {1910, 2157, 10}, 
                {2242, 1977, 9}, 
                {-658, 2318, 138}, 
                {-2054, -2565, 30}, 
                {-1416, -1468, 101}, 
                {-605, -483, 25}, 
                {-55, -326, 5}, 
                {1077, -307, 75}, 
                {-2644, 1334, 7}, 
                {2481, 2796, 10}, 
                {-857, -1944, 15}, 
                {-87, -1574, 2}, 
                {-2264, -1688, 480}, 
                { -2029.1010742188, 172.45364379883, 27.35425567627 } 
                } 
  
source = getLocalPlayer() 
  
local towar = 0 
  
-- Tworzenie markerów i blipów oraz inicjowanie ich 
for k, v in ipairs (markers) do 
    destmarker = createMarker(v[1], v[2], v[3], "cylinder", 3, 255, 255, 0, 255) 
    setElementData(destmarker, "id", v[4]) 
    id = getElementData(destmarker, "id") 
    createBlip(v[1],v[2],v[3], 51) 
end 
  
-- Funkcja rozładunek 
function rozladunek(source) 
    for b, tow in ipairs (pack) do 
        if towar == b and id == id2 then 
            triggerServerEvent("punkty", localPlayer, points) 
            towar = 0 
            rmoney = math.random(tow[4],tow[5]) 
            triggerServerEvent("kasa", localPlayer, rmoney) 
            outputChatBox("Rozładowałeś: " .. tow[2], player) 
            destroyElement(destblip) 
        else 
            outputChatBox("To nie jest ten rozładunek!", 0, 255, 0) 
        end 
    end 
end 
  
-- Funkcje załadunków 
function towarTrociny() 
    dest = markers[math.random(1, #markers)] 
    if towar == 0 then 
        towar = 1 
        outputChatBox("Załadowałeś trociny!", player) 
        destblip = createBlip( dest[1], dest[2], dest[3], 41, 2, 255, 255, 0, 0, 100) 
        setElementData(source, "id2", dest[4]) 
        id2 = getElementData(source, "id2") 
        outputChatBox("Id: " .. id .. "Id 2: " .. id2, player, 0, 255, 0) 
    else 
        outputChatBox("Aby załadować ten towar musisz mieć minimum 0 punktów!", 0, 255, 0) 
    end 
end 
  

Link to comment

Client:

  
for k, v in ipairs (markers) do 
    destmarker = createMarker(v[1], v[2], v[3], "cylinder", 3, 255, 255, 0, 255) 
    createBlip(v[1],v[2],v[3], 51) 
    setElementData(destmarker, "id", v[4])  
end 
  
function towarTrociny() 
    dest = markers[math.random(1, #markers)] 
    if towar == 0 then 
        towar = 1 
        outputChatBox("Załadowałeś trociny!", player) 
        destblip = createBlip( dest[1], dest[2], dest[3], 41, 2, 255, 255, 0, 0, 100) 
        setElementData(source, "id2", dest[4]) 
    else 
        outputChatBox("Aby załadować ten towar musisz mieć minimum 0 punktów!", player, 0, 255, 0) 
    end 
end 
  

Server:

  
function rozladunek(source) 
    local x1, y1, z1 = getMarkerTarget(source) 
    local x2, y2, z2 = getMarkerTarget(blipmarker) 
    for b, tow in ipairs (pack) do 
        if towar == b and x1 == x2 and y1 == y2 then 
            setElementData(getLocalPlayer(),"points",tonumber(points + 1)) 
            towar = 0 
            rmoney = math.random(tow[4],tow[5]) 
            givePlayerMoney( source, tonumber(rmoney)) 
            outputChatBox("Rozładowałeś: " .. tow[2], player) 
            destroyElement(destblip) 
        else 
            outputChatBox("To nie jest ten rozładunek!", player, 0, 255, 0) 
        end 
    end 
end 
addEventHandler("rozl", getRootElement(), rozladunek) 
  

Why can i unload the goods in all the markers? Error:

Bad argument @ 'getMarkerTarget' 

Link to comment

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