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

Register Touch...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 08-28-2015 , 12:12   Register Touch...
Reply With Quote #1

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

new CLASSNAME[] = "info_target"

new FILE[96]

new 
score[33]

new const 
WBMODEL[] = { "models/w_weaponbox.mdl" }

public 
plugin_init()
{
    
register_plugin("WB""1.0""redivcram")
    
    
register_touch("info_target""player""FwdPlayerTouchWeaponBox")
    
    
register_clcmd("wpbox_spawn""cmd_wpboxspawn")
    
register_clcmd("wpbox_remove""cmd_wpboxremove")
    
register_clcmd("wpbox_score""cmd_score")
}

public 
plugin_precache()
{
    
precache_model(WBMODEL)
}

public 
cmd_wpboxspawn(id)
{
    new 
origin[3]
    
get_user_origin(idorigin3)
    
wb_spawn(origin)
    
    return 
PLUGIN_HANDLED
}

public 
cmd_wpboxremove(id)
{
    new 
weaponbox = -1
    
while((weaponbox find_ent_by_class(weaponboxCLASSNAME)))
        
remove_entity(weaponbox)

    return 
PLUGIN_HANDLED
}

wb_spawn(origin[3])
{
    new 
weaponbox create_entity(CLASSNAME)
    
    if(!
weaponbox)
        return 
PLUGIN_HANDLED

    
new Float:vec[3]
    
IVecFVec(originvec)
    
entity_set_origin(weaponboxvec)
    
entity_set_model(weaponboxWBMODEL)
    
DispatchSpawn(weaponbox)
    
    return 
PLUGIN_HANDLED
}

