Jump to content

№ Player


Mr. Maxilian

Recommended Posts

Posted

Hi everyone!

I need to do one feature, but I don 't know how.

I need every player who enters the game to assign a certain number starting from 1. And I also need these numbers saved before the player comes out. If the player has left the game, then his number may be taken by another.

Help me, please.

Posted

So basically you need an ID system.

Simplest way: Set up an array and whenever a player joins run a cycle to find an empty spot in the table. First player enters, cycle runs, finds that the first spot in the array (which is 1) is empty, puts the player there. Next player will find the second spot. First player leaves, you empty this spot, and you're pretty much done.

Posted
2 minutes ago, WorthlessCynomys said:

So basically you need an ID system.

Simplest way: Set up an array and whenever a player joins run a cycle to find an empty spot in the table. First player enters, cycle runs, finds that the first spot in the array (which is 1) is empty, puts the player there. Next player will find the second spot. First player leaves, you empty this spot, and you're pretty much done.

How to write such a function?

Posted
-- SERVER-SIDE

local players = {}

addEventHandler("onPlayerJoin", root,
  function()
    for i = 1, #players+1, 1 do
      if getElementType(players[i]) != "player" then
        players[i] = source
        outputChatBox(i)
        break
      end
    end
  end
)

 

  • Like 1

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