AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   how would I write this plugin? (https://forums.alliedmods.net/showthread.php?t=183784)

Static2601 04-26-2012 15:29

how would I write this plugin?
 
Im trying to change the value of an entity in my map to set to a value. Ive been trying to do this for a long time, cant figure it out.
I want a entity to set the value to turn on.
the entity is a logic_branch "name1" i want it to "setvaluetest" "1"
Or, another one i have is "logic_relay" "name2" to "trigger".
The only way i can do this now is have a button in the map or turn on cheats and "ent_fire name1 setvaluetest 1" in console.

Tylerst 04-26-2012 17:38

Re: how would I write this plugin?
 
PHP Code:

new entity = -1;
while ((
entity FindEntityByClassname(entity"logic_branch"))!=INVALID_ENT_REFERENCE)
{
    new 
String:entName[MAX_NAME_LENGTH];
    
GetEntPropString(entityProp_Data"m_iName"entNamesizeof(entName));
    if(
StrEqual(entName"name1"))
    {
        
SetVariantBool(true);
        
AcceptEntityInput(entity"SetValueTest");
        break;
    }



rodrigo286 04-26-2012 17:55

Re: how would I write this plugin?
 
It is easier to edit the map and change what you want?

Regards.

TheAvengers2 04-26-2012 19:25

Re: how would I write this plugin?
 
You can do that if you want, but you could also do the changes via Stripper:Source instead. This is preferred since clients wouldn't need to redownload in this case.

Static2601 04-26-2012 21:08

Re: how would I write this plugin?
 
well i want to be able to turn it on and off since it controls things in the map. I'll try the code. Thanks

Bacardi 04-27-2012 04:05

Re: how would I write this plugin?
 
Quote:

Originally Posted by rodrigo286 (Post 1697029)
It is easier to edit the map and change what you want?

Regards.

If map have uploaded already most of players, you shouldn't re-compile same named map anymore.
Then you have two different version of same map and will kick players if not match with server map.

Edit map entitites with plugin or Stripper is easier and safely.

Can also with small tool (EntSpy) but this can sometimes re-compile map without asking...
And you need edit only one map what is on server.

rodrigo286 04-27-2012 05:46

Re: how would I write this plugin?
 
But it told him to save with the same name, if the map is of himself, he creates a new version, one to one edition of his clan or something.

But passaarm modes that you guys are good too.

Regards.

Static2601 04-27-2012 06:46

Re: how would I write this plugin?
 
If you saved it with the same name, I'm pretty sure players would get a map differs error. But I tried the code and works great. Im wondering if its ok to run that code multiple times, eg. Im also getting an "Unknown Command" when i enter the command, though it still works.
Code:

/* Plugin Template generated by Pawn Studio */

#include <sourcemod>
#include <sdktools>

public Plugin:myinfo =
{
    name = "New Plugin",
    author = "Unknown",
    description = "<- Description ->",
    version = "1.0",
    url = "<- URL ->"
}

public OnPluginStart()
{
    RegAdminCmd("sm_bm_on", Command_One, ADMFLAG_SLAY, "");
    RegAdminCmd("sm_bm_off", Command_Two, ADMFLAG_SLAY, "");
    RegAdminCmd("sm_rm_on", Command_Three, ADMFLAG_SLAY, "");
    RegAdminCmd("sm_rm_off", Command_Four, ADMFLAG_SLAY, "");
}

public Action:Command_One(client, args)
{
    new entity = -1;
    while ((entity = FindEntityByClassname(entity, "logic_branch"))!=INVALID_ENT_REFERENCE)
    {
        new String:entName[MAX_NAME_LENGTH];
        GetEntPropString(entity, Prop_Data, "m_iName", entName, sizeof(entName));
        if(StrEqual(entName, "bsm"))
        {
            SetVariantInt(1);
            AcceptEntityInput(entity, "SetValueTest");
            break;
        }
    }
}

public Action:Command_Two(client, args)
{
    new entity = -1;
    while ((entity = FindEntityByClassname(entity, "logic_branch"))!=INVALID_ENT_REFERENCE)
    {
        new String:entName[MAX_NAME_LENGTH];
        GetEntPropString(entity, Prop_Data, "m_iName", entName, sizeof(entName));
        if(StrEqual(entName, "bsm"))
        {
            SetVariantInt(0);
            AcceptEntityInput(entity, "SetValueTest");
            break;
        }
    }
}

public Action:Command_Three(client, args)
{
    new entity = -1;
    while ((entity = FindEntityByClassname(entity, "logic_branch"))!=INVALID_ENT_REFERENCE)
    {
        new String:entName[MAX_NAME_LENGTH];
        GetEntPropString(entity, Prop_Data, "m_iName", entName, sizeof(entName));
        if(StrEqual(entName, "rsm"))
        {
            SetVariantInt(1);
            AcceptEntityInput(entity, "SetValueTest");
            break;
        }
    }
}

public Action:Command_Four(client, args)
{
    new entity = -1;
    while ((entity = FindEntityByClassname(entity, "logic_branch"))!=INVALID_ENT_REFERENCE)
    {
        new String:entName[MAX_NAME_LENGTH];
        GetEntPropString(entity, Prop_Data, "m_iName", entName, sizeof(entName));
        if(StrEqual(entName, "rsm"))
        {
            SetVariantInt(0);
            AcceptEntityInput(entity, "SetValueTest");
            break;
        }
    }
}


Tylerst 04-27-2012 07:00

Re: how would I write this plugin?
 
The Unknown Command thing is due to having no return on the commands(Most, if not all callbacks with the Action: tag need a return of some sort), just add return Plugin_Handled; after the while loops.

Example:
PHP Code:

public Action:Command_One(clientargs)
{
    new 
entity = -1;
    while ((
entity FindEntityByClassname(entity"logic_branch"))!=INVALID_ENT_REFERENCE)
    {
        new 
String:entName[MAX_NAME_LENGTH];
        
GetEntPropString(entityProp_Data"m_iName"entNamesizeof(entName));
        if(
StrEqual(entName"bsm"))
        {
            
SetVariantInt(1);
            
AcceptEntityInput(entity"SetValueTest");
            break;
        }
    }
    return 
Plugin_Handled;


Running them multiple times shouldn't be a problem.

Powerlord 04-27-2012 11:49

Re: how would I write this plugin?
 
If you find yourself writing the same code repeatedly, extract a method out of it... find the things that change, make them variables, then move the code to a method that takes those variables. For instance:

PHP Code:

/* Plugin Template generated by Pawn Studio */

#include <sourcemod>
#include <sdktools>

public Plugin:myinfo 
{
    
name "New Plugin",
    
author "Unknown",
    
description "<- Description ->",
    
version "1.0",
    
url "<- URL ->"
}

public 
OnPluginStart()
{
    
RegAdminCmd("sm_bm_on"Command_OneADMFLAG_SLAY"");
    
RegAdminCmd("sm_bm_off"Command_TwoADMFLAG_SLAY"");
    
RegAdminCmd("sm_rm_on"Command_ThreeADMFLAG_SLAY"");
    
RegAdminCmd("sm_rm_off"Command_FourADMFLAG_SLAY"");
}

public 
Action:Command_One(clientargs)
{
    
SetValue("bsm"1);
    return 
Plugin_Handled;
 }

public 
Action:Command_Two(clientargs)
{
    
SetValue("bsm"0);
    return 
Plugin_Handled;
  }

public 
Action:Command_Three(clientargs)
{
    
SetValue("rsm"1);
    return 
Plugin_Handled;
}

public 
Action:Command_Four(clientargs)
{
    
SetValue("rsm"0);
    return 
Plugin_Handled;
}

SetValue(const String:name[], value)
{
    new 
entity = -1;
    while ((
entity FindEntityByClassname(entity"logic_branch"))!=INVALID_ENT_REFERENCE)
    {
        new 
String:entName[MAX_NAME_LENGTH];
        
GetEntPropString(entityProp_Data"m_iName"entNamesizeof(entName));
        if(
StrEqual(entNamename))
        {
            
SetVariantInt(value);
            
AcceptEntityInput(entity"SetValueTest");
            break;
        }
    }


Note: I left it as SetVariantInt and the type as a number, because I wasn't sure if should be a bool or not.
I also included Tylerst's fix as noted in the previous post.


All times are GMT -4. The time now is 23:59.

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