Eshtiz Posted February 23, 2012 Share Posted February 23, 2012 It gives an error on line 261: attempt to compare number with nil whole command stopped working line: 16 here (only posted function) function getNearbyVehicles(thePlayer, commandName) if (exports.global:isPlayerAdmin(thePlayer)) then outputChatBox("Nearby Vehicles:", thePlayer, 255, 126, 0) local count = 0 for index, nearbyVehicle in ipairs( exports.global:getNearbyElements(thePlayer, "vehicle") ) do local thisvehid = getElementData(nearbyVehicle, "dbid") local vehicleID = getElementModel(nearbyVehicle) local vehicleName = getVehicleNameFromModel(vehicleID) local owner = getElementData(nearbyVehicle, "owner") local faction = getElementData(nearbyVehicle, "faction") count = count + 1 local ownerName = "" if (faction>0) then local theTeam = exports.pool:getElement("team", faction) if theTeam then ownerName = getTeamName(theTeam) end elseif (owner==-1) then ownerName = "Admin" elseif (owner>0) then ownerName = exports['cache']:getCharacterName(owner) else ownerName = "Civilian" end if (thisvehid) then outputChatBox(" " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) elseif not (thisvehid) then outputChatBox(" " .. "*Temporary* " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) end end if (count==0) then outputChatBox(" None.", thePlayer, 255, 126, 0) end end end addCommandHandler("nearbyvehicles", getNearbyVehicles, false, false) Link to comment
mjau Posted February 23, 2012 Share Posted February 23, 2012 well idebug says it all youre trying to comapre a number with a nil value, u sure there is any elemtndata on the vehicle ? Link to comment
TAPL Posted February 23, 2012 Share Posted February 23, 2012 try this function getNearbyVehicles(thePlayer, commandName) if (exports.global:isPlayerAdmin(thePlayer)) then outputChatBox("Nearby Vehicles:", thePlayer, 255, 126, 0) local count = 0 for index, nearbyVehicle in ipairs( exports.global:getNearbyElements(thePlayer, "vehicle") ) do local thisvehid = getElementData(nearbyVehicle, "dbid") local vehicleID = getElementModel(nearbyVehicle) local vehicleName = getVehicleNameFromModel(vehicleID) local owner = getElementData(nearbyVehicle, "owner") local faction = getElementData(nearbyVehicle, "faction") count = count + 1 local ownerName = "" if (tonumber(faction) > 0) then local theTeam = exports.pool:getElement("team", faction) if theTeam then ownerName = getTeamName(theTeam) end elseif (owner==-1) then ownerName = "Admin" elseif (owner>0) then ownerName = exports['cache']:getCharacterName(owner) else ownerName = "Civilian" end if (thisvehid) then outputChatBox(" " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) elseif not (thisvehid) then outputChatBox(" " .. "*Temporary* " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) end end if (count==0) then outputChatBox(" None.", thePlayer, 255, 126, 0) end end end addCommandHandler("nearbyvehicles", getNearbyVehicles, false, false) Link to comment
Eshtiz Posted February 23, 2012 Author Share Posted February 23, 2012 try this function getNearbyVehicles(thePlayer, commandName) if (exports.global:isPlayerAdmin(thePlayer)) then outputChatBox("Nearby Vehicles:", thePlayer, 255, 126, 0) local count = 0 for index, nearbyVehicle in ipairs( exports.global:getNearbyElements(thePlayer, "vehicle") ) do local thisvehid = getElementData(nearbyVehicle, "dbid") local vehicleID = getElementModel(nearbyVehicle) local vehicleName = getVehicleNameFromModel(vehicleID) local owner = getElementData(nearbyVehicle, "owner") local faction = getElementData(nearbyVehicle, "faction") count = count + 1 local ownerName = "" if (tonumber(faction) > 0) then local theTeam = exports.pool:getElement("team", faction) if theTeam then ownerName = getTeamName(theTeam) end elseif (owner==-1) then ownerName = "Admin" elseif (owner>0) then ownerName = exports['cache']:getCharacterName(owner) else ownerName = "Civilian" end if (thisvehid) then outputChatBox(" " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) elseif not (thisvehid) then outputChatBox(" " .. "*Temporary* " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) end end if (count==0) then outputChatBox(" None.", thePlayer, 255, 126, 0) end end end addCommandHandler("nearbyvehicles", getNearbyVehicles, false, false) Thank you but what did you do? I have similar errors I'm trying to fix EDIT:nvm Link to comment
drk Posted February 23, 2012 Share Posted February 23, 2012 try this function getNearbyVehicles(thePlayer, commandName) if (exports.global:isPlayerAdmin(thePlayer)) then outputChatBox("Nearby Vehicles:", thePlayer, 255, 126, 0) local count = 0 for index, nearbyVehicle in ipairs( exports.global:getNearbyElements(thePlayer, "vehicle") ) do local thisvehid = getElementData(nearbyVehicle, "dbid") local vehicleID = getElementModel(nearbyVehicle) local vehicleName = getVehicleNameFromModel(vehicleID) local owner = getElementData(nearbyVehicle, "owner") local faction = getElementData(nearbyVehicle, "faction") count = count + 1 local ownerName = "" if (tonumber(faction) > 0) then local theTeam = exports.pool:getElement("team", faction) if theTeam then ownerName = getTeamName(theTeam) end elseif (owner==-1) then ownerName = "Admin" elseif (owner>0) then ownerName = exports['cache']:getCharacterName(owner) else ownerName = "Civilian" end if (thisvehid) then outputChatBox(" " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) elseif not (thisvehid) then outputChatBox(" " .. "*Temporary* " .. vehicleName .. " (" .. vehicleID ..") with ID: " .. thisvehid .. ". Owner: " .. ownerName, thePlayer, 255, 126, 0) end end if (count==0) then outputChatBox(" None.", thePlayer, 255, 126, 0) end end end addCommandHandler("nearbyvehicles", getNearbyVehicles, false, false) Thank you but what did you do? I have similar errors I'm trying to fix EDIT:nvm if (tonumber(faction) > 0) then You have to convert variable faction to number. Then you can compare it with another number. You can't compare strings with numbers. Now you know what he did? 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