Raised This Month: $ Target: $400
 0% 

Bomb planted EVENT


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Stormsys
Member
Join Date: Oct 2005
Old 04-15-2006 , 12:46   Bomb planted EVENT
Reply With Quote #1

Right i compile my plugin go in game, as soon as the bomb is finished planting it dosent drop and server frezzes+ crashes:

this is my code for bomb planted:

Code:
	else if (FStrEq(name, "bomb_planted"))
	{
		int userid = event->GetInt("userid");
		edict_t *pEntity = m_Engine->PEntityOfEntIndex(userid-1);
		if(pEntity)
		{
			if(FStrEq(pEntity->GetClassName(),"player"))
			{
				this->XPBombPlant(pEntity);

			}
			
		}

	}

any ideas why it crashes?
Stormsys is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-15-2006 , 13:45  
Reply With Quote #2

event->GetInt("userid");

You are getting the users UserID and not their Entity Index. Search the forums, this has been answered a ton of times.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Stormsys
Member
Join Date: Oct 2005
Old 04-15-2006 , 14:16  
Reply With Quote #3

Quote:
Originally Posted by c0ldfyr3
event->GetInt("userid");

You are getting the users UserID and not their Entity Index. Search the forums, this has been answered a ton of times.
um gonna search that now, how comes it only affects the bomb_planted event and not the player_spawn??
Stormsys is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-15-2006 , 14:58  
Reply With Quote #4

It effects every event :\
Every event that you use has a userid and attacker id, they are both UserID's and not Entity Index's.

Code:
edict_t *EdictOfUserId( int UserId )
{
	int i;
	edict_t *pEnt;
	for  (i=1; i<MAX_PLAYERS; i++)
	{
		pEnt = m_Engine->PEntityOfEntIndex(i);
		if (pEnt && !pEnt->IsFree())
		{
			if (FStrEq(pEnt->GetClassName(), "player"))
			{
				if (m_Engine->GetPlayerUserId(pEnt)==UserId)
				{
					return pEnt;
				}
			}
		}
	}

	return NULL;
}
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
API
Veteran Member
Join Date: May 2006
Old 04-19-2006 , 11:08  
Reply With Quote #5

IMO, Valve should have put the index in the event, but looping through and checking works. I would also check if what was returned is NULL.
__________________
API is offline
Send a message via AIM to API
Mani
Veteran Member
Join Date: Dec 2004
Location: UK
Old 04-19-2006 , 12:50  
Reply With Quote #6

You can make it much faster and remove the loop by creating a small 64k array lookup buffer, user ids are defined as the short type.

The setup calls are identical to the VSP names, Load(), Unload(), which must be called in priority order. i.e don't call gpManiTrackUser->Load() as the last thing in the Load() callback.

To get the player index, use gpManiTrackUser->GetIndex(user_id), if it's -1 they don't exist.

mani_trackuser.h

Code:
#ifndef MANI_TRACK_USER_H
#define MANI_TRACK_USER_H

class ManiTrackUser
{

public:
	ManiTrackUser();
	~ManiTrackUser();

	void		ClientActive(edict_t *pEntity);
	void		ClientDisconnect(player_t *player_ptr);
	void		Load(void);
	void		Unload(void);
	void		LevelInit(void);
	int		 GetIndex(int user_id) { return (int) user_table[user_id]; }
}

private:

	// Table of user ids
	char		user_table[65536];
};

extern	ManiTrackUser *gpManiTrackUser;

#endif
mani_trackuser.cpp

Code:
// Add your includes here
#include "mani_trackuser.h"

ManiTrackUser::ManiTrackUser()
{
	// Setup table for search speed lookup
	for (int i = 0; i < 65536; i ++)
	{
		user_table[i] = -1;
	}

	gpManiTrackUser = this;
}

ManiTrackUser::~ManiTrackUser()
{
	// Cleanup
}

//---------------------------------------------------------------------------------
// Purpose: Plugin Loaded
//---------------------------------------------------------------------------------
void	ManiTrackUser::Load(void)
{
	for (int i = 0; i < 65536; i ++)
	{
		user_table[i] = -1;
	}

	for (int i = 1; i <= max_players; i++)
	{
		player_t player;

		player.index = i;
		if (!FindPlayerByIndex(&player)) continue;
		user_table[player.user_id] = i;
	}
}

//---------------------------------------------------------------------------------
// Purpose: Plugin Unloaded
//---------------------------------------------------------------------------------
void	ManiTrackUser::Unload(void)
{
	for (int i = 0; i < 65536; i ++)
	{
		user_table[i] = -1;
	}
}

//---------------------------------------------------------------------------------
// Purpose: Level Loaded
//---------------------------------------------------------------------------------
void	ManiTrackUser::LevelInit(void)
{
	for (int i = 0; i < 65536; i ++)
	{
		user_table[i] = -1;
	}
}

//---------------------------------------------------------------------------------
// Purpose: Client Active
//---------------------------------------------------------------------------------
void	ManiTrackUser::ClientActive(edict_t *pEntity)
{
	if(pEntity && !pEntity->IsFree() )
	{
		IPlayerInfo *playerinfo = playerinfomanager->GetPlayerInfo( pEntity );
		if (playerinfo && playerinfo->IsConnected())
		{
			user_table[playerinfo->GetUserID()] = engine->IndexOfEdict(pEntity);
		}
	}
}

//---------------------------------------------------------------------------------
// Purpose: Check Player on disconnect
//---------------------------------------------------------------------------------
void ManiTrackUser::ClientDisconnect(player_t	*player_ptr)
{
	user_table[player_ptr->user_id] = -1;
}


ManiTrackUser	g_ManiTrackUser;
ManiTrackUser	*gpManiTrackUser;

Mani
__________________
Installation files, documentation and help can be found at: -

www.mani-admin-plugin.com
Mani is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-19-2006 , 14:08  
Reply With Quote #7

Quote:
Originally Posted by Mani
i.e don't call gpManiTrackUser->Load() as the last thing in the Load() callback.
Im just wondering; why not...?
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Mani
Veteran Member
Join Date: Dec 2004
Location: UK
Old 04-19-2006 , 14:56  
Reply With Quote #8

Quote:
Originally Posted by c0ldfyr3
Quote:
Originally Posted by Mani
i.e don't call gpManiTrackUser->Load() as the last thing in the Load() callback.
Im just wondering; why not...?
Because you might want to do a lookup via user id in your late loading handling. If the call to gpManiTrackUser->Load() has not happened, the array will not have been setup yet.

Same thing with ClientDisconnect(), it should be called last as you may have functionality which depends on it earlier in the ClientDisconnect() callback.

Mani
__________________
Installation files, documentation and help can be found at: -

www.mani-admin-plugin.com
Mani 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 15:59.


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