#RooTs Posted January 4, 2016 Share Posted January 4, 2016 (edited) Code Removed Edited January 11, 2016 by Guest Link to comment
Rouzbeh Posted January 4, 2016 Share Posted January 4, 2016 Try This: function render() if isPedInVehicle(localPlayer) then local vehicle = getPedOccupiedVehicle (localPlayer) local occupants = getVehicleOccupants(vehicle) local PlayerName = getPlayerName(localPlayer) local VehicleName = getVehicleName (vehicle) local cnt = 0 for i=0, 3 do if occupants[i] and isElement(occupants[i]) then cnt = cnt + 1 else break end dxDrawText(" #FF0000PASSAGEIROS: #FFFFFF" .. tostring(cnt) .. "/4 ", x*870, y*640, x*716, y*351, tocolor(255, 255, 255), x*1.7, "default-bold", "center", "top", false, false, false, true) end end end addEventHandler("onClientRender", root, render) Link to comment
Addlibs Posted January 6, 2016 Share Posted January 6, 2016 On line 13, you break the loop just after first if-else. This means it will stop looping after the first seat without an occupant. Remove 'break' from that line (or the whole line as it's unnecessary) Link to comment
#RooTs Posted January 6, 2016 Author Share Posted January 6, 2016 (edited) friends or @MrTasty, is possible create a table to pull all Occupants the vehicle Example Code Removed that will work ? Edited January 11, 2016 by Guest Link to comment
#RooTs Posted January 6, 2016 Author Share Posted January 6, 2016 (edited) Yeah, that should work what is the correct function, to pull all occupants in one number? getVehicleOccupant -- or getVehicleOccupants the example that I made is the right job? Code Removed Edited January 11, 2016 by Guest Link to comment
#RooTs Posted January 6, 2016 Author Share Posted January 6, 2016 my function not work local AllOccupant = {0,1,2,3,4} local check = 0 for _, v in ipairs (AllOccupant) do car = getPedOccupiedVehicle(player) check = check + getVehicleOccupant (car,v) end dxDrawText(check.....) someone help me ? Link to comment
Revolt Posted January 6, 2016 Share Posted January 6, 2016 function render() local vehicle = getPedOccupiedVehicle(getLocalPlayer()) for _, occupant in pairs(getVehicleOccupants(vehicle)) do local cnt = 0 if (occupant and getElementType(occupant) == "player") then cnt = cnt + 1 end local PlayerName = getPlayerName(getLocalPlayer()) local VehicleName = getVehicleName (vehicle) end dxDrawText(" #FF0000PASSAGEIROS: #FFFFFF" .. tostring(cnt) .. "/" .. tostring(getVehicleMaxPassengers(vehicle)), x*870, y*640, x*716, y*351, tocolor(255, 255, 255), x*1.7, "default-bold", "center", "top", false, false, false, true) end addEventHandler("onClientRender", root, render) Is this what you're looking for? Link to comment
n3wage Posted January 6, 2016 Share Posted January 6, 2016 local cnt = #getVehicleOccupants ( getPedOccupiedVehicle ( localPlayer ) ) + 1; Link to comment
myonlake Posted January 7, 2016 Share Posted January 7, 2016 local cnt = #getVehicleOccupants ( getPedOccupiedVehicle ( localPlayer ) ) + 1; No. getVehicleOccupants returns a key table, not an index table. Your hashtag will not work. Link to comment
n3wage Posted January 7, 2016 Share Posted January 7, 2016 No. getVehicleOccupants returns a key table, not an index table. Your hashtag will not work. That would be a problem if the keys were strings or everything else, with numbers the hashtag works very well. returns = { -- getVehicleOccupants returns [0] = "a", [1] = "b", [2] = "c", [3] = "d" } print ( #returns ) Prints: +1 = the amount of occupants. Link to comment
myonlake Posted January 7, 2016 Share Posted January 7, 2016 (edited) No. getVehicleOccupants returns a key table, not an index table. Your hashtag will not work. That would be a problem if the keys were strings or everything else, with numbers the hashtag works very well. returns = { -- getVehicleOccupants returns [0] = "a", [1] = "b", [2] = "c", [3] = "d" } print ( #returns ) Prints: +1 = the amount of occupants. That's what we call a hack. You should learn Lua and English before throwing crap like that here. If there is no occupant in a seat, it will have no index, meaning your hashtag method will not work since it cannot count non-index tables. It is called a key table when it's not purely indexed, having 0, 2, 5, 10 instead of 1, 2, 3, 4, etc. Wish to see it in action? 0 from print( #{ [ 0 ] = true, [ 2 ] = true } ) You can mind blow with this code addEventHandler( "onResourceStart", resourceRoot, function( ) setTimer( function( ) local function count( table ) local count = 0 for _ in pairs( table ) do count = count + 1 end return count end local vehicle = createVehicle( getVehicleModelFromName( "Premier" ), 0, 0, 3 ) if ( isElement( vehicle ) ) then print( "vehicle created <" .. tostring( vehicle ) .. ">" ) local peds = 10 for i = 0, peds - 1, 2 do local ped = createPed( 0, 0 + i, 0, 3 ) if ( isElement( ped ) ) then print( "ped created <" .. tostring( ped ) .. ">" ) if ( not warpPedIntoVehicle( ped, vehicle, i ) ) then print( "ped <" .. tostring( ped ) .. "> NOT warped to vehicle <" .. tostring( vehicle ) .. "> at slot " .. i ) local occupants = getVehicleOccupants( vehicle ) print( ">> vehicle occupants: #occupants => " .. #occupants ) print( ">> vehicle occupants: count( occupants ) => " .. count( occupants ) ) print( " begin" ) for i, v in ipairs( occupants ) do print( " vehicle occupant: " .. i .. ": " .. tostring( v ) ) end print( " end" ) print( " begin" ) for i, v in pairs( occupants ) do print( " vehicle occupant: " .. i .. ": " .. tostring( v ) ) end print( " end" ) local elements = { "ped", "vehicle" } for i = 1, #elements do local elements = getElementsByType( elements[ i ], resourceRoot ) for i = 1, #elements do destroyElement( elements[ i ] ) end end break else print( "ped <" .. tostring( ped ) .. "> warped to vehicle <" .. tostring( vehicle ) .. "> at slot " .. i ) end end end end end, 50, 1 ) end ) Edited January 7, 2016 by Guest 1 Link to comment
#RooTs Posted January 7, 2016 Author Share Posted January 7, 2016 (edited) Code RemovedIs this what you're looking for? I had already tested the his first example in first post. this will work? @n3wage, I will test your sample also Edited January 11, 2016 by Guest Link to comment
Moderators IIYAMA Posted January 7, 2016 Moderators Share Posted January 7, 2016 No it doesn't. You have to check if the vehicle does exist. Line 4 misplaced, must be de defined before the loop. Line 8 and 9 misplaced and not used. Link to comment
#RooTs Posted January 8, 2016 Author Share Posted January 8, 2016 (edited) . Edited January 11, 2016 by Guest Link to comment
luskanek Posted January 8, 2016 Share Posted January 8, 2016 addEventHandler("onClientRender", root, function() if isPlayerInVehicle(getLocalPlayer()) local vehicle = getPedOccupiedVehicle(getLocalPlayer() local cnt = 0 for _, occupant in pairs(getVehicleOccupants(vehicle)) do if occupant then if getElementType(occupant) == 'player' then cnt = cnt + 1 end end end end end ) What do you need the names of the player and vehicle for? Link to comment
#RooTs Posted January 8, 2016 Author Share Posted January 8, 2016 (edited) . Edited January 11, 2016 by Guest Link to comment
luskanek Posted January 8, 2016 Share Posted January 8, 2016 Well just use the variables in dxDrawText and you're good to go Link to comment
#RooTs Posted January 8, 2016 Author Share Posted January 8, 2016 Well just use the variables in dxDrawText and you're good to go I will test it later Link to comment
n3wage Posted January 9, 2016 Share Posted January 9, 2016 [...]You should learn Lua and English before throwing crap like that here. [...] Why all this arrogance? Ok, i made a mistake, this is normal, you could have just explained why my code wouldn't work without 'disrespecting' me, You don't even know who am i. Also my English isn't perfect, this is a fact, But I have the same right as you to post here, Have a great day . Link to comment
myonlake Posted January 9, 2016 Share Posted January 9, 2016 [...]You should learn Lua and English before throwing crap like that here. [...] Why all this arrogance? Ok, i made a mistake, this is normal, you could have just explained why my code wouldn't work without 'disrespecting' me, You don't even know who am i. Also my English isn't perfect, this is a fact, But I have the same right as you to post here, Have a great day . Because you were replying as if you knew exactly what you were doing. Apparently you didn't, but there you go. Link to comment
#RooTs Posted January 9, 2016 Author Share Posted January 9, 2016 (edited) . Edited January 11, 2016 by Guest Link to comment
#RooTs Posted January 9, 2016 Author Share Posted January 9, 2016 (edited) . Edited January 11, 2016 by Guest Link to comment
Recommended Posts