Where does this id variable come from?
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:
And changed it a little bit to automatically be called when a user connects. So I removed anything related to admin: PHP Code:
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 |
Re: Where does this id variable come from?
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 ). |
Re: Where does this id variable come from?
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. |
Re: Where does this id variable come from?
Thanks guys!
|
| All times are GMT -4. The time now is 02:34. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.