Raised This Month: $89 Target: $400

Help, how to use EntIndexToEntRef?

Post New Thread Reply   
Thread Tools Display Modes
Author Message
Junior Member
Join Date: Jun 2019
Old 09-10-2019 , 20:09   Help, how to use EntIndexToEntRef?
Reply With Quote #1

Ive written my own version of the l4d2 portals plugin, when moving portals around sometimes it breaks and instead of moving the portals something else moves instead .

A friend suggested that to fix this i need to convert the portal to an entityreferance then back to entityindex.

I found the commands EntIndexToEntRef and EntRefToEntIndex, im new to sourcemod and im not sure how to properly use them, can anyone give me an example of how to use them.
rekcah is offline
AlliedModders Donor
Join Date: May 2012
Location: average villain lair
Old 09-10-2019 , 23:44   Re: Help, how to use EntIndexToEntRef?
Reply With Quote #2

You use them when passing entities to functions. Here's an example from my Mutant Tanks plugin:

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
    if (
g_bPluginEnabled && StrEqual(classname"tank_rock"))
// pass the reference of the entity to the timer...
CreateTimer(0.1tTimerRockThrowEntIndexToEntRef(entity), TIMER_FLAG_NO_MAPCHANGE);

Action tTimerRockThrow(Handle timerint ref)
// convert the reference back to an index and check if that entity is still there...
int iRock EntRefToEntIndex(ref);
    if (!
g_bPluginEnabled || iRock == INVALID_ENT_REFERENCE || !bIsValidEntity(iRock))

// rest of the code here...

return Plugin_Continue;

The reason we pass entities like this is because entities can be changed or deleted anytime between the time of passing them through a function and the time of when we use them in that function.

We do the same thing with clients using GetClientUserId() paired with GetClientOfUserId() or GetClientSerial() paired with GetClientFromSerial():

PHP Code:
public void OnClientPostAdminCheck(int client)
    if (!
CreateTimer(3.0tTimerWelcomeGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);

Action tTimerWelcome(Handle timerint userid)
int client GetClientOfUserId(userid);
    if (!(
client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client)))

PrintToChat(client"[SM] Welcome %N!"client);


AFK like JFK
Crasher_3637 is offline

Thread Tools
Display Modes

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:17.

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