Raised This Month: $ Target: $400
 0% 

Where does this id variable come from?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chinga
Junior Member
Join Date: May 2021
Old 05-17-2021 , 15:40   Where does this id variable come from?
Reply With Quote #1

Hi,

I'm trying to edit the Pug Mod by Smiley:
https://forums.alliedmods.net/showthread.php?t=217539

What I want to do is that players who join the server will automatically be ready, so I added copied the function of force ready by admin:

PHP Code:
public PUG_ForceReady(id,iLevel)
{
    if(
g_bReadySystem && access(id,iLevel))
    {
        new 
szName[MAX_NAME_LENGTH];
        
read_argv(1,szName,charsmax(szName));
        
        new 
iPlayer cmd_target(id,szName,CMDTARGET_OBEY_IMMUNITY);
        
        if(
iPlayer)
        {
            
PUG_CommandClient(id,"!forceready","PUG_FORCE_READY",iPlayer,PUG_Ready(iPlayer));
        }
    }
    
    return 
PLUGIN_HANDLED;


And changed it a little bit to automatically be called when a user connects.
So I removed anything related to admin:

PHP Code:
public PUG_ForceReadyAuto(id)
{
    if(
g_bReadySystem && access(idl))
    {
        new 
szName[MAX_NAME_LENGTH];
        
read_argv(1,szName,charsmax(szName));
        
        new 
iPlayer cmd_target(id,szName);
        
        if(
iPlayer)
        {
            
PUG_CommandClient(id,"!forceready","PUG_FORCE_READY",iPlayer,PUG_Ready(iPlayer));
        }
    }
    
    return 
PLUGIN_HANDLED;



But there a few things I don't understand: Where does this id variable come from? And also, who calls these functions? In this file no one is calling these functions so I am not sure where it comes from. I searched every where in the .sma files but there is no where in the code where these functions are being called (Not the one I created, but the other ones such as PUG_ForceReady
chinga is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-17-2021 , 16:24   Re: Where does this id variable come from?
Reply With Quote #2

It depends.

If its a function that is automatically called by a game event like client_disconnect( id ), client_connect( id ) then id is the player id.

If it's a function you created, then it's whatever value you pass to it when called. For example, PUG_ForceReadyAuto(id) or PUG_ForceReadyAuto( 1 ) / PUG_ForceReadyAuto( 29 ) or PUG_ForceReadyAuto( SomeVariable ). If you are calling this at client_authorized( id ) or client_putinserver( id ) and you want it to impact that player, you can pass the id variable from those functions to it, PUG_ForceReadyAuto( id ).
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-18-2021 , 02:11   Re: Where does this id variable come from?
Reply With Quote #3

To clarify, "id" is a variable and you could name it whatever you want. However, it has become common convention to use the variable "id" to indicate the player entity index.

Functions like client_disconnect(id) and client_connect(id) are actually called by the core of AMX Mod X when that particular event occurs and these are known as forwards. These have predefined arguments as documented in the include files.

Some functions, like register_clcmd() allows you to register a callback function so that when that registered event occurs, your callback function is called. These functions need to define specific arguments that will be passed to the function when it's called due to the registered event. For register_clcmd(), it will call the callback function with three arguments often denoted with variables: id, level, and cid (you can name these variable however you like but it's helpful to stick with convention). The second and third arguments are optional.

In your specific case, PUG_ForceReady() is actually a callback being registered with register_clcmd(). The call to register_clcmd() is abstracted so it's not the most obvious but it is called such that it registers the "!forceready". So, when a player sends the "!forceready" command via the client, it will cause PUG_ForceReady() to be called.

Regarding your final goal, you can force the ready state on players when they join the server by simply calling PUG_Ready() when you want to force them to be ready. I would presumably you would want to wait until they join a team to do this though. You'll have to look out for accidentally introducing a bug or other unintended behavior though.
__________________
fysiks is offline
chinga
Junior Member
Join Date: May 2021
Old 05-18-2021 , 03:50   Re: Where does this id variable come from?
Reply With Quote #4

Thanks guys!
chinga is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:34.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode