AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Block event/forward default procedure (https://forums.alliedmods.net/showthread.php?t=335816)

cmndrfello 01-06-2022 01:55

Block event/forward default procedure
 
Hello!
I've got another feature that I want to work on which blocks the player from switching teams, in a way that doesn't revert him to his old team, rather not switching him teams in the first place.

I found that in DoD, "PTeam" is an event that is called when the player tries to switch teams.

Is there a way to overwrite / block the default procedure of the event? So that a custom function that is registered on the event will block the team switch from happening?

PHP Code:

register_event("PTeam""dod_onswitchteams""""")

public 
dod_onswitchteams(id)
{
   if(
variable == desired_value)
   {
      
//In theory this will stop the event from proceeding and nothing will happen
      
return EVENT_BLOCKED
   
}
   
//If skipped, the event will continue and user will switch teams
   
return EVENT_CONTINUE


Could something like this be even possible with events? or could this be done with forwards? or with hamsandwich?
Because I've noticed that there are return types such as PLUGIN_HANDLED, PLUGIN_CONTINUE but I can't seem to get them to work. (At least with my past attempts) Though I feel like my problem could be solved with those returns values in someway

Natsheh 01-06-2022 02:00

Re: Block event/forward default procedure
 
Its not possible to block events because its already been happened.

cmndrfello 01-06-2022 02:12

Re: Block event/forward default procedure
 
Quote:

Originally Posted by Natsheh (Post 2767752)
Its not possible to block events because its already been happened.

Then, is it possible to block a forward from happening? for example with "dod_client_changeteam"? Will returning PLUGIN_HANDLED stop the team switch?

(I'm just not able to check it right now though curious)

Natsheh 01-06-2022 02:22

Re: Block event/forward default procedure
 
if its a global forward i don't see a problem but i am not that familiar with the DoD mod so i won't give tips, give a test and you will know!

HamletEagle 01-06-2022 03:10

Re: Block event/forward default procedure
 
You can use register_message to hook events as pre and block. Fakemeta/hamsandwich hooks can be blocked when hooked as pre.

However, blocking something does not guarantee things will work as you expect them to. For example, blocking DeathMsg event hooked as a message won't prevent the player from being killed as DeathMsg is merely a notification.

fysiks 01-06-2022 22:37

Re: Block event/forward default procedure
 
I think you'd be better off trying to block the jointeam command sent from the client rather than trying to block some random thing that has "team" in the name since there is a high likelihood that you'll mess with some larger more complex operation.

EDIT:

I just tested registering "jointeam" with register_clcmd() and then returning PLUGIN_HANDLED if I want to block joining teams and PLUGIN_CONTINUE if I don't want to block it. I used a global variable to control which return value was used and toggles that value with a chat command for testing.


All times are GMT -4. The time now is 11:36.

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