public 
FwdPlayerTouchWeaponBox(weaponboxid)
{
    
score[id]++
    
client_print(idprint_chat"You got 1 score for picking up a Weapon Box")
    
remove_entity(weaponbox)
    
    return 
PLUGIN_HANDLED

Entity successfully spawns, whenever player touches it, doesn't do anything
redivcram is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-28-2015 , 13:24   Re: Register Touch...
Reply With Quote #2

If you are creating a weaponbox entity, then you should do create_entity("weaponbox"), not info_target. Anyway, your way of creating a weaponbox is poor. What do you really want to do ?
__________________

Last edited by HamletEagle; 08-28-2015 at 13:32.
HamletEagle is offline
Leonidddd
Member
Join Date: Apr 2012
Old 08-28-2015 , 14:49   Re: Register Touch...
Reply With Quote #3

what's about solid?

Last edited by Leonidddd; 08-28-2015 at 14:49.
Leonidddd is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-28-2015 , 15:17   Re: Register Touch...
Reply With Quote #4

Im no expert but, i don't think you can create an entity like this
Spoiler


I recommend you to search for zombie plague supply box plugin and take a look at that code

Last edited by Depresie; 08-28-2015 at 15:18.
Depresie is offline
Old 08-29-2015, 04:37
HamletEagle
This message has been deleted by HamletEagle.
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 08-29-2015 , 07:41   Re: Register Touch...
Reply With Quote #5

Not using directly the weaponbox entity, i chose It's model for an example...
Testing it out, Adding some simple stuff into the touch function, doesn't have to be weapons...

If you didn't understand the first post,

The entity spawned succesfuly.. where ever i aim to there it spawns.. and It's passable, which is okay, but what I'm trying to do is add up score by one, print out the chat message, and remove the entity.. but whenever i touch it nothing happens, maybe it needs to be solid?
redivcram is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-29-2015 , 07:58   Re: Register Touch...
Reply With Quote #6

i did understand the first post, you seem to not understand my post...

don't be ignorant and lazy, you have your answer in that code...

anyway, this touch works fine for me when i create entities, if it doesn't for you, you have to create your entity properly... you have the example above

Code:
#define ENT_NAME "just-a-box"

new FILE[96]

new score[33]

new const WBMODEL[] = { "models/w_weaponbox.mdl" }

public plugin_init()
{
    register_plugin("WB", "1.0", "redivcram")
    
    register_touch(ENT_NAME, "player", "FwdPlayerTouchWeaponBox")
    
    register_clcmd("wpbox_spawn", "cmd_wpboxspawn")
    register_clcmd("wpbox_remove", "cmd_wpboxremove")
    register_clcmd("wpbox_score", "cmd_score")
}

Last edited by Depresie; 08-29-2015 at 08:03.
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-29-2015 , 08:37   Re: Register Touch...
Reply With Quote #7

You must make the entity solid and give it a size in order to be able to touch it. Also note that an entity is not solid for it's owner.
__________________

Last edited by HamletEagle; 08-29-2015 at 08:37.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-29-2015 , 09:43   Re: Register Touch...
Reply With Quote #8

you could of done it easily by looking over the lasermine, jetpack or supply box code... that is the way i've learnt how to deal with entities...
all you had to do is copy paste the entity creation and touch functions, then edit them a little...

anyway, here you have an example ( sorry, i didn't have time to finish it, but im sure you can do it yourself )

this way, may i ask if the public Event_NewRound is correct? i mean it works, but in some cases i seen looping to get the entities removed

Code:
#define ClassUC "uclip"

public plugin_init()
{
    register_touch(ClassUC, "player", "Touch")
}

public Event_NewRound()
{
    remove_entity_name(ClassUC)
}

public Create_Entity(id)
{
    new ent = create_entity("info_target")
    if(!is_valid_ent(ent)) return;
    
    new Float:Aim[3], Float:Origin[3]
    velocity_by_aim(id, 32, Aim)
    entity_get_vector(id, EV_VEC_origin, Origin)
    Origin[0] += 2*Aim[0]
    Origin[1] += 2*Aim[1]
    entity_set_string(ent, EV_SZ_classname, ClassUC)
    entity_set_model(ent, ModelJetpack_W)
    entity_set_int(ent, EV_INT_movetype, MOVETYPE_TOSS)
    entity_set_int(ent, EV_INT_solid, SOLID_TRIGGER)
    entity_set_size(ent, Float:{-8.0, -8.0, -8.0}, Float:{8.0, 8.0, 8.0})
    entity_set_float(ent, EV_FL_gravity, 1.25)
    entity_set_vector(ent, EV_VEC_origin, Origin)
    velocity_by_aim(id, 400, Aim)
    entity_set_vector(ent, EV_VEC_velocity, Aim)
}

public Touch(ent, id)
{
    if(is_valid_ent(ent) && is_user_connected(id))
    {
        if(!is_user_alive(id)) return PLUGIN_HANDLED;
        
        entity_set_int(ent, EV_INT_solid, SOLID_NOT)
        remove_entity(ent)
    }
    
    return PLUGIN_CONTINUE;
}

Last edited by Depresie; 08-29-2015 at 09:46.
Depresie is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 09-02-2015 , 06:44   Re: Register Touch...
Reply With Quote #9

I tried fakemeta and still get the same results... It spawns, but when I touch it nothing happens...

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

new gClassName[] = "weponbocks"
new gEntModel[] = "models/w_weaponbox.mdl"
new Score[33]

public 
plugin_init()
{
    
register_plugin("EntFM""1.0""EsprimoP")
    
    
register_clcmd("say /spawnent""cmd_spawn_entity")
    
register_clcmd("say /myscore""cmd_show_score")
    
    
register_forward(FM_Touch"FwTouchEnt")
}

public 
plugin_precache()
{
    
precache_model(gEntModel)
}

public 
cmd_show_score(id)
{
    
client_print(idprint_chat"Your score: %d"Score[id])
    return 
PLUGIN_HANDLED
}


public 
cmd_spawn_entity(id)
{
    new 
origin[3]
    
get_user_origin(idorigin3)
    
    new 
weaponbox engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
    
    if(!
weaponbox)
        return 
PLUGIN_HANDLED
    
    
new Float:vec[3]
    
IVecFVec(originvec)
    
    
set_pev(weaponboxpev_classnamegClassName)
    
engfunc(EngFunc_SetOriginweaponboxvec)
    
engfunc(EngFunc_SetModelweaponboxgEntModel)
    
set_pev(weaponboxpev_solidSOLID_TRIGGER)
    
engfunc(EngFunc_SetSizeweaponboxFloat:{-50.0, -50.0, -50.0}, Float:{50.050.050.0})
    
set_pev(weaponboxpev_ownerid)
    
dllfunc(DLLFunc_Spawnweaponbox)
    
    return 
PLUGIN_HANDLED
}

public 
FwTouchEnt(PtdPtr)
{
    new 
ClassName[33], weaponbox Ptdid Ptr
    pev
(Ptdpev_classnameClassNamesizeof(ClassName) - 1)
    
    if(!
equal(ClassNamegClassName))
    {
        
weaponbox Ptr
        id 
Ptd
        
        pev
(Ptrpev_classnameClassNamesizeof(ClassName) - 1)
        
        if(!
equal(ClassNamegClassName))
            return
    }
    
    new 
Owner pev(weaponboxpev_owner)
    
    if(
Owner !=  id)
        return

    
Score[id]++
    
client_print(idprint_chat"You picked up a Weapon Box and earned 1 score")

redivcram is offline
Vancold
Member
Join Date: Jan 2015
Old 09-03-2015 , 02:33   Re: Register Touch...
Reply With Quote #10

Quote:
Originally Posted by redivcram View Post
I tried fakemeta and still get the same results... It spawns, but when I touch it nothing happens...

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

new gClassName[] = "weponbocks"
new gEntModel[] = "models/w_weaponbox.mdl"
new Score[33]

public 
plugin_init()
{
    
register_plugin("EntFM""1.0""EsprimoP")
    
    
register_clcmd("say /spawnent""cmd_spawn_entity")
    
register_clcmd("say /myscore""cmd_show_score")
    
    
register_forward(FM_Touch"FwTouchEnt")
}

public 
plugin_precache()
{
    
precache_model(gEntModel)
}

public 
cmd_show_score(id)
{
    
client_print(idprint_chat"Your score: %d"Score[id])
    return 
PLUGIN_HANDLED
}


public 
cmd_spawn_entity(id)
{
    new 
origin[3]
    
get_user_origin(idorigin3)
    
    new 
weaponbox engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
    
    if(!
weaponbox)
        return 
PLUGIN_HANDLED
    
    
new Float:vec[3]
    
IVecFVec(originvec)
    
    
set_pev(weaponboxpev_classnamegClassName)
    
engfunc(EngFunc_SetOriginweaponboxvec)
    
engfunc(EngFunc_SetModelweaponboxgEntModel)
    
set_pev(weaponboxpev_solidSOLID_TRIGGER)
    
engfunc(EngFunc_SetSizeweaponboxFloat:{-50.0, -50.0, -50.0}, Float:{50.050.050.0})
    
set_pev(weaponboxpev_ownerid)
    
dllfunc(DLLFunc_Spawnweaponbox)
    
    return 
PLUGIN_HANDLED
}

public 
FwTouchEnt(PtdPtr)
{
    new 
ClassName[33], weaponbox Ptdid Ptr
    pev
(Ptdpev_classnameClassNamesizeof(ClassName) - 1)
    
    if(!
equal(ClassNamegClassName))
    {
        
weaponbox Ptr
        id 
Ptd
        
        pev
(Ptrpev_classnameClassNamesizeof(ClassName) - 1)
        
        if(!
equal(ClassNamegClassName))
            return
    }
    
    new 
Owner pev(weaponboxpev_owner)
    
    if(
Owner !=  id)
        return

    
Score[id]++
    
client_print(idprint_chat"You picked up a Weapon Box and earned 1 score")

You could use RegisterHam Ham_Touch.
Works fine. just read up on it

Last edited by Vancold; 09-03-2015 at 02:34.
Vancold 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 00:56.


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