Raised This Month: $ Target: $400
 0% 

Calling custom classes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 07-28-2014 , 16:07   Re: Calling custom classes
Reply With Quote #1

you must change the BLOCK on RegisterHam by "info_target" and then check if the classname of the entity is BLOCK inside the function.

I see you change BLOCK per g_block_classname, so use that constant

ohh and change RegisterHamFromEntity by only RegisterHam

Last edited by baneado; 07-28-2014 at 16:14.
baneado is offline
proffs
Senior Member
Join Date: Jul 2013
Old 07-28-2014 , 16:33   Re: Calling custom classes
Reply With Quote #2

Quote:
Originally Posted by baneado View Post
you must change the BLOCK on RegisterHam by "info_target" and then check if the classname of the entity is BLOCK inside the function.

I see you change BLOCK per g_block_classname, so use that constant

ohh and change RegisterHamFromEntity by only RegisterHam
RegisterHam Only read default cs classes? Or Am I wrong?

And please can you show me? I don't get 90% of what you said lol
proffs is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-28-2014 , 19:36   Re: Calling custom classes
Reply With Quote #3

Well, here is the scripting help section, so we expect you to have even a bit experience with coding.
However, here it is (the whole info was basically given by Niko):
PHP Code:
#include <amxmodx> 
#include <hamsandwich> 
#include <fakemeta> 

#define PLUGIN "g" 
#define VERSION "1.0" 
#define AUTHOR "g" 

#define RIC "debris/metal6.wav" 
#define BLOCK "BMd_Block" 

public plugin_precache() 
    
