Added backwards compatibility for NS2AMXx

Changed most stocks to natives.
This commit is contained in:
David Anderson 2004-06-29 19:38:03 +00:00
parent 1b09d4e3fc
commit feda453e6d
4 changed files with 369 additions and 245 deletions

321
plugins/include/ns2amx.inc Executable file
View File

@ -0,0 +1,321 @@
/* NS2AMX Utility backwards compatibility
*
* by the AMX Mod X Development Team
*
* This file is provided as is (no warranties).
*/
#if defined _ns2amx_included
#endinput
#endif
#define _ns2amx_included
#include <engine>
#include <ns2amxx>
#include <ns2amxx_const>
stock is_entity(id)
{
return is_valid_ent(id)
}
stock get_build(classname[], value, number=0, NS_Version=NS_VERSION)
{
return ns_get_build(classname, value, number, NS_Version)
}
stock get_private_i(index, offset, linuxdiff=5)
{
return get_offset_int(index, offset, linuxdiff)
}
stock set_private_i(index, offset, value, linuxdiff=5)
{
return set_private_i(index, offset, value, linuxdiff)
}
stock Float:get_private_f(index, offset, linuxdiff=5)
{
return get_private_f(index, offset, linuxdiff)
}
stock Float:set_private_f(index, offset, Float:value, linuxdiff=5)
{
return set_private_f(index, offset, value, linuxdiff)
}
stock make_string(value[])
{
return 0
}
stock string(value, ret[])
{
return 0
}
stock gpgobals_time()
{
return halflife_time()
}
stock get_range(ida, idb)
{
return entity_get_range(ida, idb)
}
stock supercede()
{
return 0
}
stock register_clientkill()
{
return 0
}
stock register_changelvl()
{
return 0
}
stock register_msgblock(msgName[])
{
return set_msg_block(get_user_msgid(msgName), BLOCK_SET)
}
stock register_msgedit(msgName[], cmd[])
{
return register_message(get_user_msgid(msgName), cmd)
}
stock register_playback(event, cmd[])
{
return 0
}
stock get_spwan(type, number=0, Float:ret[3])
{
return ns_get_spawn(type, number, ret)
}
stock has_weapon(index, weapon, setweapon=-1)
{
return user_has_weapon(index, weapon, setweapon)
}
stock gpglobals_v(type, Float:ret[3])
{
return get_global_vector(type, ret)
}
stock pev(index, value, ...)
{
return 0
}
stock set_pev(index, value, ...)
{
return 0
}
stock msg_args()
{
return get_msg_args()
}
stock Float:msg_loc(vec)
{
new Float:Ret[3]
get_msg_origin(Ret)
if (vec < 0 || vec > 3)
return float(0)
else
return Ret[vec]
}
stock msg_dest()
{
return 0
}
stock msg_type()
{
return 0
}
stock msg_name()
{
return 0
}
stock msg_set_s(number, value[])
{
return set_msg_arg_string(number, value)
}
stock msg_set_f(number, Float:value)
{
return set_msg_arg_float(number, value)
}
stock msg_set_i(number, value)
{
return set_msg_arg_int(number, value)
}
stock msg_data_type(value)
{
return get_msg_arg_type(value)
}
stock msg_strdata(value)
{
return 0
}
stock msg_data(value, ...)
{
return 0
}
stock get_filename(szFile[], len=-1)
{
new name[16], version[16], author[16], status[16]
new res = get_plugin(0, szFile, len, name, 16, version, 16, author, 16, status, 16)
return res
}
stock get_speedchange(id)
{
return ns_get_speedchange(id)
}
stock set_speedchange(id, speed)
{
return ns_set_speedchange(id)
}
stock get_maxspeed(id)
{
return ns_get_maxspeed(id)
}
stock set_ns_menu(id,r=NSMENU_R,g=NSMENU_G,b=NSMENU_B,Float:x=NSMENU_X,Float:y=NSMENU_Y, effects=0, Float:fadeintime=0.0, Float:fadeouttime=0.0,channel1=NSMENU_CHAN1,channel2=NSMENU_CHAN2)
{
return ns_set_menu(id, r, g, b, x, y, effects, fadeintime, fadeouttime, channel1, channel2)
}
stock show_ns_menu(id, cmd[], text[], keys, time)
{
ns_show_menu(id, cmd, text, keys, time)
}
stock set_player_model(id, model[]="")
{
return ns_set_player_model(id, model)
}
stock set_player_skin(id, skin=-1)
{
return ns_set_player_skin(id, skin)
}
stock set_player_body(id, body=-1)
{
return ns_set_player_body(id, body)
}
stock ns2amx_version()
{
return ns_version()
}
stock set_kvhandled()
{
return 0
}
stock ns2amx_getammo(id,Weapon)
{
return ns_getammo(id, Weapon)
}
stock ns2amx_setammo(id,Weapon,Value)
{
return ns_setammo(id, Weapon, Value)
}
stock ns2amx_giveitem(id,svClassname[])
{
return ns_giveitem(id, svClassname)
}
stock ns2amx_moveto(idMoved,idDest)
{
return ns_moveto(idMoved, idDest)
}
/* Returns whether or not the player has the MASK_DIGESTING flag set. */
stock ns2amx_isdigesting(id)
return ns_get_mask(id,MASK_DIGESTING)
/* Returns total # of active hives. */
stock ns2amx_gethives()
return ns_get_build("team_hive",1)
/* Returns 1 if the two entities are within the given range. */
stock ns2amx_inrange(ida,idb,range)
{
if (entity_get_range(ida,idb) <= range)
return 1
return 0
}
stock ns2amx_nspopup(id,svMessage[190])
{
return ns_nspopup(id, svMessage)
}
stock ns2amx_setres(id,value)
{
return ns_setres(id, value)
}
stock ns2amx_getenergy(id)
{
return ns_getenergy(id)
}
stock ns2amx_setenergy(id,energy)
{
return ns_setenergy(id, energy)
}
stock ns2amx_getjpfuel(id)
{
return ns_getjpfuel(id)
}
stock ns2amx_setjpfuel(id,fuel)
{
return ns_setjpfuel(id, fuel)
}
stock get_mask(id,mask)
{
return ns_get_mask(id, mask)
}
stock set_mask(id,mask,value)
{
return ns_set_mask(id,mask,value)
}
stock get_special(id,mask)
{
return ns_get_special(id,mask)
}
stock get_res(id)
{
return ns_get_res(id)
}
stock get_class(id)
{
return ns_get_class(id)
stock is_combat()
{
return ns_is_combat()
}

View File

@ -6,14 +6,14 @@
#endinput
#endif
#define __ns2amxx__ 02
#include <ns2amxxdefines>
#include <ns2amxx_const>
/* Returns the number of specified entities in map if value is 0
otherwise it returns the index of the #th entity of that class. */
native ns_get_ent(classname[],Value);
/* Same as get_ent, but only returns fully built structures (if Value > 0) */
native ns_get_build(classname[],Value,Number=0,NSVersion=NS_VERSION);
native ns_get_build(classname[],Value,Number=0);
/* Get's spawn point for specified team (type). */
native ns_get_spawn(type,number=0,Float:ret[3]);
@ -47,4 +47,49 @@ native ns_set_player_model(id,szModel[]="")
native ns_set_player_skin(id,skin=-1)
native ns_set_player_body(id,body=-1)
#include <ns2amxxhelpers>
native ns_getammo(id,Weapon);
native ns_setammo(id,Weapon,Value);
native ns_giveitem(id,svClassname[]);
native ns_moveto(idMoved,idDest)
native ns_isdigesting(id);
native ns_nspopup(id,svMessage[190]);
native ns_setres(id,value);
native ns_getenergy(id);
native ns_setenergy(id,energy);
native ns_getjpfuel(id);
native ns_setjpfuel(id,fuel);
native ns_get_mask(id,mask);
native ns_set_mask(id,mask,value);
native ns_get_special(id,mask);
native ns_get_res(id);
native ns_get_class(id);
stock ns_gethives()
{
return ns_get_build("team_hive",1)
}
stock ns_inrange(ida,idb,range)
{
if (entity_get_range(ida,idb) <= range)
{
return 1
}
return 0
}

View File

@ -1,242 +0,0 @@
/* NS2AMXHELPERS.INC
* Provides many functions to ease developing for the NS2AMX module.
* Version 1.0
*/
#if defined __ns2amxxhelpers__
#endinput
#endif
#define __ns2amxxhelpers__ 02
#include <fun>
#include <engine>
#include <ns2amxx>
#include <ns2amxxdefines>
stock ns_getammo(id,Weapon)
{
if (id > get_playersnum() || id < 1)
{
return 0
}
if (Weapon == WEAPON_MG)
{
return get_offset_int(id,PRIVATE_AMMO_LMG)
}
if (Weapon == WEAPON_HMG)
{
return get_offset_int(id,PRIVATE_AMMO_HMG)
}
if (Weapon == WEAPON_GRENADE_GUN)
{
return get_offset_int(id,PRIVATE_AMMO_GL)
}
if (Weapon == WEAPON_PISTOL)
{
return get_offset_int(id,PRIVATE_AMMO_PISTOL)
}
if (Weapon == WEAPON_SHOTGUN)
{
return get_offset_int(id,PRIVATE_AMMO_SHOTGUN)
}
return 1
}
stock ns_setammo(id,Weapon,Value)
{
if (id > get_playersnum() || id < 1)
{
return 0
}
if (Weapon == WEAPON_MG)
{
set_offset_int(id,PRIVATE_AMMO_LMG,Value)
return 1
}
if (Weapon == WEAPON_HMG)
{
set_offset_int(id,PRIVATE_AMMO_HMG,Value)
return 1
}
if (Weapon == WEAPON_GRENADE_GUN)
{
set_offset_int(id,PRIVATE_AMMO_GL,Value)
return 1
}
if (Weapon == WEAPON_PISTOL)
{
set_offset_int(id,PRIVATE_AMMO_PISTOL,Value)
return 1
}
if (Weapon == WEAPON_SHOTGUN)
{
set_offset_int(id,PRIVATE_AMMO_SHOTGUN,Value)
return 1
}
return 0
}
stock ns_giveitem(id,svClassname[])
{
new entity = create_entity(svClassname)
ns_moveto(entity,id)
entity_set_int(entity, EV_INT_team, entity_get_int(id, EV_INT_team))
spawn(entity)
fake_touch(entity,id)
}
stock ns_moveto(idMoved,idDest)
{
new Float:origin[3]
new Float:dest[3]
entity_get_vector(idMoved, EV_VEC_origin, origin)
entity_get_vector(idDest, EV_VEC_origin, dest)
entity_set_vector(idMoved, dest)
}
stock ns_isdigesting(id)
{
return ns_get_mask(id,MASK_DIGESTING)
}
stock ns_gethives()
{
return ns_get_build("team_hive",1)
}
stock ns_inrange(ida,idb,range)
{
if (entity_get_range(ida,idb) <= range)
{
return 1
}
return 0
}
stock ns_nspopup(id,svMessage[190])
{
message_begin(MSG_ONE,get_user_msgid("HudText2"),{0,0,0},id)
write_string(svMessage)
write_byte(0)
message_end()
}
stock ns_setres(id,value)
{
if (entity_get_int(id,EV_INT_team) == 2) // this only works for aliens
{
set_offset_float(id,PRIVATE_ALIEN_RES,float(value))
return 0;
}
return 1;
}
stock ns_getenergy(id)
{
if (entity_get_int(id,EV_INT_iuser3) >= 3 && entity_get_int(id,EV_INT_iuser3) <= 7)
{
new Float:energy
entity_set_float(id,EV_FL_fuser3,energy)
return floatround(energy / 10.0)
}
return 0
}
stock ns_setenergy(id,energy)
{
if (entity_get_int(id,EV_INT_iuser3) >= 3 && entity_get_int(id,EV_INT_iuser3) <= 7)
{
entity_set_float(id,EV_FL_fuser3,float(energy * 10))
}
}
stock ns_getjpfuel(id)
{
if (get_offset_int(id,eni_team) == 1)
{
return floatround(get_offset_float(id,enf_fuser3) / 10.0)
}
return 0
}
stock ns_setjpfuel(id,fuel)
{
if (entity_get_int(id,EV_INT_team) == 1)
{
entity_set_float(id,EV_FL_fuser3, float(fuel * 10))
return 1
}
return 0
}
stock ns_get_mask(id,mask)
{
return (entity_get_int(id,EV_INT_iuser4) & mask)
}
stock ns_set_mask(id,mask,value)
{
if (value)
{
if (ns_get_special(id,mask))
return
entity_set_int(id,EV_INT_iuser3,entity_get_int(id,EV_INT_iuser4) + mask)
return
}
if (ns_get_special(id,mask))
entity_set_int(id,EV_INT_iuser4,entity_get_int(id,EV_INT_iuser4) - mask)
}
stock ns_get_special(id,mask)
{
if (entity_get_int(id,EV_INT_iuser4) & mask)
return 1
return 0
}
stock ns_get_res(id)
{
if (id < 1 && id > get_maxplayers())
return 0
if (!is_user_connected(id))
return 0
#if NS_VERSION == 3
if (entity_get_int(id,EV_INT_iuser1) > 0)
{
// This is only reported to be affected in first person spectator, but might as well be safe
new Float:res = get_offset_float(id,PRIVATE_ALIEN_RES)
return floatround(res)
}
else
{
// They aren't in spectator mode...
new Float:res[3]
entity_get_vector(id,EV_VEC_vuser4,res)
res[2] = (res[2] + 1.0) / 100
return floatround(res[2])
}
return 0
#else
new Float:res[3]
entity_get_vector(id,EV_VEC_vuser4, res)
res[2] = (res[2] + 1.0) / 100
return floatround(res[2])
#endif
}
stock ns_get_class(id)
{
new iuser3 = entity_get_int(id,EV_INT_iuser3)
if (entity_get_int(id,EV_INT_deadflag) > 0)
return CLASS_DEAD
if (entity_get_int(id,EV_INT_team) == 0)
return CLASS_NOTEAM
if (iuser3 == 1)
{
// Light armor marine..
if (entity_get_int(id,EV_INT_iuser4) & MASK_HEAVYARMOR)
return CLASS_HEAVY
if (entity_get_int(id,EV_INT_iuser4) & MASK_JETPACK)
return CLASS_JETPACK
return CLASS_MARINE
}
if (iuser3 == 2)
return CLASS_COMMANDER
if (iuser3 == 3)
return CLASS_SKULK
if (iuser3 == 4)
return CLASS_GORGE
if (iuser3 == 5)
return CLASS_LERK
if (iuser3 == 6)
return CLASS_FADE
if (iuser3 == 7)
return CLASS_ONOS
if (iuser3 == 8)
return CLASS_GESTATE
return CLASS_UNKNOWN
}