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

find_ent_by_class problem (Natural Selection MvM plugin)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
golem
Junior Member
Join Date: Oct 2004
Location: Hannover
Old 02-01-2013 , 07:03   find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #1

hi

im quite new to amxx coding and i need some help with my first steps:

(i will write this in a way you dont need to know ns background to help me)

the plugin im working on is more a marine vs. marine map, so we have 2 command chairs on the map
i want to make both of them invulnerable
here is what i have written:

Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <ns>
#include <fun>

public plugin_init()
{
	register_plugin("mvm mod","0.1","golem")
	CCInv()
}

public CCInv()
{
	new cc = find_ent_by_class(1, "team_command")
	set_pev(cc,pev_takedamage,0.0)
}
the plugin is displayed in amx_plugins

but it doesnt work, as both command chairs still get damage.

maybe the plugin cant handle the fact, that there are 2 cc's?

help please
golem is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-01-2013 , 07:28   Re: find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #2

You need to loop entities, also there are const, use them for readability (for people who read your code and for yourself, see hlsdk_const.inc).
End, CCInv function doesn't need to be public since you don't want to call it from outside of the plugin (by another plugin using callfunc or by amxx setting a task or being a command callback). You should even put the code directly in plugin_init if you don't plain to make a hudge plugin.

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>

public plugin_init()
{
    
register_plugin("mvm mod","0.1","golem")
    
CCInv()
}

CCInv()
{
    new 
cc = -1
    
while( (cc find_ent_by_class(1"team_command")) > )
    {
        
set_pev(ccpev_takedamageDAMAGE_NO)
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
golem
Junior Member
Join Date: Oct 2004
Location: Hannover
Old 02-01-2013 , 07:49   Re: find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #3

thanks for your help!!

Quote:
Originally Posted by ConnorMcLeod View Post
You should even put the code directly in plugin_init if you don't plain to make a hudge plugin.
maybe not huge, but this plugin should definitely grow a lot... i hope...
golem is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-01-2013 , 07:52   Re: find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #4

Anyway, it's not a big deal during plugin_init because it is executed at map start, also when functions are executed only once during map.

You could also hook the spawn of those entities with hamsandwich (updated version by Arkshine) and set takedamage there (post function).

PHP Code:
public plugin_precache()
{
    
RegisterHam(Ham_Spawn"team_command""TeamCommand_Spawn"1)
}

public 
TeamCommand_Spawncc )
{
    
set_pev(ccpev_takedamageDAMAGE_NO)

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 02-01-2013 at 07:55.
ConnorMcLeod is offline
golem
Junior Member
Join Date: Oct 2004
Location: Hannover
Old 02-01-2013 , 08:15   Re: find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #5

hm its not working at all right now

i killed my testserver and i cant run it on localhost.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <ns>
#include <fun>

public plugin_init()
{
    
register_plugin("mvm mod","0.1","golem")
    
CCInv()
}

CCInv()
{
    new 
cc = -1
    
while( (cc find_ent_by_class(1"team_command")) > )
    {
        
set_pev(ccpev_takedamageDAMAGE_NO)
    }

is there something missing? and what about this DAMAGE_NO? shall i define it somewhere? or can i remove it and write 0.0 ?
golem is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-01-2013 , 08:25   Re: find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #6

My bad

Replace :

find_ent_by_class(1

with

find_ent_by_class(cc

so it can actually take the last entity to start the search, else it gonna find the same entity and server gonna freeze.

About DAMAGE_NO, it is defined in hlsdk_const.inc, and that file is included by default in engine.inc and fakemeta.inc so it's fine like this, you couldn't compile if there was a problem with it anyway.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
golem
Junior Member
Join Date: Oct 2004
Location: Hannover
Old 02-01-2013 , 09:16   Re: find_ent_by_class problem (Natural Selection MvM plugin)
Reply With Quote #7

ok this works now. at least i dont get an error when i launch the game

but the test server crashed and i cant realy try it :/

thanks anyway!!
golem is offline
Reply



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 18:23.


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