Items API
DescriptionNativesSimple API for create custom items.
This can be used for the creation of healthkits, keycards, etc.
How to use?Register item.
Set model index to item.
- item_create(const pick_func[]);
Set collision box size to item.
- item_set_modelindex(item, modelindex);
Check if the entity is a item.
- item_set_size(item, const Float:fSize[3]);
Spawn item by index.
- bool:item_is_valid(ent);
Remove item correctly.
- item_spawn(item, const Float:fOrigin[3]);
- item_remove(ent);
Example
- Use item_create native for create new item (Pass the name of the callback function that is executed when item was picked).
- Use item_set_modelindex native for set modelindex to item.
- Use item_set_size native for set size to item.
- Create callback function. Function must return ITEM_PICKED if item has been picked and ITEM_IGNORED if not.
PHP Code:
#pragma semicolon 1
#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <fakemeta_util>
#include <api_items>
#define PLUGIN "[Item] CS Defuse Kit"
#define VERSION "0.1.0"
#define AUTHOR "Hedgehog Fog"
new g_itemIndex;
new g_itemMdl;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
g_itemIndex = item_create("on_item_picked");
item_set_modelindex(g_itemIndex, g_itemMdl);
item_set_size(g_itemIndex, Float:{8.0, 8.0, 4.0});
register_clcmd("dk", "clcmd_dk");
register_clcmd("say /dk", "clcmd_dk");
}
public plugin_precache()
{
g_itemMdl = precache_model("models/w_thighpack.mdl");
}
public clcmd_dk(id)
{
new Float:fOrigin[3];
fm_get_aim_origin(id, fOrigin);
fOrigin[2] += 4.0;
item_spawn(g_itemIndex, fOrigin);
}
public on_item_picked(id, ent)
{
if(cs_get_user_defuse(id))
return ITEM_IGNORED;
cs_set_user_defuse(id, 1);
return ITEM_PICKED;
}
Attached Files Get Plugin or Get Source (api_items.sma - 4.0 KB) api_items.inc (1.1 KB)
Wyświetl pełny artykuł