AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Register touch and pick up? (https://forums.alliedmods.net/showthread.php?t=51525)

Davidos 02-19-2007 12:02

Register touch and pick up?
 
Is it possible to register a dropped entity <medkit for this example> and adding it to an inventory section <amx menu> ?

More importantly, how?

Oh and, how do you make it so it gets picked up even though the player has less than 100 hp <medkit> unless the user has activated it <give item_medkit> from menu?

public pfn_touch(ent,id)


K i get that part...

classname item_medkit. Then my brain shuts down -_-

XxAvalanchexX 02-19-2007 19:15

Re: Register touch and pick up?
 
I don't understand what you're asking. Maybe you could rephrase it.

Davidos 02-20-2007 04:19

Re: Register touch and pick up?
 
Wow, Sorry about that... late night yesterday...

Ok.

So, I have set up a basic inventory mod that allows you to pick up stuff from the ground and put them into your inventory.

Now frankly, the problem is... I have no idea how to make a script so you can pick an item up (Ammo, batteries etc.), delete the ent of the picked up item, and make it so that when you use it in your inventory,
it doesn't get re-added to your inventory in like 4 seconds, but is picked up by the player in game <so it gives you ammo and then disapears mod based, like how you would pick up anything in normal half-life 1>...


Code:

give item_healthkit //spawns healthkit in player


So frankly, if someone could write up an example/tutorial on how to use the
pfn_touch function, I can learn from that -_-.

Do you understand now?

Code:
pfn_touch(ent,id)
that's as far as my knowledge takes me...

Cheap_Suit 02-20-2007 14:23

Re: Register touch and pick up?
 
If you are going do it with engine, register_touch is alot easier to use imo.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Owner"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_touch("item_healthkit""player""touch_healthkit")
}

public 
touch_healthkit(entid)
{
    if(!
is_valid_ent(ent) || !is_user_alive(id))
        return 
PLUGIN_CONTINUE
    
    
//do stuff
    
    //remove ent if touched (do some checks first to make sure they player meets your requirements)
    
remove_entity(ent)
    
    
    return 
PLUGIN_CONTINUE


Another way is setting the classname and let hl handle it. An example would be Healthkit (like in HL) by VEN.

Davidos 02-20-2007 17:29

Re: Register touch and pick up?
 
Quote:

Originally Posted by Cheap_Suit (Post 442960)
If you are going do it with engine, register_touch is alot easier to use imo.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Owner"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_touch("item_healthkit""player""touch_healthkit")
}

public 
touch_healthkit(entid)
{
    if(!
is_valid_ent(ent) || !is_user_alive(id))
        return 
PLUGIN_CONTINUE
    
    
//do stuff
    
    //remove ent if touched (do some checks first to make sure they player meets your requirements)
    
remove_entity(ent)
    
    
    return 
PLUGIN_CONTINUE


Another way is setting the classname and let hl handle it. An example would be Healthkit (like in HL) by VEN.


Thanks alot, too bad I can't karma you anymore... damn system...


anyway...

I tested this on SCSTUFF plugin

Code:
public touch_healthkit(ent, id) {     if(is_valid_ent(ent) || is_user_alive(id) || get_user_health(id) > 75)     {         player_kits[id] +=1         client_print(id,print_chat,"[SCSP] You picked up a medkit! (%i medkits left)",player_kits[id])         remove_entity(ent)         return PLUGIN_HANDLED     }       else     {               return PLUGIN_HANDLED     }     return PLUGIN_HANDLED }

gives me tag mismatch, and when on <75 hp it forces the entity to go into inventory.

Although if I spawn it on myself it works so I just have to pick it up and use it <more realistic anyway -_->

Plus the medkits don't respawn, I suspected this... but how do I fix it?

XxAvalanchexX 02-20-2007 19:40

Re: Register touch and pick up?
 
You should be using && (and) instead of || (or). The else statement isn't needed.

On what line is the tag mismatch?

If you want it to come back, you could try saving its origin, and moving it far away. Set a task to restore it back to its original origin.

Davidos 02-21-2007 05:07

Re: Register touch and pick up?
 
Quote:

Originally Posted by XxAvalanchexX (Post 443087)
You should be using && (and) instead of || (or). The else statement isn't needed.

On what line is the tag mismatch?

If you want it to come back, you could try saving its origin, and moving it far away. Set a task to restore it back to its original origin.

Just fixed statement 1 and 2.

So how do I move it far away? I don' thave entmod so that isn't going to fly, something else perhaps?

<Reminder, I just started 3 days ago>

Oskar 02-21-2007 12:20

Re: Register touch and pick up?
 
Instead of removing the ent, you could reduce the players hp.

Oskar 02-21-2007 12:22

Re: Register touch and pick up?
 
and btw, maybe this runs faster:

register_event("ItemPickup","healthkit_event" ,"b","1&item_healthkit" )

public healthkit_event(id)
{
// do stuff
// apple pie, pizza...
}

Davidos 02-21-2007 17:17

Re: Register touch and pick up?
 
Quote:

Originally Posted by Oskar (Post 443394)
and btw, maybe this runs faster:

register_event("ItemPickup","healthkit_event" ,"b","1&item_healthkit" )

public healthkit_event(id)
{
// do stuff
// apple pie, pizza...
}

<twitch> ...


All times are GMT -4. The time now is 00:42.

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