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

how would I write this plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Static2601
Senior Member
Join Date: Jun 2010
Old 04-26-2012 , 15:29   how would I write this plugin?
Reply With Quote #1

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.

Last edited by Static2601; 04-26-2012 at 15:30.
Static2601 is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 04-26-2012 , 17:38   Re: how would I write this plugin?
Reply With Quote #2

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;
    }


Last edited by Tylerst; 04-26-2012 at 17:42.
Tylerst is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 04-26-2012 , 17:55   Re: how would I write this plugin?
Reply With Quote #3

It is easier to edit the map and change what you want?

Regards.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 04-26-2012 at 17:56.
rodrigo286 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-27-2012 , 04:05   Re: how would I write this plugin?
Reply With Quote #4

Quote:
Originally Posted by rodrigo286 View Post
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.
Bacardi is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 04-26-2012 , 19:25   Re: how would I write this plugin?
Reply With Quote #5

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.

Last edited by TheAvengers2; 04-26-2012 at 21:21.
TheAvengers2 is offline
Static2601
Senior Member
Join Date: Jun 2010
Old 04-26-2012 , 21:08   Re: how would I write this plugin?
Reply With Quote #6

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
Static2601 is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 04-27-2012 , 05:46   Re: how would I write this plugin?
Reply With Quote #7

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.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
Static2601
Senior Member
Join Date: Jun 2010
Old 04-27-2012 , 06:46   Re: how would I write this plugin?
Reply With Quote #8

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;
        }
    }
}
Static2601 is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 04-27-2012 , 07:00   Re: how would I write this plugin?
Reply With Quote #9

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.

Last edited by Tylerst; 04-27-2012 at 07:08.
Tylerst is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-27-2012 , 11:49   Re: how would I write this plugin?
Reply With Quote #10

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 04-27-2012 at 11:52.
Powerlord is offline
Reply


Thread Tools
Display Modes

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 17:53.


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