Jump to content

Defining how many crate objects there is.


villr

Recommended Posts

Hello, how can i define how many objects i get from this code?

local objects = 0 
addEvent( "seeIfThereisCrates", true ) 
addEventHandler( "seeIfThereisCrates", getLocalPlayer(),  
function (player) 
for i,elem in ipairs(getElementsByType("object")) do 
if getElementModel(elem) == 2912 then 
local objects = elem+1 
outputChatBox("client:".. objects) 

Itested that and didnt work :S

It always tell me 1.

EDIT: And dont think i didnt use ends and things like that because its not in the code LOL.

Edited by Guest
Link to comment
addEvent("seeIfThereisCrates", true) 
addEventHandler("seeIfThereisCrates", root, 
function (player) 
     local objects = 0 
     for i,elem in ipairs(getElementsByType("object")) do 
          if getElementModel(elem) == 2912 then 
               local objects = objects + 1 
          end 
     end 
     outputChatBox("client: "..objects) 
end) 

Link to comment
Guest Guest4401
addEvent("seeIfThereisCrates", true) 
addEventHandler("seeIfThereisCrates", root, 
    function (player) 
        local objects = 0 
        for i,elem in ipairs(getElementsByType("object")) do 
            if getElementModel(elem) == 2912 then 
                objects = objects + 1 
            end 
        end 
        outputChatBox("client: "..objects) 
    end 
) 

Link to comment
addEvent("seeIfThereisCrates", true) 
addEventHandler("seeIfThereisCrates", root, 
    function (player) 
        local objects = 0 
        for i,elem in ipairs(getElementsByType("object")) do 
            if getElementModel(elem) == 2912 then 
                objects = objects + 1 
            end 
        end 
        outputChatBox("client: "..objects) 
    end 
) 

Thanks! :)

Link to comment
and my code not work? lol
local o = 0 
for i = 1,5 do 
    o = o + 1 
end 
print(o) --> 5 

local o = 0 
for i = 1,5 do 
    local o = o + 1 
end 
print(o) --> 0 

really?

i have tested my code and it work, all you have did is making it global while this not needed since he will not use it outside the function.

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