|
AMX Mod X Plugin Approver
|
04-08-2012
, 16:24
Re: Module: Rage
|
#82
|
Here some stuff from Joaquim : Class Creator.
Quote:
Originally Posted by Joaquim
This is a module that allows you to create new classes for entities based on existent classes. For example, you can create a "weapon_boomerang" based on "weapon_knife" and use it then in other plugins seamlessly without having to rely on an API, just using it straight way. It does support hamsandwich so you can handle new entities with new classnames like you do normally for old classes.
|
Please note :
- It would have been better to make class_creator as a library but Joaquim doesn't have the time right now.
- Remember that if you can make the weapon with C++ you should because of increased efficiency and less trouble on handle intricate stuff.
- There are room for improvements and we wanted to present this module differently but at the end better to share unpolished stuffs rather than keeping it for us.
2 examples are provided through a :
- Pawn plugin ; basic example which creates just a weapon_boomerang entity based on the deagle and does nothing else.
- Module ; more elaborated example which create a real weapon weapon_hivehand (the same as HL1) based on the ak47. (next post)
With a pawn plugin :
Spoiler
PHP Code:
#include <amxmodx> #include <rage> #include <fun> #include <fakemeta> #include <hamsandwich> #include <class_creator>
public plugin_precache() { CreateNewClass("weapon_boomerang","weapon_deagle")
precache_generic( "sprites/weapon_boomerang.txt" );
RegisterHam(Ham_Spawn,"weapon_deagle","OnSpawnDeagle") RegisterHam(Ham_Spawn,"weapon_boomerang","OnSpawnBoomerang")
RegisterHam( Ham_Item_AddToPlayer, "weapon_boomerang", "OnAddToPlayerBoomerang", .Post = true );
register_clcmd("boo","give_boomerang") register_clcmd("say boo","give_boomerang") }
public OnSpawnDeagle(id) { new classname[32] pev(id,pev_classname,classname,31)
client_print(0,print_chat,"Spawned a %s",classname) }
public OnSpawnBoomerang(id) { new classname[32] pev(id,pev_classname,classname,31)
client_print(0,print_chat,"Spawned a %s",classname) }
public give_boomerang(id) { give_item(id,"weapon_boomerang") return PLUGIN_HANDLED }
public OnAddToPlayerBoomerang( const item, const player ) { if( pev_valid( item ) && is_user_alive( player ) ) { static msgIndexWeaponList; msgIndexWeaponList || ( msgIndexWeaponList = get_user_msgid( "WeaponList" ) );
message_begin( MSG_ONE, msgIndexWeaponList, .player = player ); { write_string( "weapon_boomerang" ); // WeaponName write_byte( 8 ); // PrimaryAmmoID write_byte( 35 ); // PrimaryAmmoMaxAmount write_byte( -1 ); // SecondaryAmmoID write_byte( -1 ); // SecondaryAmmoMaxAmount write_byte( 1 ); // SlotID (0...N) write_byte( 1 ); // NumberInSlot (1...N) write_byte( CSW_DEAGLE ); // WeaponID write_byte( 0 ); // Flags } message_end(); } }
Some explanations :
- The key is the use of CreateNewClass. It allows to create a new entity and can be used everywhere you want, like with give_item native or be hooked with what you want.
- To make a weapon, you have to deal with the HUD. In order to show the sprites of the new weapon and to tell the client you use a new weapon (to be able to select it), you have to deal with WeaponList message. You need to create a new file weapon_boomerang.txt containing your sprites. For more information you can look at the Custom Weapon Hud Sprites + Slot Redirection tutorial (Note: you don't need to hook the command)
- The example above is not really complete, for example, you create a new weapon based on the deagle : if you get your new weapon, you will see your new sprites, but if you drop it and get a real deagle, the hud will be fucked up. It's just a matter to send again a WeaponList message with the original value if you get a deagle and you were using before your new weapon.
It's important to update Rage to the vBeta3 !
- class_creator_BIN.zip : contains handlers/modules/amxx binaries + plugin source.
- class_creator_SRC.zip : contains handlers/modules source code.
__________________
Last edited by Arkshine; 04-08-2012 at 17:09.
|
|
|
|