precache_sound(RIC


public 
plugin_init() { 
    
register_plugin(PLUGINVERSIONAUTHOR
    
    new 
ent
    
while((ent engfunc(EngFunc_FindEntityByStringent"classname"BLOCK)) != 0)
    {
        
RegisterHamFromEntity(Ham_TraceAttackent"shoot_item")
    }


public 
shoot_item(entattackerFloat:damageFloat:direction[3], tracedamagebits

    static 
Float:endpoint[3
    
get_tr2(traceTR_vecEndPosendpoint
    
draw_spark(endpoint
    
    
engfunc(EngFunc_EmitSoundentCHAN_ITEMRIC0.5ATTN_STATIC0PITCH_NORM
    
    return 
HAM_IGNORED 


stock draw_spark(const Float:origin[3]) 

    
message_begin(MSG_ALLSVC_TEMPENTITY
    
write_byte(TE_SPARKS
    
engfunc(EngFunc_WriteCoordorigin[0]) 
    
engfunc(EngFunc_WriteCoordorigin[1]) 
    
engfunc(EngFunc_WriteCoordorigin[2]) 
    
message_end() 

__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-29-2014 , 00:12   Re: Calling custom classes
Reply With Quote #4

As I already told you on steam, you should add a custom forward or call a custom native in the blockmaker plugin, transmitting the block entity id as parameter.

Looping through all blocks in your custom plugin, as my previous posters mentioned, seems kind of ineffiecient and poor.
mottzi is offline
Send a message via MSN to mottzi
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 07-29-2014 , 07:18   Re: Calling custom classes
Reply With Quote #5

@Flick3rR
Why are you registering the forward on plugin_init?
It makes no sense, it's better to do that every time he create the entity.

Why are you still using BLOCK? He has changed to a constant called g_block_classname

Ok, so there are two ways:

First way: as @NikKOo31 posted, before you create the entity and apply all the entity properties, add this line:
PHP Code:
RegisterHamFromEntity(Ham_TraceAttackent"shoot_item"
You don't need to add anything on plugin_init

Second way, I said https://forums.alliedmods.net/showpo...8&postcount=10

on plugin_init put this:
PHP Code:
RegisterHam(Ham_TraceAttack"info_target""shoot_item"
then on the function shoot_item
PHP Code:
public shoot_item(entattackerFloat:damageFloat:direction[3], tracedamagebits
{
    static 
szClassname[10// be careful about g_block_classname length
    
entity_get_string(entEV_SZ_classnameszClassnamecharsmax(szClassname))
    
    if (!
equal(szClassnameg_block_classname)) 
        return 
HAM_IGNORED;
    
    static 
Float:endpoint[3
    
get_tr2(traceTR_vecEndPosendpoint
    
draw_spark(endpoint
    
    
engfunc(EngFunc_EmitSoundentCHAN_ITEMRIC0.5ATTN_STATIC0PITCH_NORM
    
    return 
HAM_IGNORED 

Obviously I prefer first way.
Second way can be used if you have more than 1 entity with different classnames to avoid creating a different function for each entity

Last edited by baneado; 07-29-2014 at 07:24.
baneado is offline
proffs
Senior Member
Join Date: Jul 2013
Old 07-29-2014 , 07:32   Re: Calling custom classes
Reply With Quote #6

Quote:
Originally Posted by baneado View Post
@Flick3rR
Why are you registering the forward on plugin_init?
It makes no sense, it's better to do that every time he create the entity.

Why are you still using BLOCK? He has changed to a constant called g_block_classname

Ok, so there are two ways:

First way: as @NikKOo31 posted, before you create the entity and apply all the entity properties, add this line:
PHP Code:
RegisterHamFromEntity(Ham_TraceAttackent"shoot_item"
You don't need to add anything on plugin_init

Second way, I said https://forums.alliedmods.net/showpo...8&postcount=10

on plugin_init put this:
PHP Code:
RegisterHam(Ham_TraceAttack"info_target""shoot_item"
then on the function shoot_item
PHP Code:
public shoot_item(entattackerFloat:damageFloat:direction[3], tracedamagebits
{
    static 
szClassname[10// be careful about g_block_classname length
    
entity_get_string(entEV_SZ_classnameszClassnamecharsmax(szClassname))
    
    if (!
equal(szClassnameg_block_classname)) 
        return 
HAM_IGNORED;
    
    static 
Float:endpoint[3
    
get_tr2(traceTR_vecEndPosendpoint
    
draw_spark(endpoint
    
    
engfunc(EngFunc_EmitSoundentCHAN_ITEMRIC0.5ATTN_STATIC0PITCH_NORM
    
    return 
HAM_IGNORED 

Obviously I prefer first way.
Second way can be used if you have more than 1 entity with different classnames to avoid creating a different function for each entity
If I use your method 2nd. I get this error:

Quote:
Error: Undefined symbol "entity_get_string" on line 25
proffs is offline
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 07-29-2014 , 08:33   Re: Calling custom classes
Reply With Quote #7

ok, you don't want to use engine, use fakemeta instead:
pev(ent, pev_classname, szClassname, charsmax(szClassname))
baneado is offline
proffs
Senior Member
Join Date: Jul 2013
Old 07-29-2014 , 09:06   Re: Calling custom classes
Reply With Quote #8

I get this now xD
Error: Undefined symbol "g_block_classname" on line 27
Should I define it somewhere?

Last edited by proffs; 07-29-2014 at 09:06.
proffs is offline
schmurgel1983
Veteran Member
Join Date: Aug 2006
Location: Germany
Old 07-29-2014 , 12:28   Re: Calling custom classes
Reply With Quote #9

Use this only as sub-plugin!
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "g"
#define VERSION "1.0"
#define AUTHOR "g"

#define RIC "debris/metal6.wav"
new const g_block_classname[] = "BMd_Block"

public plugin_precache()
    
precache_sound(RIC)

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_TraceAttack"info_target""shoot_item")
}

public 
shoot_item(entattackerFloat:damageFloat:direction[3], tracedamagebits)
{
    if (!
pev_valid(ent))
        return
    
    static class[
32]
    
pev(entpev_classname, class, charsmax(class))
    if (!
equali(class, g_block_classname)
        return
    
    static 
Float:endpoint[3]
    
get_tr2(traceTR_vecEndPosendpoint)
    
draw_spark(endpoint)
    
    
engfunc(EngFunc_EmitSoundentCHAN_ITEMRIC0.5ATTN_STATIC0PITCH_NORM)
}

stock draw_spark(const Float:origin[3])
{
    
//message_begin(MSG_ALL, SVC_TEMPENTITY)
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0)
    
write_byte(TE_SPARKS)
    
engfunc(EngFunc_WriteCoordorigin[0])
    
engfunc(EngFunc_WriteCoordorigin[1])
    
engfunc(EngFunc_WriteCoordorigin[2])
    
message_end()

__________________

Working on:
nothing

Last edited by schmurgel1983; 07-29-2014 at 12:29.
schmurgel1983 is offline
proffs
Senior Member
Join Date: Jul 2013
Old 07-29-2014 , 12:50   Re: Calling custom classes
Reply With Quote #10

Quote:
Originally Posted by schmurgel1983 View Post
Use this only as sub-plugin!
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "g"
#define VERSION "1.0"
#define AUTHOR "g"

#define RIC "debris/metal6.wav"
new const g_block_classname[] = "BMd_Block"

public plugin_precache()
    
precache_sound(RIC)

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_TraceAttack"info_target""shoot_item")
}

public 
shoot_item(entattackerFloat:damageFloat:direction[3], tracedamagebits)
{
    if (!
pev_valid(ent))
        return
    
    static class[
32]
    
pev(entpev_classname, class, charsmax(class))
    if (!
equali(class, g_block_classname)
        return
    
    static 
Float:endpoint[3]
    
get_tr2(traceTR_vecEndPosendpoint)
    
draw_spark(endpoint)
    
    
engfunc(EngFunc_EmitSoundentCHAN_ITEMRIC0.5ATTN_STATIC0PITCH_NORM)
}

stock draw_spark(const Float:origin[3])
{
    
//message_begin(MSG_ALL, SVC_TEMPENTITY)
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0)
    
write_byte(TE_SPARKS)
    
engfunc(EngFunc_WriteCoordorigin[0])
    
engfunc(EngFunc_WriteCoordorigin[1])
    
engfunc(EngFunc_WriteCoordorigin[2])
    
message_end()

Thanks a lot it works!
proffs 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 13:09.


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