Jump to content

x[ استفسار ]x بالجداول


Recommended Posts

السلام عليكم ورحمة الله وبركاته

عندي استفسار

مثلا

مسوي لين يكتب باف 8 ss

يروح ضايفه لجدول

table.insert

بعدين لين يموت يحذفه من الجدول

الحين مثلا اكتب باف 8 who

يجيب اسم اخر واحد بالجدول

كيف اجيب اسم اخر واحد بالجدول

وشكرا مقدما :mrgreen:

Link to comment

Table = {} 
  
  
addCommandHandler('ss', 
function ( player )  
    table.insert(Table,player) 
end) 
  
addEventHandler('onPlayerWasted',root, 
function (  )  
    for key , value in ipairs ( Table) do 
        if ( value == source ) then 
            table.remove(Table,key) 
            break 
        end 
    end 
end) 
  
addCommandHandler('who', 
function ( player )  
    if ( #Table == 1 ) then 
        outputChatBox( getPlayerName(Table[1])..' فقط هذا اللاعب الموجود بالجدول',player) 
    elseif ( #Table > 1 ) then 
        outputChatBox( ' يوجد اكثر من لاعب داخل الجدول',player) 
    end 
end) 

هالمثال مايحتاج شرح لما يكتب الكلمة يدخله للجدول ولما يموت يطلعه من الجدول

وفيه لاعب واحد فقط بالجدول راح يحط اسمه واذا فيه اكثر من لاعب بيقولك ان فيه اكثر من لاعب who واذا كتبت

وبهالطريقة جبنا اخر لاعب بالجدول

Table[1]

ولو مثلا فيه اثنين بالجدول وتبي تجيب ثاني لاعب تغير رقم 1 الي 2 عشان يجيب القيمة الثانية الي هي اللاعب

اتمني فهمت

:roll:

Edited by Guest
Link to comment

^ value بـ key سطر 12 بدل

ذا مثال اذا حذفت اللاعب من الجدول وكان آخر لاعب بالجدول يحطه بمتغير وتقدر تجيب المتغير بعدين :

p, last = {}; 
  
addCommandHandler ( 'add', function ( plr, _, state ) 
    if state == '1' then 
        table.insert ( p, plr ) 
            outputChatBox ( #p ) 
    else 
        for k,v in ipairs ( p ) do 
            if v == plr then 
                if k == 1 then last = v end 
                    table.remove ( p, k ) 
                break 
            end 
        end 
    end 
end) 
  
addCommandHandler ( 'who', function ( ) 
    if last and getElementType ( last ) == 'player' then 
        outputChatBox ( getPlayerName ( last ) ) 
        end 
    end 
) 
Edited by Guest
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...