SwarmTools
SwarmTools adds natives and stocks that are useful for Alien Swarm plugin developers.
Users:
The attached swarmtools.inc may be required to compile some plugins, and the SwarmTools plugin itself may be required on the server for some Alien Swarm plugins to run.
Plugin Developers
In Alien Swarm, the player/client entity is separate from the marine entity. There is then a third entity type, a marine resource, that links these two together.
This plugin provides a few natives to make converting between client and marine seemless. There are also many useful stocks provided to simplify plugin development.
A taste:
Code:
/**
* Returns whether or not the game is active. If not, all the below calls will error.
*
* @return True if game is active, false otherwise
*/
native bool:Swarm_IsGameActive();
/**
* Gets the marine entity controlled by the given player
*
* @param client Client index
* @return Marine entity index or -1 for none or not found
* @error Invalid client index
*/
native Swarm_GetMarine(client);
/**
* Gets the count of marines controlled by a given player
*
* @param client Client index
* @return Count of marines found under given player's control
*
* @error Invalid client index
*/
native Swarm_GetClientMarineCount(client);
/**
* Gets the client index controlling given marine
*
* @param marine Marine entity index
* @return Client index of controller or -1 for none or not found
* @error Invalid marine index
*/
stock Swarm_GetClientOfMarine(marine);
/**
* Gets the marine resource entity index of given client
*
* @param client Client index
* @return Marine resource entity index of client or -1 for none or not found
* @error Invalid client index
*/
native Swarm_GetMarineResFromCommander(client);
/**
* Gets the marine resource entity index of given marine
*
* @param marine Marine entity index
* @return Marine resource entity index of entity or -1 for none or not found
* @error Invalid marine index
*/
native Swarm_GetMarineResOfMarine(marine);
/**
* Returns the weapon in a marine's slot.
*
* @param marine Marine entity index
* @param slot Slot index (0-based)
* @return Entity index on success, -1 if no weapon existed.
* @error Invalid entity or unable to find marine's weapons
*/
stock Swarm_GetMarineWeaponSlot(marine, slot);
/**
* Returns the marine's current weapon.
*
* @param marine Marine entity index
* @return Entity index on success, -1 if no weapon existed.
* @error Invalid entity
*/
stock Swarm_GetMarineActiveWeapon(marine);
/**
* Returns the marine's health.
*
* @param marine Marine entity index
* @return Health value
* @error Invalid entity
*/
stock Swarm_GetMarineHealth(marine);
/**
* Set the marine's health. (same as SetEntityHealth)
*
* @param marine Marine entity index
* @param amount Health amount
* @error Invalid entity
*/
stock Swarm_SetMarineHealth(marine, health);
/**
* Returns the marine's max health.
*
* @param marine Marine entity index
* @return Max Health value
* @error Invalid entity
*/
stock Swarm_GetMarineMaxHealth(marine);
/**
* Returns the marine's ammo amount of the specified type.
*
* @param marine Marine entity index
* @return Amount
* @error Invalid entity or unable to find marine ammo offset
*/
stock Swarm_GetMarineAmmo(marine, SwarmAmmoType:ammotype);
/**
* Set the marine's ammo amount of the specified type.
*
* @param marine Marine entity index
* @param amount Amount
* @error Invalid entity or unable to find marine ammo offset
*/
stock Swarm_SetMarineAmmo(marine, SwarmAmmoType:ammotype, amount);
/**
* Returns if a marine is infested
*
* @param marine Marine entity index
* @return True if marine is infested, false otherwise
* @error Invalid entity
*/
stock bool:Swarm_IsMarineInfested(marine);
/**
* Causes a marine to become infested.
*
* @param marine Marine entity index
* @param duration Length of infestion
* @noreturn
* @error Function not found or invalid marine
*/
native Swarm_StartMarineInfestation(marine, Float:duration=20.0);
/**
* Cures a marine's infestation.
*
* @param marine Marine entity index
* @noreturn
* @error Invalid entity
*/
stock Swarm_CureMarineInfestation(marine);
/**
* Returns if a marine is on fire
*
* @param marine Marine entity index
* @return True if marine is on fire, false otherwise
* @error Invalid entity
*/
stock bool:Swarm_IsMarineOnFire(marine);
/**
* Adds a weapon to the marine's inventory and equips it.
*
* @param marine Marine entity index
* @param weapon Weapon entity index
* @noreturn
* @error Function not found or invalid marine
*/
native Swarm_EquipMarineWeapon(marine, weapon);
/**
* Forces a marine to drop the specified weapon.
*
* @param marine Marine entity index
* @param weapon Weapon entity index
* @noreturn
* @error Function not found or invalid marine
*/
native Swarm_DropMarineWeapon(marine, weapon);
/**
* Forces a marine to commit suicide.
*
* @param marine Marine entity index
* @noreturn
* @error Function not found or invalid marine
*/
native Swarm_ForceMarineSuicide(marine);
/**
* Slaps a marine in a random direction.
*
* @param marine Marine entity index
* @param amount Health to subtract
* @param bsound False to disable sound effects
* @noreturn
* @error Function not found or invalid marine
*/
native Swarm_SlapMarine(marine, amount=5, bool:bSound=true);
/**
* Returns the marines's eye angles.
*
* @param marine Marine entity index
* @param ang Destination vector to store the marine's eye angles
* @noreturn
* @error Function not found or invalid marine
*/
native Swarm_GetMarineEyeAngles(marine, Float:ang[3]);
enum SwarmAmmoType
{
SwarmAmmo_AR2,
SwarmAmmo_Rifle,
SwarmAmmo_RifleGrenades,
SwarmAmmo_Autogun,
SwarmAmmo_Shotgun,
SwarmAmmo_AssaultShotgun,
SwarmAmmo_Flamer,
SwarmAmmo_Pistol,
SwarmAmmo_MiningLaser,
SwarmAmmo_TeslaGun,
SwarmAmmo_Railun,
SwarmAmmo_ChainSaw,
SwarmAmmo_Flares,
SwarmAmmo_Medkit,
SwarmAmmo_MedSatchel,
SwarmAmmo_MedSatchelSelf,
SwarmAmmo_Stim,
SwarmAmmo_Welder,
SwarmAmmo_FireExtinguisher,
SwarmAmmo_VGrenades,
SwarmAmmo_PDW,
SwarmAmmo_HandGrenades,
SwarmAmmo_GrenadeLauncher,
SwarmAmmo_SniperRifle,
}
To use any of the natives or stocks in a plugin, just add the following:
Code:
#include <swarmtools>
If you are not using any of the natives or any of the stocks that require the natives and do not wish to require the plugin, you can add it as such:
Code:
#undef REQUIRE_PLUGINS
#include <swarmtools>
#define REQUIRE_PLUGINS
If you post a plugin requiring it, put the SwarmTools plugin id into the dependency field so that users can easily find it.
-------------
Thank you to comp_noob for doing all of the testing.