1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

SA-MP Player ID System

Discussion in 'Scripts' started by StreetGT, Jan 4, 2017.

Tags:
  1. StreetGT

    StreetGT Senpai Global Moderator Wiki Moderator Developer

    Messages:
    201
    Likes Received:
    90
    Joined:
    Aug 8, 2016
    Hello there, I saw a lot of people here in forum asking about a SA-MP Player ID system to be implemented in GTA:N, there is no need for that since you can implement it using C#.

    This is basicly my first time coding C# :=P

    Add it your server Settings (settings.xml), example.
    NOTICE: use playerids always on top or won't work.
    PHP:
    <resource src="playerids" />
    <
    resource src="welcomemessages" />
    <
    resource src="freeroam" />
    <
    resource src="admin" />
    Exported Methods:
    PHP:
    // Returns Client give ID or Part Of Name
    public Client findPlayer(Client senderstring idOrName)

    // Returns ID  given a Client
    public int getIdFromClient(Client target)

    // Returns Client given a ID
    public Client getClientFromId(Client senderint id)
    Settings from resouce (meta.xml)
    PHP:
    <settings>
        <
    setting name="max_players" value="50" default="50"/> Set your server max players here.
        <
    setting name="player_tags" value="false" default="false"/> If you want to add ID on player head set to true.
    </
    settings>

    How to use findPlayer, example:
    PHP:
    [Command("giveweapon""~y~USAGE: ~w~/giveweapon [id/PartOfName] [weapon]"GreedyArg true)]
    public 
    void GiveWeaponCommand(Client senderstring idOrNameWeaponHash weapon)
    {
         
    Client target API.exported.playerids.findPlayer(senderidOrName);
         
    API.givePlayerWeapon(targetweapon9999truetrue);
    }
    Another example using getIdFromClient:
    PHP:
    public void onPlayerConnect(Client player)
    {

        
    API.sendNotificationToAll("~b~~h~" player.name "("API.exported.playerids.getIdFromClient(player) + ")~h~ ~w~joined.");
        
    API.sendChatMessageToAll("~b~~h~" player.name "(" API.exported.playerids.getIdFromClient(player) + ")~h~ ~w~joined.");
    }

    Source Code - LINK

    Feel free to comment and improve the code if you want to!

    Greetings,
    StreetGT
     
  2. VFRZ

    VFRZ Active Member

    Messages:
    65
    Likes Received:
    19
    Joined:
    Dec 29, 2016
    StreetGT likes this.
  3. xForcer

    xForcer Member

    Messages:
    18
    Likes Received:
    5
    Joined:
    Jan 4, 2017
    Thank you for this! SAMP scripters will love this.
     
  4. MasterZero

    MasterZero Member

    Messages:
    42
    Likes Received:
    22
    Joined:
    Oct 4, 2016
    Very nice! Thanks.
     
  5. Jorge Santamaria

    Jorge Santamaria Member

    Messages:
    38
    Likes Received:
    7
    Joined:
    Dec 8, 2016
  6. Kruzzel

    Kruzzel Active Member

    Messages:
    61
    Likes Received:
    2
    Joined:
    Dec 12, 2016
    It doesn't work for me, don't know why it doesn't create the ID above the player and when I try /freeze 0 or /freeze Kruz or /freeze Kruzzel it doesn't work...
     
  7. StreetGT

    StreetGT Senpai Global Moderator Wiki Moderator Developer

    Messages:
    201
    Likes Received:
    90
    Joined:
    Aug 8, 2016
    You are probably doing something wrong .
     
  8. Kruzzel

    Kruzzel Active Member

    Messages:
    61
    Likes Received:
    2
    Joined:
    Dec 12, 2016
    Yeah, my playerids.cs was empty. By the way, isn't it possible to not see your own ID above your head?
     
  9. xForcer

    xForcer Member

    Messages:
    18
    Likes Received:
    5
    Joined:
    Jan 4, 2017
    If you want to remove the ID number, just remove every line of code that has the word "label" in it.
     
  10. StreetGT

    StreetGT Senpai Global Moderator Wiki Moderator Developer

    Messages:
    201
    Likes Received:
    90
    Joined:
    Aug 8, 2016
    I have a setting to enable / disable it, I know what he wants. I don't think it's possible to show only labels to other players and don't see your own.
     
  11. Hardstop

    Hardstop Active Member

    Messages:
    84
    Likes Received:
    12
    Joined:
    Jan 12, 2017
    Oh goody goody, no more ugly name writings for teleportation or any type of command :=D
     
    MasterZero likes this.
  12. AgresivD

    AgresivD Member

    Messages:
    8
    Likes Received:
    14
    Joined:
    Jan 12, 2017
    Instead this:
    PHP:
    int index getFreeId();
    private 
    int getFreeId()
    {
        foreach (var 
    item in players)
        {
            if (
    item == null)
            {
                return 
    this.players.IndexOf(item);
            }
        }
        return -
    1;
    }
    You could do:
    PHP:
    int index players.IndexOf(itemnull);
     
  13. Flakeycarnivore

    Flakeycarnivore Member

    Messages:
    7
    Likes Received:
    1
    Joined:
    Jan 28, 2017
    Nice work. Everything works correctly when I utilise the command:
    Code:
    [Command("giveweapon", "~y~USAGE: ~w~/giveweapon [id/PartOfName] [weapon]", GreedyArg = true)]
    public void GiveWeaponCommand(Client sender, string idOrName, WeaponHash weapon)
    {
         Client target = API.exported.playerids.findPlayer(sender, idOrName);
         API.givePlayerWeapon(target, weapon, 9999, true, true);
    }
    However I get this exception in console:
    I am unsure as to what this means, should I just ignore it, everything works correctly?
     
  14. leejewitt

    leejewitt Member

    Messages:
    29
    Likes Received:
    0
    Joined:
    Apr 2, 2017
    I get this error in the console when running it I have added the xml code to the meta.xml in the playerid resource folder
     

    Attached Files:

  15. DurtyFree

    DurtyFree New Member

    Messages:
    0
    Likes Received:
    0
    Joined:
    Oct 30, 2016
    Something with your server settings.xml doesn't seem to be right.
    Please post it here.
     
  16. leejewitt

    leejewitt Member

    Messages:
    29
    Likes Received:
    0
    Joined:
    Apr 2, 2017

    Code:
    <?xml version="1.0"?>
    <config xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <servername>[DEV] - Lee's Cops and Robbers</servername>
      <serverport>4499</serverport>
      <maxplayers>50</maxplayers>
      <minclientversion>0.0.0.0</minclientversion>
      <minclientversion_auto_update>true</minclientversion_auto_update>
      <announce>true</announce>
      <password></password>
      <masterserver>" rel="nofollow">http://master.gtanet.work/</masterserver>
      <acl_enabled>true</acl_enabled>
      <loglevel>0</loglevel>
      <log>true</log>
      <global_streaming_range>175</global_streaming_range>
      <player_streaming_range>500</player_streaming_range>
      <vehicle_streaming_range>250</vehicle_streaming_range>
      <vehicle_lagcomp>true</vehicle_lagcomp>
      <onfoot_lagcomp>true</onfoot_lagcomp>
      <refresh_rate>120</refresh_rate>
      <resource src="playerid" />
      <resource src="doormanager" />
      <resource src="cnr" />
      <resource src="daynight" />
      <resource src="playerblips2" />
      <resource src="admin" />
      <resource src="welcomemessages" />
      <announce_lan>true</announce_lan>
      <upnp>false</upnp>
      <fqdn></fqdn>
      <conntimeout>false</conntimeout>
      <allowcefdevtool>false</allowcefdevtool>
    </config>
    
     
    Last edited by a moderator: Apr 12, 2017
  17. DurtyFree

    DurtyFree New Member

    Messages:
    0
    Likes Received:
    0
    Joined:
    Oct 30, 2016
    Weird, that one looks okay.

    Are you sure your running that one?
     
  18. leejewitt

    leejewitt Member

    Messages:
    29
    Likes Received:
    0
    Joined:
    Apr 2, 2017
  19. StreetGT

    StreetGT Senpai Global Moderator Wiki Moderator Developer

    Messages:
    201
    Likes Received:
    90
    Joined:
    Aug 8, 2016
    change from
    Code:
    <resource src="playerid" />
    
    to
    Code:
    <resource src="playerids" />
    
     
  20. leejewitt

    leejewitt Member

    Messages:
    29
    Likes Received:
    0
    Joined:
    Apr 2, 2017
    It was originally playerids but had to type it in again to show on here and forgot to put the "s" at the end as u can see in the error on cmd it is loading playerids
     

Share This Page