Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Get client num(id)

  1. #1

    Question Get client num(id)

    Code:
    main: 
    	level waittill spawn
    	thread forzar
    end	 
    
    forzar:
    
        setcvar "id" "-1"
        setcvar "com" "comando"
    
      while(1)
       {		
           level.id = int(getcvar(id))
           level.com = getcvar(com)
         if (level.id >= 0)
           {
              $player[(level.id)+1] stufftext (level.com)
              setcvar "id" "-1"
           }
       }
    end

    This seems to work, with one or two clients
    example:

    // make the client "2" send the message hello

    Code:
    rcon com "say hello"
    rcon id 2
    result: client 2 sends the message hello


    The problem:
    if they are more than two clients, it works
    but with problems, like this one:

    //// make the customer "4" send the message hello

    Code:
    rcon com "say hello"
    rcon id 4
    result: client 3 sends the message hello

    Conclusion: I think that $ player [(level.id) +1] does not get the correct client id

    Question: What is the correct way to obtain the id of a client?
    Last edited by feralv; October 11th, 2018 at 12:13 AM.

  2. #2
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Sh or AA?

  3. #3

    Default

    To get the right player you need to get his entity number like this:


    main:
    level waittill spawn
    thread forzar
    end

    forzar:

    setcvar "com" ""
    setcvar "id" ""

    while(1)
    {

    wait 0.02


    local.id = int(getcvar(id))
    local.command = getcvar(com)


    for(local.i = 1;local.i <= $player.size;local.i++)
    {

    local.player = $player[local.i]

    if(local.player == NULL)
    end

    if(local.player.entnum == local.id && local.command != "" && local.id != "")
    {

    local.player stufftext local.command

    }
    }

    setcvar id ""
    setcvar com ""

    }

    end

  4. #4

    Default


    forzar:

    setcvar "id" "-1"
    setcvar "com" "say commando"

    while (1)
    {
    local.id = int(getcvar(id))
    if (local.id >= 0 && $player)
    {
    for (local.i = 1; local.i <= $player.size; local.i++)
    {
    if ($player[local.i].entnum == local.id)
    {
    $player[local.i] stufftext (getcvar(com))
    break
    }
    }
    setcvar "id" "-1"
    }
    waitframe
    }
    end


    Try this perhaps?

    Edit: Oh sorry, DoubleKill, didn't see you post, but you don't want to end if there aren't any players or grab the com command every loop, or loop over the players each time, only when it's changed etc. Probably better ways to do it in Reborn lol.
    Last edited by 1337Smithy; October 10th, 2018 at 05:06 AM.

  5. #5

    Default

    Quote Originally Posted by RyBack View Post
    Sh or AA?
    AA

  6. #6
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    You should use the getclientnum reborn check instead of entnum check.
    Code:
     getclientnum $player[local.i] == local.id

  7. #7

    Default

    Thank you for your prompt reply, I will try

  8. #8

    Default

    Thank you !! @ 1337Smithy and @RyBack

    works like a charm

    so I remain:

    Code:
    main: 
    	level waittill spawn
    	thread forzar
    end	
    
    forzar:
    
        setcvar "id" "-1"
        setcvar "com" "your_comand"
    	
    	while(1)
    	{		
    			local.id = int(getcvar(id))
    			if (local.id >= 0)
    			{		
    				for (local.i = 1; local.i <= $player.size; local.i++)
    				{
    					if (getclientnum $player[local.i] == local.id)
    					{
    						$player[local.i] stufftext (getcvar(com))
    						break
    					}				
    				}
    				setcvar "id" "-1"
    			}
    			waitframe
    	}
    end

  9. #9

    Default

    Glad it worked . Btw, what's the difference, Ry? I should really familiarise myself with Reborn at some point.

  10. #10
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Well entnum is the index of the entity in the whoe entity array. The entity array is of size sv_maxentities or smth which is usually 1024 or any other power of 2.
    The game reserves the first 32 (or whatever sv_maxclients is) indices for the player/client entity. So basically ent 0 is client 0 and ent 1 is client 1 and so on.
    The old way of getting the client is by getting the entnum with the same client num. Now reborn has new functions that can change this approach.
    One of them is getclientnum ($player) instead of
    entnum. Makes sense since client num is there for a reason. This however is not much different from the classic check which requires a loop inside the script.

    Another reborn function for the same purpose is getent(entnum) which gets the entity associated with the entnum directly from the entity array without looping. That means it's the fastest way of getting an entity(best performance). Breakthrough developers even thought of it back in 2003/4 and made a function getentitybyentnum(entnum). But that's bt only.

    getent is buggy however so we don't use it a lot. The bt version is stable.


    Sorry for the text wall but you asked for it
    Last edited by RyBack; October 11th, 2018 at 02:39 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •