Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

WeaponBoxApi[ V 0.0.1 ]


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
Brak odpowiedzi do tego tematu

#1 Adminek AMXX.PL

    Admin :)

  • Bot

Reputacja: 156
Profesjonalista

  • Postów:7 488
  • Lokalizacja:AMXX.PL
Offline

Napisano 09.04.2015 15:32


WeaponBoxApi
Release: 09.04.2015 | Last Update: 09.04.2015

Table of Contents
  • Description
  • Requirements
  • Installation
  • API
  • Credits
  • Changelog
Description top

This api give acces to WeaponBox functions from game, making weaponbox manipulation much more easier than ever before.
Usually you would need to redo this functions in pawn, this work si workill and in my opinion is for nothing. Now, you can use just 5 natives and to the job perfectly.

You may ask where you need this. Well, if you are not a coder or if you don't know what a weaponbox entity is your don't need that for sure.

Requirements top

You need the fallowing things to get this working:

  • Orpheu module
  • An updated server without dproto.
    Signatures may not work into updated server.

Installation top

To install the plugin:

  • Download the resources from this post. You need to get the source and compile it locally.
  • Put WeaponBoxApi.amxx in addons/amxmodx/plugins
  • Open addons/amxmodx/configs/plugins.ini and add at the end of this file WeaponBoxApi.amxx
  • You can put WeaponBoxApi.sma file into addons/amxmodx/sources but this is not mandatory.
  • Open the archive provided and copy the content from Orpheu folder into addons/amxmodx/configs/Orpheu(you need to have orpheu installed)
To install orpheu:
  • Download orpheu files and extract the archive.
  • Copy the dll/so file depending on your operation system into addons/amxmodx/modules
  • The module will be auto-loaded, you don't need to add it into modules.ini
To compile locally:
  • First way:
    • Download AMX Mod X for windows/linux from main site
    • Extract somewhere the arhive and remember the folder!
    • Copy the content from include folder from orpheu arhive into addons/amxmodx/scripting/include( in the folder created in the step 2 ).
    • Copy the content from include folder from WeaponBoxApi arhive into addons/amxmodx/scripting/include( in the folder created in the step 2 ).
    • Download the source of the plugin( WeaponBoxApi.sma) from this post and drag it over the compile.exe(scripting folder from the arhive created at step 2)
    • It will create a new folder called compiled. Open it and you will find your compiled plugin( WeaponBoxApi.amxx )
  • Second way:
    • Go to http://spider.limetech.org/
    • Copy/paste the code from the .sma file into the website.
    • Under the big blue Compile button you see a box which Drop .inc files here
    • Then press Compile and Download

API top

Well, not much things to say. Everything is well documented inside weaponbox_api.inc



PHP Code:



#if defined _weaponbox_api_included
#endinput
#endif
#define _weaponbox_api_included

enum /* Functions that can be hooked */
{
CreateNamedEntity,
CWeaponBoxHasWeapon,
CWeaponBoxKill,
CWeaponBoxPackWeapon,
CWeaponBoxPackAmmo
}

/**
* Calls CWeaponBox functions.
*
* Can call:
* -> CreateNamedEntity Creates an weaponbox entity
* @param CreateNamedEntity The function to hook
*
* -> CWeaponBoxHasWeapon Check if an weaponbox entity contain a specific item
* @param CWeaponBoxHasWeapon The function to hook
* @param WeaponBoxEntity The weaponbox entity
* @param Item The item to check
*
* -> CWeaponBoxKill Kill an weaponbox entity.
* @param CWeaponBoxKill The functionTo hook
* @param WeaponBoxEntity The weaponbox entity to remove
*
* -> CWeaponBoxPackWeapon Add a specific item into an weaponbox entity
* @param CWeaponBoxPackWeapon The function to hook
* @param WeaponBoxEntity The weaponbox entity
* @param Item The item to add inside weaponbox entity
* @param ApplyModel 1 if you want to let Core plugin to automatically set proper model. 0 otherwise
*
* -> CWeaponBoxPackAmmo Add ammo for an intem inside an weaponbox entity
* @param CWeaponBoxPackAmmo The fucntion to hook
* @param WeaponBoxEntity The weaponbox entity
* @param Item The item for which you want to add ammo
* @param Count The ammo that you want to add
*
* All functions return 0 on failure, 1 otherwise.
*/

