Raised This Month: $51 Target: $400
 12% 

[CSS] Remove player weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
altex
Veteran Member
Join Date: May 2009
Location: Russia
Old 12-25-2009 , 03:57   [CSS] Remove player weapon
Reply With Quote #1

What is the difference between two functions

Code:
new ent = GetPlayerWeaponSlot(client, slot);
RemoveEdict(ent);
and

Code:
new ent = GetPlayerWeaponSlot(client, slot);
RemovePlayerItem(client, ent);
Which aproach is most correct and why?
__________________

Last edited by altex; 12-25-2009 at 04:02.
altex is offline
jackpf
Senior Member
Join Date: Dec 2009
Location: Uhm...
Old 12-25-2009 , 04:12   Re: [CSS] Remove player weapon
Reply With Quote #2

I'd say the latter, since you're specifically removing a client's weapon, not just any entity.
jackpf is offline
altex
Veteran Member
Join Date: May 2009
Location: Russia
Old 12-25-2009 , 04:13   Re: [CSS] Remove player weapon
Reply With Quote #3

But why? I tested and both works fine :-|

also i was found even the following code in forum

Code:
new ent = GetPlayerWeaponSlot(client, slot);
RemovePlayerItem(client, ent);
RemoveEdict(ent);
__________________
altex is offline
jackpf
Senior Member
Join Date: Dec 2009
Location: Uhm...
Old 12-25-2009 , 04:20   Re: [CSS] Remove player weapon
Reply With Quote #4

Well, as you've stated yourself, both work.

I'm simply making a decision on suitability imo, but obviously it's completely down to taste/coding style

Quote:
new ent = GetPlayerWeaponSlot(client, slot);
RemovePlayerItem(client, ent);
RemoveEdict(ent);
I'm not sure why that's necessary, or even valid. Surely destroying an entity twice, it will not exist the second time, so will throw an error. Could be wrong though.
jackpf is offline
altex
Veteran Member
Join Date: May 2009
Location: Russia
Old 12-25-2009 , 04:23   Re: [CSS] Remove player weapon
Reply With Quote #5

sourcemod-1.2.4\linux\addons\sourcemod\scripting\includ e\tf2_stocks.inc
Code:
/**
 * Removes all weapons from a client's weapon slot
 *
 * @param client		Player's index.
 * @param slot			Slot index (0-5)
 * @noreturn
 * @error				Invalid client, invalid slot or lack of mod support
 */
stock TF2_RemoveWeaponSlot(client, slot)
{
	new weaponIndex;
	while ((weaponIndex = GetPlayerWeaponSlot(client, slot)) != -1)
	{
		RemovePlayerItem(client, weaponIndex);
		RemoveEdict(weaponIndex);
	}
}
__________________
altex is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 12-25-2009 , 10:56   Re: [CSS] Remove player weapon
Reply With Quote #6

I think it works because it removes the item from the player and then deletes the ent.
Dragonshadow is offline
altex
Veteran Member
Join Date: May 2009
Location: Russia
Old 12-25-2009 , 11:52   Re: [CSS] Remove player weapon
Reply With Quote #7

Actualy i do not understand what "remove from player" means. I just noticed that it makes sdk call to RemovePlayerItem function.
__________________
altex is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 12-25-2009 , 14:26   Re: [CSS] Remove player weapon
Reply With Quote #8

Quote:
Originally Posted by altex View Post
Actualy i do not understand what "remove from player" means. I just noticed that it makes sdk call to RemovePlayerItem function.
Ok, player is holding a weapon, first part removes the weapon from the player. Now the weapon is "gone" but the entity still exists, so the second part removes the actual entity
Dragonshadow is offline
altex
Veteran Member
Join Date: May 2009
Location: Russia
Old 12-25-2009 , 14:33   Re: [CSS] Remove player weapon
Reply With Quote #9

So the most correct way is

Code:
new ent = GetPlayerWeaponSlot(client, slot);
RemovePlayerItem(client, ent);
RemoveEdict(ent);
Thank you
__________________
altex is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 12-25-2009 , 15:35   Re: [CSS] Remove player weapon
Reply With Quote #10

No problem ^^
Dragonshadow 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 12:23.


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