Raised This Month: $ Target: $400
 0% 

Client Index Ref


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ici
Member
Join Date: Jan 2014
Old 03-18-2015 , 15:11   Client Index Ref
Reply With Quote #1

Why are client indexes not referenced in most of SourceMod's forwards? Is it bad if I reference client indexes in my functions? If somebody could give me an explanation, I'd be thankful!
ici is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-18-2015 , 16:33   Re: Client Index Ref
Reply With Quote #2

because why would you waste your time converting a client to a reference index then immediately undoing that? Client indexes are always going to be the same. Especially since there is disconnect events and connect events. entities other than the player are good for referencing because you cannot really tell when the entity will be destroyed.

However you should Serialize your client indices if you are using Timers and passing in the client, to make sure it is the same client that issued the timer.
Mitchell is offline
ici
Member
Join Date: Jan 2014
Old 03-18-2015 , 17:11   Re: Client Index Ref
Reply With Quote #3

Not this kind of entity reference indexes. Sorry, I meant pointers. I'm little bit confused right now.

Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype)

Aren't &attacker, &inflictor, &Float:damage and &damagetype pointers?

Param_CellByRef - A non-Float cell by reference
I thought that this is a pointer^

I've always thought that the '&' symbol stood for a pointer. Is that not correct?
ici is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-18-2015 , 17:23   Re: Client Index Ref
Reply With Quote #4

Quote:
Originally Posted by ici View Post
Not this kind of entity reference indexes. Sorry, I meant pointers. I'm little bit confused right now.

Action:public(victim, &attacker, &inflictor, &Float:damage, &damagetype)

Aren't &attacker, &inflictor, &Float:damage and &damagetype pointers?

Param_CellByRef - A non-Float cell by reference
I thought that this is a pointer^

I've always thought that the '&' symbol stood for a pointer. Is that not correct?
pointers are a c++ term for variables, & in method params definition means reference.
__________________
WildCard65 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 03-18-2015 , 18:21   Re: Client Index Ref
Reply With Quote #5

Sorry i thought you meant you were serializing clients and passing that into your functions. (via EntIndexToEntRef)
The only reason to reference the client indices is if you plan on having some other plugin call it and change the index then return for you to handle it.

Last edited by Mitchell; 03-18-2015 at 18:22.
Mitchell is offline
ici
Member
Join Date: Jan 2014
Old 03-18-2015 , 18:46   Re: Client Index Ref
Reply With Quote #6

So referencing is just serializing a variable? I thought that the '&' symbol meant do not recreate / initialize a new instance of the variable that is pushed to the function.

In the following example:
PHP Code:
public OnClientPostAdminCheck(client)
{
    if (!
IsValidClient(client) || IsFakeClient(client))
    {
        return;
    }
    
    
decl String:sClientAuth[25];
    
GetClientAuthString(clientsClientAuthsizeof(sClientAuth));
    
    new 
Handle:hDataPack CreateDataPack();
    
WritePackCell(hDataPackclient);
    
WritePackString(hDataPacksClientAuth);
    
    
OnPlayerJoin(sClientAuthhDataPack);

PHP Code:
OnPlayerJoin(const String:sClientAuth[], &Handle:hDataPack
should I remove the '&' symbol at &Handle:hDataPack ?
ici is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-18-2015 , 20:30   Re: Client Index Ref
Reply With Quote #7

SourcePawn doesn't have pass-by-value objects bigger than a cell, so you're actually causing a (absolutely tiny) perf cost (for the dereference) by passing by reference when you don't need to.

When you pass a handle to a datapack as a param, you're not making a copy of the contents, the handle itself is a reference to the datapack.
__________________
asherkin 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 20:30.


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