native WeaponBoxCallFunc(any:...);

/**
* Hook Touch between a weaponbox entity and another ent
*
* @param CallBack The function that will be called on touch
* @param Entity The entity for which we should hook touch
* @param Post Pre(0)/Post(1) forward. Default Pre
*/
native WeaponBoxHookTouch(const CallBack[], const Entity[], Post = 0);
Basically, you can use two natives.

  • WeaponBoxCallFunc
    • Call a specific weaponbox function.
    • Params for each function are explained inside include file.
  • WeaponBoxHookTouch
    • Hook touch between weaponbox entity and another
    • Params are explained inside include file.
I feel like providing a plugin example is the best way to explain how this natives work:


Code:
[font=monospace]
[color=#ff0000][i]/* Plugin generated by AMXX-Studio */[/i][/color]

[color=#339900]#include <amxmodx>[/color]
[color=#339900]#include <orpheu>[/color]
[color=#339900]#include <hamsandwich>[/color]
[color=#339900]#include <fakemeta>[/color]
[color=#339900]#include <weaponbox_api>[/color]

[color=#007700]new[/color] WeaponBox 
[color=#007700]new[/color]  [color=#ff0000]const[/color] m_rgpPlayerItems_CBasePlayer[color=#000000][[/color][color=#0000dd]6[/color][color=#000000]][/color] = [color=#000000]{[/color][color=#0000dd]367[/color], [color=#0000dd]368[/color], ... [color=#000000]}[/color]

[color=#ff0000]public[/color] plugin_init[color=#000000]([/color][color=#000000])[/color] 
[color=#000000]{[/color]
    [color=#00c0c0]register_clcmd[/color][color=#000000]([/color][color=#800080]"CreateWeaponBox"[/color], [color=#800080]"ClientCommand_CreateWeaponBox"[/color][color=#000000])[/color]
    [color=#00c0c0]register_clcmd[/color][color=#000000]([/color][color=#800080]"KillWeaponBox"[/color], [color=#800080]"ClientCommand_KillWeaponBox"[/color][color=#000000])[/color]
    [color=#00c0c0]register_clcmd[/color][color=#000000]([/color][color=#800080]"CheckForWeapon"[/color], [color=#800080]"ClientCommand_CheckForWeapon"[/color][color=#000000])[/color]
    
    [color=#cf0020]//Hook touch[/color]
    [color=#cf0020]//Hook for player[/color]
    WeaponBoxHookTouch[color=#000000]([/color][color=#800080]"CWeaponBoxTouch"[/color], [color=#800080]"player"[/color], [color=#007700]false[/color][color=#000000])[/color][color=#cf0020]//hook a touch forward as pre[/color]
    
[color=#000000]}[/color]

[color=#ff0000]public[/color] ClientCommand_CreateWeaponBox[color=#000000]([/color]id[color=#000000])[/color]
[color=#000000]{[/color]
    WeaponBox = WeaponBoxCallFunc[color=#000000]([/color]CreateNamedEntity[color=#000000])[/color] [color=#cf0020]//create weaponbox entity[/color]
    ExecuteHamB[color=#000000]([/color]Ham_Spawn, WeaponBox[color=#000000])[/color][color=#cf0020]//spawn it[/color]
    
    [color=#cf0020]//Set some origins so we can touch it later[/color]
    [color=#007700]new[/color] Origin[color=#000000][[/color][color=#0000dd]3[/color][color=#000000]][/color]; [color=#00c0c0]get_user_origin[/color][color=#000000]([/color]id, Origin, [color=#0000dd]3[/color][color=#000000])[/color]
    [color=#007700]new[/color] [color=#00c0c0]Float[/color]: FOrigin[color=#000000][[/color][color=#0000dd]3[/color][color=#000000]][/color]; IVecFVec[color=#000000]([/color]Origin, FOrigin[color=#000000])[/color]
    
    engfunc[color=#000000]([/color]EngFunc_SetOrigin, WeaponBox, FOrigin[color=#000000])[/color]
    
    
    [color=#007700]new[/color] Weapon = get_pdata_cbase[color=#000000]([/color]id, m_rgpPlayerItems_CBasePlayer[color=#000000][[/color][color=#0000dd]1[/color][color=#000000]][/color][color=#000000])[/color][color=#cf0020]//retrieve a primary weapon from player[/color]
    WeaponBoxCallFunc[color=#000000]([/color]CWeaponBoxPackWeapon, WeaponBox, Weapon, [color=#0000dd]1[/color][color=#000000])[/color][color=#cf0020]//add this to weaponbox[/color]
    WeaponBoxCallFunc[color=#000000]([/color]CWeaponBoxPackAmmo, WeaponBox, Weapon, [color=#0000dd]32[/color][color=#000000])[/color][color=#cf0020]//set ammo for it[/color]
[color=#000000]}[/color]

[color=#ff0000]public[/color] ClientCommand_KillWeaponBox[color=#000000]([/color]id[color=#000000])[/color]
[color=#000000]{[/color]
    [color=#cf0020]//No need to call it at Roundend()[/color]
    [color=#cf0020]//Game already remove all weaponbox ents when needed[/color]
    WeaponBoxCallFunc[color=#000000]([/color]CWeaponBoxKill, WeaponBox[color=#000000])[/color][color=#cf0020]//kill an weaponbox function[/color]
[color=#000000]}[/color]

[color=#ff0000]public[/color] ClientCommand_CheckForWeapon[color=#000000]([/color]id[color=#000000])[/color]
[color=#000000]{[/color]
    [color=#007700]new[/color] Weapon = get_pdata_cbase[color=#000000]([/color]id, m_rgpPlayerItems_CBasePlayer[color=#000000][[/color][color=#0000dd]2[/color][color=#000000]][/color][color=#000000])[/color][color=#cf0020]//let's get a secondary weapon from player[/color]
    [color=#0000ff]if[/color][color=#000000]([/color]WeaponBoxCallFunc[color=#000000]([/color]CWeaponBoxHasWeapon, WeaponBox, Weapon[color=#000000])[/color][color=#000000])[/color][color=#cf0020]//check if weaponbox already contain this weapon[/color]
    [color=#000000]{[/color]
        [color=#00c0c0]client_print[/color][color=#000000]([/color]id, print_chat, [color=#800080]"It  has same weapon type."[/color][color=#000000])[/color]
    [color=#000000]}[/color]
    [color=#0000ff]else[/color] 
    [color=#000000]{[/color]
        [color=#00c0c0]client_print[/color][color=#000000]([/color]id, print_chat, [color=#800080]"It doesn't have already same weapon type."[/color][color=#000000])[/color]
    [color=#000000]}[/color]
    
[color=#000000]}[/color]

[color=#cf0020]//Touched is weaponbox entity[/color]
[color=#cf0020]//Toucher is the entity that touched the weaponbox[/color]
[color=#ff0000]public[/color] CWeaponBoxTouch[color=#000000]([/color]Touched, Toucher[color=#000000])[/color]
[color=#000000]{[/color]
    [color=#cf0020]//do stuffs[/color]
[color=#000000]}[/color][/font]
Every line is well commented. You need to get item index from a player weapon slot, you can do that by using:
new const m_rgpPlayerItems_CBasePlayer[6] = {367, 368, ... }
get_pdata_cbase
XO_CWeaponBox = 4
Note that if item is invalid it will return -1, not 0.

Credits top

  • ConnorMcLeod
  • Arkshine
  • HLSDK

ChangeLog <a href="#top">top

  • V 0.1:
  • Initial release



Attached Files Dołączona grafikaWeaponBoxApi.tar.gz (5.0 KB) Dołączona grafikaGet Plugin or Get Source (WeaponBoxApi.sma - 11.2 KB)

Wyświetl pełny artykuł




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych