AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] Entity Toggler (https://forums.alliedmods.net/showthread.php?t=284465)

Ecclesiastical 06-27-2016 07:05

[ANY] Entity Toggler
 
An Entity Toggler I wrote for Disabling Func_no_builds and other Entities for tf2, but should work for Any Game;


Code:

#include <sourcemod>
#include <sdktools>
 
public Plugin myinfo =
{
    name = "Ent Toggler",
    author = "Ecclesiastical",
    description = "Toggle Entities and such",
    version = "3.3.3",
    url = "http://xt6zo6bcjbrrjyvr.onion"
}
 
public void OnPluginStart()
{
    RegAdminCmd("sm_toggleent_admin", Command_EntToggler, ADMFLAG_SLAY);
    RegAdminCmd("sm_enthealth_admin", Command_EntHealth, ADMFLAG_SLAY);
    RegAdminCmd("sm_entcolor_admin", Command_EntColor, ADMFLAG_SLAY);
    RegAdminCmd("sm_entmodel_admin", Command_EntModel, ADMFLAG_SLAY);
    RegConsoleCmd("sm_toggleent", Command_EntToggler, "Toggle an Entity;");
    RegConsoleCmd("sm_enthealth", Command_EntHealth, "Set an Entity's Health;");
    RegConsoleCmd("sm_entcolor", Command_EntColor, "Set an Entity's Color;");
    RegConsoleCmd("sm_entmodel", Command_EntModel, "Set an Entity's Model;");
}
 
public Action Command_EntToggler(client, args)
{
    char arg1[64];
    char arg2[64];
    char name[MAX_NAME_LENGTH];
   
    if (args < 1)
    {
      ReplyToCommand(client, "[SM] Usage: sm_toggleent <Entity> <Input>");
      return Plugin_Handled;
    }
 
    GetCmdArg(1, arg1, sizeof(arg1));
    GetCmdArg(2, arg2, sizeof(arg2));
   
    new horse = FindEntityByClassname(-1, arg1);
       
    for(new x = 0; x > horse; x++)
    {
        AcceptEntityInput(horse, arg2);
    }

    GetClientName(client, name, sizeof(name));
    ReplyToCommand(client, "[SM] You Toggled The %s Entity", arg1);
 
    return Plugin_Handled;
}

public Action Command_EntHealth(client, args)
{
    char arg1[64];
    char arg2[64];
    char name[MAX_NAME_LENGTH];
   
    if (args < 2)
    {
      ReplyToCommand(client, "[SM] Usage: sm_enthealth <Entity> <Health>");
      return Plugin_Handled;
    }
 
    GetCmdArg(1, arg1, sizeof(arg1));
    GetCmdArg(2, arg2, sizeof(arg2));
   
    new horse = FindEntityByClassname(-1, arg1);
    new turtle = StringToInt(arg2);
   
    for(new x = 0; x > horse; x++)
    {
        SetEntityHealth(horse, turtle);
    }
   
    GetClientName(client, name, sizeof(name));
    ReplyToCommand(client, "[SM] %s's Health is now %d", arg1, turtle);
 
    return Plugin_Handled;
}

public Action Command_EntColor(client, args)
{
    char arg1[64];
    char arg2[64];
    char arg3[64];
    char arg4[64];
    char arg5[64];
    char name[MAX_NAME_LENGTH];

    if (args < 3)
    {
      ReplyToCommand(client, "[SM] Usage: sm_entcolor <entity> <Red 0-255> <Green 0-255> <blue 0-255> <alpha 0-255>");
      return Plugin_Handled;
    }
 
    GetCmdArg(1, arg1, sizeof(arg1));
    GetCmdArg(2, arg2, sizeof(arg2));
    GetCmdArg(3, arg3, sizeof(arg3));
    GetCmdArg(4, arg4, sizeof(arg4));
    GetCmdArg(5, arg5, sizeof(arg5));
   
    new horse = FindEntityByClassname(-1, arg1);
   
    new donkey = StringToInt(arg2);
    new penguin = StringToInt(arg3);
    new anteater = StringToInt(arg4);
    new angel = StringToInt(arg5);
       
    for(new x = 0; x > horse; x++)
    {
        SetEntityRenderColor(horse, donkey, penguin, anteater, angel);
    }
   
    GetClientName(client, name, sizeof(name));
    ReplyToCommand(client, "[SM] You Changed %s's color Red: %d; Green: %d; Blue: %d; Alpha: %d ", horse, donkey, penguin, anteater, angel);
 
    return Plugin_Handled;
}

public Action Command_EntModel(client, args)
{
    char arg1[64];
    char arg2[64];
    char name[MAX_NAME_LENGTH];
   
    if (args < 3)
    {
      ReplyToCommand(client, "[SM] Usage: sm_entmodel <entity > <model>");
      return Plugin_Handled;
    }
 
    GetCmdArg(1, arg1, sizeof(arg1));
    GetCmdArg(2, arg2, sizeof(arg2));
   
    new horse = FindEntityByClassname(-1, arg1);
   
    for(new x = 0; x > horse; x++)
    {
        SetEntityModel(horse, arg2);
    }

    GetClientName(client, name, sizeof(name));
    ReplyToCommand(client, "[SM] The Model for %s has been changed to %s", arg1, arg2);
 
    return Plugin_Handled;
}

For Joanne;

Mitchell 06-27-2016 10:05

Re: [ANY] Entity Toggler
 
Interesting, however you should upload a .sp file, instead of posting the code in the thread.
Also this bothers me:
Code:

    new horse = FindEntityByClassname(-1, arg1);
   
    for(new x = 0; x > horse; x++)
    {
        //XXXXXXXXXXX
    }

How does this code even do anything at all?
Also your naming conventions is pretty interesting but also inconsiderate to a reader, as it doesn't explain what the variable is storing.

Horsedick 06-27-2016 19:58

Re: [ANY] Entity Toggler
 
*the code calls my name....*

xXDeathreusXx 06-27-2016 20:29

Re: [ANY] Entity Toggler
 
Quote:

Originally Posted by Mitchell (Post 2431106)
Code:

    new horse = FindEntityByClassname(-1, arg1);
   
    for(new x = 0; x > horse; x++)
    {
        //XXXXXXXXXXX
    }

How does this code even do anything at all?

I'm puzzled at this myself, logically, it would do absolutely fuck all

Quote:

Originally Posted by Horsedick (Post 2431270)
*the code calls my name....*

You deserve all the internets

shavit 06-28-2016 07:12

Re: [ANY] Entity Toggler
 
i never laughed so much by just reading code man haha

xines 06-28-2016 09:24

Re: [ANY] Entity Toggler
 
Quote:

Originally Posted by Mitchell (Post 2431106)
as it doesn't explain what the variable is storing.

Mitchell, chill brotha its simply storing:

Code:

1. A Horse
2. A Donkey
3. A Penguin
4. A Anteater
5. An Angel

Rofl u get the point lolol :lol::lol:

Mitchell 06-28-2016 10:13

Re: [ANY] Entity Toggler
 
With all jokes aside...
Some use this stock function created by exvel:
Code:

stock FindEntityByClassname2(startEnt, const String:classname[])
{
        /* If startEnt isn't valid shifting it back to the nearest valid one */
        while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
       
        return FindEntityByClassname(startEnt, classname);
}

then use within your code:
Code:

new horse = MaxClients;
while ((horse = FindEntityByClassname2(horse, arg1)) != -1)
{
    //Do stuff in this block.
}

I don't normally use FindEntityByClassname2, so i'm not sure what the advantages are.

xXDeathreusXx 06-28-2016 21:30

Re: [ANY] Entity Toggler
 
Quote:

Originally Posted by Mitchell (Post 2431453)
I don't normally use FindEntityByClassname2, so i'm not sure what the advantages are.

You can give it a number and it'll shift down the entity list backwards until it finds a valid one, kind of a safety precaution...

Generally you can just give it -1 and FindEntityByClassname will do it's job


All times are GMT -4. The time now is 10:41.

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