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

Items API


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Gameplay       
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 11-26-2015 , 08:20   Items API
Reply With Quote #1


Items API

Description

Simple API for create custom items.
This can be used for the creation of healthkits, keycards, etc.
Natives

Register item.
  • item_create(const pick_func[]);

Set model index to item.
  • item_set_modelindex(item, modelindex);

Set collision box size to item.
  • item_set_size(item, const Float:fSize[3]);

Check if the entity is a item.
  • bool:item_is_valid(ent);

Spawn item by index.
  • item_spawn(item, const Float:fOrigin[3]);

Remove item correctly.
  • item_remove(ent);
How to use?
  • 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.
Example

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(PLUGINVERSIONAUTHOR);

    
g_itemIndex item_create("on_item_picked");
    
item_set_modelindex(g_itemIndexg_itemMdl);
    
item_set_size(g_itemIndexFloat:{8.08.04.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(idfOrigin);

    
fOrigin[2] += 4.0;

    
item_spawn(g_itemIndexfOrigin);
}

public 
on_item_picked(ident)
{
    if(
cs_get_user_defuse(id))
        return 
ITEM_IGNORED;

    
cs_set_user_defuse(id1);

    return 
ITEM_PICKED;

Attached Files
File Type: sma Get Plugin or Get Source (api_items.sma - 641 views - 4.0 KB)
File Type: inc api_items.inc (1.1 KB, 123 views)
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities

Last edited by Hedgehog Fog; 11-26-2015 at 08:21.
Hedgehog Fog is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 11-26-2015 , 10:03   Re: Items API
Reply With Quote #2

Good job! What about submodels and skins support for models of items?
Why you not visit CSM-chat (IRC) anymore ?
Phant is offline
Send a message via ICQ to Phant
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-26-2015 , 12:16   Re: Items API
Reply With Quote #3

This should be posted in Code Snippets/Tutorial since it is not a plugin that a non-scripting user can use.
__________________
fysiks is offline
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 11-26-2015 , 12:28   Re: Items API
Reply With Quote #4

fysiks,
I posted this in Code Snippets/Tutorial before, but then I saw that other users post API's in Plugins.

Phant,
I can add submodels and skins support in next version. I think about the good solution for all variables.
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities

Last edited by Hedgehog Fog; 11-27-2015 at 15:27.
Hedgehog Fog is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-26-2015 , 12:42   Re: Items API
Reply With Quote #5

Quote:
Originally Posted by Hedgehog95 View Post
fysiks,
I posted this in Code Snippets/Tutorial before, but then I saw that other users post API's in Plugins.
Just because other users have done it doesn't make it the best place to put it. People who are writing plugins wont' look in any of the plugin forums for an API.
__________________
fysiks is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-05-2015 , 08:18   Re: Items API
Reply With Quote #6

So, basically your API allow users to create an entity, give it a model and the plugin is noticed when the entity is touched.

You don't need an API for that, this are basic stuffs that can be done easily. Unapproved.
__________________

Last edited by HamletEagle; 12-05-2015 at 08:19.
HamletEagle is offline
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 12-06-2015 , 21:30   Re: Items API
Reply With Quote #7

HamletEagle,
It saves more than 100 lines of code and you don't need to allocate memory for EngFunc_AllocString everytime.
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities

Last edited by Hedgehog Fog; 12-06-2015 at 21:41.
Hedgehog Fog is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-06-2015 , 21:52   Re: Items API
Reply With Quote #8

Quote:
Originally Posted by Hedgehog95 View Post
HamletEagle,
It saves more than 100 lines of code and you don't need to allocate memory for EngFunc_AllocString everytime.
100? lol That is not very much code.
__________________
fysiks is offline
Hedgehog Fog
Senior Member
Join Date: Jun 2010
Location: Ukraine
Old 12-07-2015 , 03:36   Re: Items API
Reply With Quote #9

fysiks,
This is enough.

You don't need remove entity, make basic checks, make/remove HamHook. This is a simple API, but it simplifies the creation of custom items. It contains the basic checks and the setups that allows you to not write the same code many times. It could well be useful for mods, where is necessary to implement a few custom items (it was created for Halloween Mod, here we have 3 custom items: pumpkins, spells, gifts and I have decided to replace the duplication of same code to the ready-made solution).
I agree that it is not very difficult to implement, but I do not agree that it is useless, but your forum - your rules.

OFFTOP
__________________

❄️ CS Snow Wars - Mod based on snowballs fights
🧟 CS Zombie Panic - A port of HL Zombie Panic!
🎃 CS Halloween Mod - Completely new gamemode for Halloween Holidays
📦 AMXXPack - CLI and build system for amxx projects
🔧 Custom Entities API - API to register custom entities

Last edited by Hedgehog Fog; 12-07-2015 at 04:44.
Hedgehog Fog is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 12-07-2015 , 19:13   Re: Items API
Reply With Quote #10

Quote:
Originally Posted by Hedgehog95 View Post
I agree that it is not very difficult to implement, but I do not agree that it is useless, but your forum - your rules.
Could you try Code Snippets/Tutorials subforum instead of new plugins.

Last edited by addons_zz; 12-07-2015 at 19:13. Reason: spelling fix
addons_zz 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 23:44.


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