Raised This Month: $ Target: $400
 0% 

Can Events like player_builtobject be blocked?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 13:34.


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