Jump to content

تصحيح كود


Recommended Posts

تصحيح كود يجيب عدد الاعبين يلي معهم داتا عن طريق الجدول, الديبق ما فيه اخطاء....

playersTable = {} 
function onRStart() 
outputChatBox("Start", getRootElement(), 255, 255, 255, true) 
timer1 = setTimer(function() 
for i,v in ipairs(getElementsByType("player")) do 
if getElementData(v, "playersInMission") then 
table.insert(playersTable, v) 
if #playersTable < 3 then 
outputChatBox("No Players In The Mission", getRootElement(), 255, 255, 255, true) 
else 
outputChatBox("Have Players In The Mission", getRootElement(), 255, 255, 255, true) 
end 
end 
end 
end, 5000, 1) 
end 
addEventHandler("onResourceStart", resourceRoot, onRStart) 

Link to comment
playersTable = {} 
function onRStart() 
outputChatBox("Start", getRootElement(), 255, 255, 255, true) 
timer1 = setTimer(function() 
for i,v in ipairs(getElementsByType("player")) do 
if getElementData(v, "playersInMission") == true then 
table.insert(playersTable, v) 
if #playersTable < 3 then 
outputChatBox("No Players In The Mission", getRootElement(), 255, 255, 255, true) 
else 
outputChatBox("Have Players In The Mission", getRootElement(), 255, 255, 255, true) 
end 
end 
end 
end, 5000, 1) 
end 
addEventHandler("onResourceStart", resourceRoot, onRStart) 

مانك متحقق من الداتا

true or false

Link to comment
playersTable = {} 
function onRStart() 
outputChatBox("Start", getRootElement(), 255, 255, 255, true) 
timer1 = setTimer(function() 
for i,v in ipairs(getElementsByType("player")) do 
if getElementData(v, "playersInMission") == true then 
table.insert(playersTable, v) 
if #playersTable < 3 then 
outputChatBox("No Players In The Mission", getRootElement(), 255, 255, 255, true) 
else 
outputChatBox("Have Players In The Mission", getRootElement(), 255, 255, 255, true) 
end 
end 
end 
end, 5000, 1) 
end 
addEventHandler("onResourceStart", resourceRoot, onRStart) 

مانك متحقق من الداتا

true or false

مش لازم .

Link to comment

عدلت لك الكود كامل ، جرب

  
function onRStart() 
outputChatBox("Start", getRootElement(), 255, 255, 255, true) 
timer1 = setTimer(function() 
    if getHowManyPlayersInMission() < 3 then 
    outputChatBox("No Players In The Mission",      getRootElement(), 255, 255, 255, true) 
    else 
    outputChatBox("Have Players In The Mission", getRootElement(), 255, 255, 255, true) 
    end 
    end, 5000, 1) 
end 
addEventHandler("onResourceStart", resourceRoot, onRStart) 
  
  
function getHowManyPlayersInMission() 
     plrs = 0 
     for _, player in ipairs(getElementsByType("player")) do 
          if getElementData(player,"playersInMission") then 
               plrs = plrs + 1 
          end 
     end 
     return plrs 
end 
  

أعتذر اذا فيه اخطاء ، جالس اكتب من الجوال

Link to comment

إستخدم هذا الكود عشان تجيب اللاعبين اللي بالداتا المحدده

أسهل لك و أفضل وإذا مافهمت الوظيفة علمني

setElementData( player, "DataName", true ) -- لما يدخل اللاعب للمهمة 
setElementData( player, "DataName", false ) -- لما يطلع اللاعب من المهمة 
  
  
-- Syntax : getPlayersFromData( string data ) 
  
function getPlayersFromData( data ) 
      if type(data) == "string" then 
            local t = {    } 
            local players = getElementsByType("player") 
            for _, i in ipairs( players ) do 
                  if ( getElementData(i,data) == true ) then 
                         table.insert( t, i ) 
                  end 
            end 
            return t 
       else return outputDebugString("Bad Argument @ data , got "..tostring(type(data)), 2) end 
end 
  
-- مثال على إستخدام الوظيفة 
  
setTimer( function() 
     for k, v in ipairs( getPlayersFromData("DataName") ) do 
           outputChatBox(getPlayerName(v)) 
     end 
end, 2000, 0) 
  
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...