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

Cannot block player_changeclass in TF2?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joev
Member
Join Date: Dec 2007
Old 12-08-2007 , 20:02   Cannot block player_changeclass in TF2?
Reply With Quote #1

Hi all,

I've been writing a plugin to do Heavy weapons guy Melee only sudden death in SM - ala Beetlesmod.

It works like a dream except I can't seem to block the player_changeclass event from firing.

Here's an example of my code (simplified):

Code:
public OnPluginStart() {
    HookEvent("player_changeclass", EventPlayerChangeClass_Pre, EventHookMode_Pre);
}
public Action:EventPlayerChangeClass_Pre(Handle:event, const String:name[], bool:dontBroadcast){    
    return Plugin_Handled;
}
Couldn't be simpler in theory, however the above code does not block the event as I would hope (effectively preventing the change of class).

Am I misunderstanding? I had assumed that this code would basically fire before the event and by returning Plugin_Handled, the engine assumes that the event has been handled by the code in the handler. However, in TF2, this isn't the case, the change in class happens regardless.

I would love for someone to tell me I've got the wrong end of the stick and that there's an easy way to do this!

Any help appreciated.

Cheers

joev
joev is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 12-08-2007 , 20:12   Re: Cannot block player_changeclass in TF2?
Reply With Quote #2

Events are just a notification that something took place. They are triggered after the actual action takes place, so in theory you can't block changing class like that. The best way to do it is to hook the change class, and force the player to choose another class.
bl4nk is offline
joev
Member
Join Date: Dec 2007
Old 12-08-2007 , 20:50   Re: Cannot block player_changeclass in TF2?
Reply With Quote #3

That's basically exactly the opposite of what's said here:
http://wiki.alliedmods.net/Events_%2...locking_Events

Hence my confusion

I solved the problem anyway by using "joinclass 0" to cancel the change in class.

Cheers

joev
joev is offline
pRED*
Join Date: Dec 2006
Old 12-08-2007 , 21:25   Re: Cannot block player_changeclass in TF2?
Reply With Quote #4

bl4nk is correct. An 'event' is a message from the server to clients that informs them about things happening.

The provided example in the wiki checks death messages to see if they are headshots and blocks them.

This would not stop people dying if they get shot in the head. It would only prevent the kill notification thing (top right corner,two player names, picture of a gun...) from displaying.
pRED* is offline
joev
Member
Join Date: Dec 2007
Old 12-09-2007 , 08:59   Re: Cannot block player_changeclass in TF2?
Reply With Quote #5

Quote:
Originally Posted by pRED* View Post
bl4nk is correct. An 'event' is a message from the server to clients that informs them about things happening.
Ah! I see. A Sourcemod "Event" Handler is actually an Interceptor and/or Observer, not an actual implementation of the event handling code. It can intercept and modify the message about the event but it doesn't handle the event itself!

Makes sense now (although the nomenclature is a bit opposite of what a C/C++/C#/JAVA/etc. programmer would expect) Maybe they should be called Event_Messages or Event_Notifications then - at least that's how I'll think of them henceforth anyway (and perhaps that's enough!)

Thanks for the insight. As I said, I'd intuitively solved the problem I was having anyway but it's good to have my misconception sorted out.

cheers

joev
joev is offline
BAILOPAN
Join Date: Jan 2004
Old 12-09-2007 , 11:08   Re: Cannot block player_changeclass in TF2?
Reply With Quote #6

The SourceMod event handlers are directly from the HL2SDK. They're used in the HL2SDK for two things:

- Internal message passing for event notifications (such as deaths/namechanges).
- Networking information to clients (for example, player_death will show a HUD icon).
__________________
egg
BAILOPAN is offline
joev
Member
Join Date: Dec 2007
Old 12-09-2007 , 12:35   Re: Cannot block player_changeclass in TF2?
Reply With Quote #7

Quote:
Originally Posted by BAILOPAN View Post
The SourceMod event handlers are directly from the HL2SDK. They're used in the HL2SDK for two things:

- Internal message passing for event notifications (such as deaths/namechanges).
- Networking information to clients (for example, player_death will show a HUD icon).
Yep, I get it. It's clear now. Thanks Bailopan.

Cheers

joev
joev 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 14:11.


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