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

Can Events like player_builtobject be blocked?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr. Jekyll
Member
Join Date: Sep 2015
Old 10-30-2015 , 21:43   Can Events like player_builtobject be blocked?
Reply With Quote #1

PHP Code:
Working on a plugin for Custom Weapons 2 to limit the level that an engineer can upgrade his buildings toI'm trying to prevent a building from being built. Here's the code:

//used when "max building level" is set to 0. Returns Plugin_Handled, which blocks the building from being built
public Action Event_PreBuild(Event event, const char[] namebool dontBroadcast)
{
    
PrintToServer("Inside EventPreBuild");
    
int builderID GetEventInt(event"userid", -1);
    
int clientIndex GetClientOfUserId(builderID);
    
int buildingID GetEventInt(event"index", -1);
    
char buildingClassname[64];
    
GetEntityClassname(buildingIDbuildingClassnamesizeof(buildingClassname));
    
PrintToServer("%d"builderID);
    
PrintToServer("%d"clientIndex);
    
    if(
clientIndex != -1)
    {
        
PrintToServer("playerisvalid");
        
PrintToServer("%d"hasMaxBuildingLevel[clientIndex]);
        
PrintToServer("%d"clientIndex);
        if(
hasMaxBuildingLevel[clientIndex] == true)
        {
            
PrintToServer("playerhasmaxbuilding");
            if(
buildingID != -1)
            {
                
PrintToServer("validBuilding");
                
PrintToServer("%s"buildingClassname);
                if(
strcmp(buildingClassname"obj_attachment_sapper"false) != 0)
                {
                    
PrintToServer("not sapper");
                    if(!
strcmp(buildingClassname"obj_sentrygun"false)) //strcmp returns 0 if strings are equal
                    
{
                        
PrintToServer("Building is sentry");
                        
PrintToServer("%d"maxBuildingLevel[clientIndex][0]);
                        if(
maxBuildingLevel[clientIndex][0] == 0)
                            return 
Plugin_Handled;
                    }
                    else if(!
strcmp(buildingClassname"obj_dispenser"false))
                    {
                        if(
maxBuildingLevel[clientIndex][1] == 0)
                            return 
Plugin_Handled;
                    }
                    else if(!
strcmp(buildingClassname"obj_teleporter"false))
                    {
                        if(
maxBuildingLevel[clientIndex][2] == 0)
                            return 
Plugin_Handled;
                    }
                }
            }
        }
    }
    return 
Plugin_Continue;

It's getting all the way to inside if(!strcmp(buildingClassname, "obj_sentrygun", false)) //strcmp returns 0 if strings are equal

But "return Plugin_Handled;" either isn't working or it's not successfully blocking the event. Anyone know what might be going on?

Last edited by Dr. Jekyll; 11-06-2015 at 23:35.
Dr. Jekyll is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 10-30-2015 , 22:10   Re: Can Events like player_builtobject be blocked?
Reply With Quote #2

Use EventHookMode_Pre as the 3rd parameter under HookEvent.

That being said, I don't think that would block the building from being built. That would just block the event from being transmitted. There is probably a player command being sent to the server that says the client is dropping a building. You would want to attach a commandlistener to that command (I don't know the name, if it even exists) and return Plugin_Handled in that callback.
Potato Uno is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 10-31-2015 , 02:01   Re: Can Events like player_builtobject be blocked?
Reply With Quote #3

As Potato Uno said, you can't block events as they are just notifications.

The command for dropping a building is "build" so you can try to use AddCommandListener and return Plugin_Handled.
__________________
Chaosxk is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 10-31-2015 , 07:25   Re: Can Events like player_builtobject be blocked?
Reply With Quote #4

Use [PHP] tags to include source code...
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Dr. Jekyll
Member
Join Date: Sep 2015
Old 10-31-2015 , 17:16   Re: Can Events like player_builtobject be blocked?
Reply With Quote #5

Quote:
Originally Posted by KissLick View Post
Use [PHP] tags to include source code...
Thanks
Dr. Jekyll is offline
Dr. Jekyll
Member
Join Date: Sep 2015
Old 10-31-2015 , 17:19   Re: Can Events like player_builtobject be blocked?
Reply With Quote #6

Quote:
Originally Posted by Potato Uno View Post
Use EventHookMode_Pre as the 3rd parameter under HookEvent.

That being said, I don't think that would block the building from being built. That would just block the event from being transmitted. There is probably a player command being sent to the server that says the client is dropping a building. You would want to attach a commandlistener to that command (I don't know the name, if it even exists) and return Plugin_Handled in that callback.
Sorry, I should have included the code where I hook the event. I am using EventHookMode_Pre as my third parameter.

I'm going off this page from the sourcemod wiki. Are these instructions wrong, or is it just for player_builtobject that it doesn't work?
Dr. Jekyll is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 10-31-2015 , 17:21   Re: Can Events like player_builtobject be blocked?
Reply With Quote #7

"Note: Blocking events does not necessarily block actions like damaging players."
Miu is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 10-31-2015 , 18:42   Re: Can Events like player_builtobject be blocked?
Reply With Quote #8

Quote:
Originally Posted by Chaosxk View Post
As Potato Uno said, you can't block events as they are just notifications.

The command for dropping a building is "build" so you can try to use AddCommandListener and return Plugin_Handled.
Potato Uno is offline
Dr. Jekyll
Member
Join Date: Sep 2015
Old 11-07-2015 , 00:39   Re: Can Events like player_builtobject be blocked?
Reply With Quote #9

Quote:
Originally Posted by Chaosxk View Post
As Potato Uno said, you can't block events as they are just notifications.

The command for dropping a building is "build" so you can try to use AddCommandListener and return Plugin_Handled.
Just tried this tonight, and it worked for blocking "build". But I'm hoping to block the build command for one particular building, not for all of them. Any suggestions on how to do that?
Dr. Jekyll is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 11-07-2015 , 00:53   Re: Can Events like player_builtobject be blocked?
Reply With Quote #10

Inside the command callback, use GetCmdArg. There are two arguments for the build command. First is the building type, second is the building mode. The values for each can be found in tf2.inc.
__________________

Last edited by pheadxdll; 11-07-2015 at 00:53.
pheadxdll 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 07:32.


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