PHP Code:
Working on a plugin for Custom Weapons 2 to limit the level that an engineer can upgrade his buildings to. I'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[] name, bool dontBroadcast)
{
PrintToServer("Inside EventPreBuild");
int builderID = GetEventInt(event, "userid", -1);
int clientIndex = GetClientOfUserId(builderID);
int buildingID = GetEventInt(event, "index", -1);
char buildingClassname[64];
GetEntityClassname(buildingID, buildingClassname, sizeof(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?